OK, I am trying to learn how to do 3D using this guide, and have gotten to the part for rotating around a point.

The problem is, all it seems to be doing is skewing my cube.

Here is my code:


Code:

-- base functions
local clear = zmg.clear
local drawCircle = zmg.drawCircle
local drawLine = zmg.drawLine
local drawPoint = zmg.drawPoint
local drawRectFill = zmg.drawRectFill
local drawText = zmg.drawText
local fastCopy = zmg.fastCopy
local keyMenuFast = zmg.keyMenuFast
local keyDirectPoll = zmg.keyDirectPoll
local keyDirect = zmg.keyDirect
local makeColor = zmg.makeColor
local floor = math.floor
local sin = math.sin
local cos = math.cos
local pi = math.pi

-- major vars
local key = {f1=79, f2=69, f3=59, f4=49, f5=39, f6=29, alpha=77, exit=47,
optn=68, up=28, down=37, left=38, right=27, exe=31, shift=78}
local color = {bg=makeColor("white"), fg=makeColor("gray")}
local exit=0

-- 3d vars
local move = {x=50,y=50}
local piv = {x=0, y=0}
local angle = {z=0}
local roffset = {x=0, y=0}
local x = 0
local y = 0
local xd = 0
local yd = 0
local scale = 1

-- 3d arrays
local cube = {x,y}
cube.x = {-20, 20, -20, 20}
cube.y = {-20, -20, 20, 20}

-- functions
local function d2r(angle)
   return angle*(pi/180)
end

local function drawCrosshair(x, y, size, color)
   drawLine(x-size, y, x+size, y, color)
   drawLine(x, y-size, x, y+size, color)
end

-- 3d
while exit~=1 do
   keyDirectPoll()
   clear()
   
   -- SPLAT BEGIN
   for i=1, 4, 1 do
      xd = cube.x[i]-piv.x
      yd = cube.y[i]-piv.y
      roffset.x = xd*cos(d2r(angle.z)) - yd*sin(d2r(angle.z)) - xd
      roffset.y = xd*sin(d2r(angle.z)) - yd*cos(d2r(angle.z)) - yd
      
      x = (cube.x[i] + roffset.x) / scale + move.x
      y = (cube.y[i] + roffset.y) / scale + move.y
      
      drawCrosshair(x, y, 5/scale, color.fg)
   end
   
   if keyDirect(key.left)>0 then move.x = move.x-2 end
   if keyDirect(key.right)>0 then move.x = move.x+2 end
   if keyDirect(key.up)>0 then move.y = move.y-2 end
   if keyDirect(key.down)>0 then move.y = move.y+2 end
   if keyDirect(key.f1)>0 then scale = scale*1.02 end
   if keyDirect(key.f2)>0 then scale = scale/1.02 end
   if keyDirect(key.f3)>0 then angle.z = angle.z-1 end
   if keyDirect(key.f4)>0 then angle.z = angle.z+1 end
   if keyDirect(key.exit)>0 then exit=1 end
   -- SPLAT END
   
   drawText(1, 1, angle.z, color.fg, color.bg)
   
   fastCopy()
end
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement