mIRC Home    About    Download    Register    News    Help

Print Thread
Heres a fun toy to play with for y'all #166408 10/12/06 11:50 AM
Joined: Dec 2002
Posts: 230
T
Talon Offline OP
Fjord artisan
OP Offline
Fjord artisan
T
Joined: Dec 2002
Posts: 230
load this up, then type "/init cube" left click and drag to move object, right click for a ton of options. Everyone should try out Solid Fill with shading turned on. It's the coolest effect. I wish mirc was faster with graphics and faster with mathmatics and some gaming possibilities would be endless.
Code:
menu @Render3D {
  mouse {
    if ($mouse.key & 1) {
      var %YAngle = $calc(($mouse.x - ($window($active).dw / 2)) * -1) , %XAngle = $calc(($mouse.y - ($window($active).dh / 2))) , %Zangle = $calc((%XAngle / 2) + (%YAngle / 2))
      ChkRender $iif($hget(Render3D,EXR),0,%XAngle) $iif($hget(Render3D,EYR),0,%YAngle) $iif($hget(Render3D,EZR),0,%ZAngle)
    }
  }
  Add
  .Cube:init cube
  .Diamond:init diamond
  .Pyramid:init Pyramid
  Del
  .$submenu($GenerateObjSel($1,Del))
  -
  X Rotation ( $+ $iif($hget(Render3D,EXR),Off,On) $+ ) { hadd -m Render3D EXR $iif($hget(Render3D,EXR),0,1) }
  Y Rotation ( $+ $iif($hget(Render3D,EYR),Off,On) $+ ) { hadd -m Render3D EYR $iif($hget(Render3D,EYR),0,1) }
  Z Rotation ( $+ $iif($hget(Render3D,EZR),Off,On) $+ ) { hadd -m Render3D EZR $iif($hget(Render3D,EZR),0,1) }
  -
  Shading ( $+ $iif($hget(Render3D,Shading),On,Off) $+ ) { hadd -m Render3D Shading $iif($hget(Render3D,Shading),0,1) | ChkRender }
  -
  rotate
  .Camera:hdel Render3D move | hdel Render3D Render
  .$submenu($GenerateObjSel($1,Render))
  move
  .$submenu($GenerateObjSel($1,Move))
  -
  Dots ( $+ $iif($hget(Render3D,Mode) = 0,On,Off) $+ ) :hadd -m Render3d Mode 0 | ChkRender
  Wireframe ( $+ $iif($hget(Render3D,Mode) = 1,On,Off) $+ ) :hadd -m Render3d Mode 1 | ChkRender
  Solid ( $+ $iif($hget(Render3D,Mode) = 2,On,Off) $+ ) :hadd -m Render3d Mode 2 | ChkRender
  Solid Fill ( $+ $iif($hget(Render3D,Mode) = 3,On,Off) $+ ) :hadd -m Render3d Mode 3 | ChkRender
}
on *:close:@Render3d: { hfree Render3D }
alias GenerateObjSel {
  var %FoundObject = $hfind(Render3D,Room.*,$1,w) , %FONum = $remove(%FoundObject,Room.)
  if ($1 = begin) || ($1 = end) { return - }
  if ($2 != Del) {
    if ($1 <= $hfind(Render3D,Room.*,0,w)) { hdel Render3D move | return Object %FONum :hadd -m Render3D $2 %FONum }
  }
  else {
    if ($1 <= $hfind(Render3D,Room.*,0,w)) { 
      return Object %FONum :hdel -w Render3D $+(Object,%FONum,.*) $chr(124) buildroom $chr(124) chkrender
    }
  }
}
alias matrix {
  var %cos = $cos($2) , %sin = $sin($2)
  if ($1 = X) { return 1 0 0 0 0 %cos $calc(0 - %sin) 0 0 %sin %cos 0 0 0 0 1 }
  elseif ($1 = Y) { return %cos 0 %sin 0 0 1 0 0 $calc(0 - %sin) 0 %cos 0 0 0 0 1 }
  else { return %cos $calc(0 - %sin) 0 0 %sin %cos 0 0 0 0 1 0 0 0 0 1 }
}
alias MultiplyMatrix {
  $iif($regex(MyMatrix,$1,/([-0-9.]+)/g),$null)
  return $calc(($2 * $regml(MyMatrix,1)) + ($3 * $regml(MyMatrix,2)) + ($4 * $regml(MyMatrix,3)) + $regml(MyMatrix,4)) $calc(($2 * $regml(MyMatrix,5)) + ($3 * $regml(MyMatrix,6)) + ($4 * $regml(MyMatrix,7)) + $regml(MyMatrix,8)) $calc(($2 * $regml(MyMatrix,9)) + ($3 * $regml(MyMatrix,10)) + ($4 * $regml(MyMatrix,11)) + $regml(MyMatrix,12))
}

alias XCube {
  if ($1 = verts) { return -50 -50 -50;-50 50 -50;50 50 -50;50 -50 -50;-50 -50 50;-50 50 50;50 50 50;50 -50 50 }
  if ($1 = polys) { return 1 2 3 4 1;2 6 7 3 2;3 7 8 4 3;1 5 6 2 1;1 4 8 5 1;8 7 6 5 8 }
  if ($1 = pycol) { return 255 0 0;0 255 0;0 0 255;255 255 0;0 255 255;255 0 255 }
}
alias XPyramid {
  if ($1 = verts) { return -50 50 -50;50 50 -50;-50 50 50;50 50 50;0 -50 0 }
  if ($1 = polys) { return 5 1 2 5;5 2 4 5;5 4 3 5;5 3 1 5;3 4 2 1 3 }
  if ($1 = pycol) { return 255 0 0;0 255 0;0 0 255;255 255 0;0 255 255 }
}
alias XDiamond {
  if ($1 = verts) { return 50 0 -90;25 43.30125 -90;-25 43.3013 -90;-50 0.00005 -90;-25.00005 -43.30125 -90;24.99995 -43.3013 -90;75 0 -70;64.951875 37.5 -70;37.5 64.951875 -70;0 75 -70;-37.5 64.95195 -70;-64.951875 37.5 -70;-75 0.000075 -70;-64.95195 -37.499925 -70;-37.500075 -64.951875 -70;-0.000075 -75 -70;37.499925 -64.95195 -70;64.951875 -37.500075 -70;0 0 25 }
  if ($1 = polys) { return 6 5 4 3 2 1 6;1 2 8 1;2 3 10 2;3 4 12 3;4 5 14 4;5 6 16 5;6 1 18 6;7 1 8 7;8 2 9 8;9 2 10 9;10 3 11 10;11 3 12 11;12 4 13 12;13 4 14 13;14 5 15 14;15 5 16 15;16 6 17 16;17 6 18 17;18 1 7 18;7 8 19 7;8 9 19 8;9 10 19 9;10 11 19 10;11 12 19 11;12 13 19 12;13 14 19 13;14 15 19 14;15 16 19 15;16 17 19 16;17 18 19 17;18 7 19 18 }
  if ($1 = pycol) { return 255 0 0;253 0 0;251 0 0;249 0 0;247 0 0;245 0 0;243 0 0;241 0 0;239 0 0;237 0 0;235 0 0;233 0 0;231 0 0;229 0 0;227 0 0;225 0 0;223 0 0;221 0 0;219 0 0;217 0 0;215 0 0;213 0 0;211 0 0;209 0 0;207 0 0;205 0 0;203 0 0;201 0 0;99 0 0;97 0 0;95 0 0 }
}
alias points {
  $iif($regex(Pts,$1,/([-0-9.]+)/g),$null)
  if ($prop = x) { return $regml(Pts,1) }
  elseif ($prop = y) { return $regml(Pts,2) }
  else { return $regml(Pts,3) }
}
alias zscale { return 500 }
alias DEG2RAD { return $calc(($1 * $PI) / 180) }
alias mytvec { return $hget(Render3D,$+(DPS.,$1,.,$2)) }
alias init {
  if ($isalias($+(X,$1))) { var %ObjAlias = $+($,X,$1) 
    var %Object = 0 | :startloop | inc %Object
    if ($hget(Render3d,$+(Object,%Object,.Obj))) { goto startloop }
    hadd -m Render3D $+(Object,%Object,.Obj) %ObjAlias $+ (verts)
    hadd -m Render3D $+(Object,%Object,.verts) $eval(%ObjAlias $+ (verts),2)
    hadd -m Render3D $+(Object,%Object,.polys) $eval(%ObjAlias $+ (polys),2)
    hadd -m Render3D $+(Object,%Object,.pycol) $eval(%ObjAlias $+ (pycol),2)
    hadd -m Render3D $+(Object,%Object,.OffX) $iif($2,$2,0)
    hadd -m Render3D $+(Object,%Object,.OffY) $iif($3,$3,0)
    buildroom
    chkrender
  }
}
alias BuildRoom {
  var %x = $hfind(Render3D,Object*.verts,0,w) | hdel -w Render3d Room.*
  while (%x) {
    var %FoundObject = $hfind(Render3D,Object*.verts,%x,w) , %FONum = $remove(%FoundObject,Object,.verts)
    tokenize 59 $hget(Render3D,%FoundObject)
    var %i = 0 , %NewVerts = "" , %RVerts ""
    while (%i < $0) { 
      inc %i 
      var %NewVerts = $calc($points($eval($+($,%i),2)).x + $hget(Render3D,$+(Object,%FONum,.OffX))) $calc($points($eval($+($,%i),2)).y + $hget(Render3D,$+(Object,%FONum,.OffY))) $points($eval($+($,%i),2)).z
      var %RVerts = $addtok(%RVerts,%NewVerts,59)
    }
    hadd -m Render3D $+(Room.,%FONum) %RVerts
    dec %x
  }
}
alias movobj {
  hadd -m Render3D $+(Object,$1,.OffX) $2
  hadd -m Render3D $+(Object,$1,.OffY) $3
  buildroom
  render $gettok($editbox(@Render3d),2-,32)
}
alias rotobj {
  var %Xmatrix = $matrix(x,$deg2rad($2)) , %Ymatrix = $matrix(y,$deg2rad($3)) , %Zmatrix = $matrix(z,$deg2rad($4))
  var %i = 0 , %NewVerts = "" , %RVerts "" , %O1 = $1
  tokenize 59 $eval($hget(Render3D,$+(Object,$1,.Obj)),2)
  while (%i < $0) { inc %i
    $iif($regex(Matrix,$multiplymatrix(%Xmatrix,$points($eval($+($,%i),2)).x,$points($eval($+($,%i),2)).y,$points($eval($+($,%i),2)).z),/([-0-9.]+)/g),$null)
    $iif($regex(Matrix,$multiplymatrix(%Ymatrix,$regml(Matrix,1),$regml(Matrix,2),$regml(Matrix,3)),/([-0-9.]+)/g),$null)
    $iif($regex(Matrix,$multiplymatrix(%Zmatrix,$regml(Matrix,1),$regml(Matrix,2),$regml(Matrix,3)),/([-0-9.]+)/g),$null)
    var %NewVerts = $regml(Matrix,1) $regml(Matrix,2) $regml(Matrix,3)
    var %RVerts = $addtok(%RVerts,%NewVerts,59)
    hadd -m Render3D $+(Object,%O1,.verts) %RVerts
  }
  buildroom
  render $gettok($editbox(@Render3d),2-,32)
}
alias ChkRender {
  if ($1 = $null) { tokenize 32 $gettok($editbox(@Render3d),2-,32) }
  if ($hget(Render3D,Render) = $null) && ($hget(Render3D,Move) = $null) { render $1- | editbox @Render3D /render $1- }
  else { 
    if ($hget(Render3d,move)) { movobj $ifmatch $calc($2 * -1) $1 }
    else { rotobj $hget(Render3D,Render) $1- }
  }
}
alias render {
  if ($window(@Render3D) = $null) { window -pe @Render3D -1 -1 640 480 /render | hadd -m Render3d Mode 1 }
  else { drawrect -rnf @Render3D 0 1 0 0 $window(@Render3D).dw $window(@Render3D).dh }
  var %render = $ticks , %1 = $1 , %2 = $2 , %3 = $3 , %TVsSmall = 0
  var %Xmatrix = $matrix(x,$deg2rad(%1)) , %Ymatrix = $matrix(y,$deg2rad(%2)) , %Zmatrix = $matrix(z,$deg2rad(%3))
  var %cx = $calc($window(@Render3D).dw / 2) , %cy = $calc($window(@Render3D).dh / 2)
  var %x = $hfind(Render3D,Room.*,0,w) , %y = $hfind(Render3D,Object*.verts,0,w)
  while (%x) {
    var %FoundObject = $hfind(Render3D,Room.*,%x,w) , %FONum = $remove(%FoundObject,Room.) , %AvgZ = 0
    tokenize 59 $hget(Render3D,%FoundObject)
    var %i = $0
    while (%i) {
      $iif($regex(Matrix,$multiplymatrix(%Xmatrix,$points($eval($+($,%i),2)).x,$points($eval($+($,%i),2)).y,$points($eval($+($,%i),2)).z),/([-0-9.]+)/g),$null)
      $iif($regex(Matrix,$multiplymatrix(%Ymatrix,$regml(Matrix,1),$regml(Matrix,2),$regml(Matrix,3)),/([-0-9.]+)/g),$null)
      $iif($regex(Matrix,$multiplymatrix(%Zmatrix,$regml(Matrix,1),$regml(Matrix,2),$regml(Matrix,3)),/([-0-9.]+)/g),$null)
      hadd -m Render3D $+(TVS.,%FONum,.,%i) $regml(Matrix,1) $regml(Matrix,2) $regml(Matrix,3)
      var %CalcdX = $calc(%cx + ($regml(Matrix,1) * $zscale) / ($regml(Matrix,3) + $zscale))
      var %CalcdY = $calc(%cy + ($regml(Matrix,2) * $zscale) / ($regml(Matrix,3) + $zscale))
      hadd -m Render3D $+(DPS.,%FONum,.,%i) %CalcdX %CalcdY
      if ($hget(Render3D,Mode) = 0) { drawdot -nr @Render3D $rgb(0,255,0) 1 %CalcdX %CalcdY }
      inc %AvgZ $regml(Matrix,3)
      dec %i
    }
    var %AvgZ = $calc(%AvgZ / $0) , %Zorder = $instok(%Zorder,%AvgZ,1,32) , %Zorder2 = $instok(%Zorder2,%FONum,1,32)
    dec %x
  }
  if ($hget(Render3D,Mode) > 0) { 
    tokenize 32 $sorttok(%Zorder,32,n) | var %Zorder2 = $regex(Order,%Zorder2,/([-0-9.]+)/g)
    var %x = $0 
    while (%x) { 
      if ($1 = $2) || ($2 = $3) { drawpoly $Regml(Order,%x) $eval($+($,%x),2) }
      else { drawpoly $Regml(Order,$findtok(%Zorder, [ $ $+ [ %x ] ] ,1,32)) $eval($+($,%x),2) }
      dec %x 
    }
  }
  drawdot @Render3D | titlebar @Render3D Rendered in: $calc(($ticks - %render) / 1000) secs, Can Render: $calc(1000 / ($ticks - %render)) fps
}
alias drawpoly {
  var %Polys = $hget(Render3D,$+(Object,$1,.polys))) , %i2 = $1 , %i4 = $2
  var %Colors = $hget(Render3D,$+(Object,$1,.pycol)))
  tokenize 59 %Polys
  var %i = 0 , %i3 = $0
  while (%i < %i3) { inc %i
    var %table = $gettok(%Polys,%i,59) , %TB2 = $regex(Table,%table,/([-0-9.]+)/g) , %Ctable = $gettok(%Colors,%i,59)
    var %x = $regml(Table,0) , %y = %x , %avgd = 0 , %xf = 0 , %yf = 0 | dec %x
    .tokenize 32 $mytvec(%i2,$regml(Table,3)) 0 $mytvec(%i2,$regml(Table,2)) 0 $mytvec(%i2,$regml(Table,1)) 
    var %test = $calc(($1 - $4) * ($8 - $5) - ($2 - $5) * ($7 - $4))
    .tokenize 32 $window(@Render3D).dw $window(@Render3D).dh 0 1 $window(@Render3D).dh 0 1 1
    var %test2 = $calc(($1 - $4) * ($8 - $5) - ($2 - $5) * ($7 - $4))
    .tokenize 32 %Ctable
    var %perc = $calc(($abs(%test) / $abs(%test2)) * 20) 
    if ($hget(Render3d,Shading)) && (%perc <= 1) { var %dl.color = $rgb($int($calc($1 * %perc)),$int($calc($2 * %perc)),$int($calc($3 * %perc))) }
    else { var %dl.color = $rgb($1,$2,$3) }
    while (%x) { 
      if (%test < 0) || ($hget(Render3D,Mode) = 1) {
        tokenize 32 $mytvec(%i2,$regml(Table,%x)) $mytvec(%i2,$regml(Table,%y))
        drawline -nr @Render3D %dl.color 1 $1- | inc %xf $1 | inc %yf $2 | inc %avgd
      }
      dec %x | dec %y
    }
    var %avgx = $int($calc(%xf / %avgd)) , %avgy = $int($calc(%yf / %avgd))
    if (%test < 0) && ($getdot(@Render3d,%avgx,%avgy) != %dl.color) && ($hget(Render3D,Mode) = 3) { drawfill -nr @Render3D %dl.color %dl.color %avgx %avgy }
  }
}

Re: Heres a fun toy to play with for y'all [Re: Talon] #166415 10/12/06 02:37 PM
Joined: Mar 2003
Posts: 612
B
billythekid Offline
Fjord artisan
Offline
Fjord artisan
B
Joined: Mar 2003
Posts: 612
lol, that's great.

btk


billythekid
Re: Heres a fun toy to play with for y'all [Re: billythekid] #166636 13/12/06 08:35 AM
Joined: Oct 2004
Posts: 73
M
Mardeg Offline
Babel fish
Offline
Babel fish
M
Joined: Oct 2004
Posts: 73
I really like this! Great use of hashtables smile
I wonder how come the if and $iif conditions work with = instead of ==

Re: Heres a fun toy to play with for y'all [Re: Mardeg] #166651 13/12/06 02:29 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
You don't *have* to use == in an if statement. However, it is very highly recommended that you do.


Invision Support
#Invision on irc.irchighway.net
Re: Heres a fun toy to play with for y'all [Re: Talon] #166844 15/12/06 07:36 PM
Joined: Oct 2006
Posts: 166
B
b1ink Offline
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2006
Posts: 166
that was great.


Kind Regards, blink
Re: Heres a fun toy to play with for y'all [Re: Talon] #168842 15/01/07 02:39 PM
Joined: Jan 2007
Posts: 6
S
SlAiD Offline
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
S
Joined: Jan 2007
Posts: 6
Great, tks.

SL


#WindowsHelp @ irc.PTnet.org
Windows channel for help and chat, since 2002.

http://www.247tech.info