Poll: lua is
You do not have permission to vote in this poll.
yes
50.00%
3 50.00%
no
50.00%
3 50.00%
Total 6 vote(s) 100%
* You voted for this item. [Show Results]

Using Lua to create games in PR3R
#7
Started working on some basic 3d. Right now, it's looking to support camera position and rotation on one axis; the main reason for only one axis of rotation is because that way I can use complex numbers to easily handle rotation and it wont be as difficult as matrices. Whenever ROP (successor to PR3R) comes around is probably when I'm gonna make full 3d, since more processing power will be available and it'll be usable for far longer. Code is below

Code:
-- initialize camera vars & constants

b3d_pi = math.pi() -- defines pi if it becomes necessary
-- b3dcam_ is a prefix before properties of the camera
b3dcam_pos = {0,0,0} -- defined as a coordinate in 3d space (x,y,z)
b3dcam_rot = 0 -- defined in radians
--[[
camera only rotates on one axis (left or right)
this makes things easier on me and i dont have to implement proper 3d rotation
and complex numbers are cool and i can just use those :)
]]--
b3dcam_focallength = 100 -- defines a constant addition to perspective var to make things look right.

function b3d_camsetpos(x,y,z) -- puts camera to given xyz
  b3dcam_pos = {x,y,z}
end

function b3d_cammove(x,y,z) -- moves camera by given xyz
  b3dcam_pos = {b3dcam_pos[1] + x, b3dcam_pos[2] + y, b3dcam_pos[3] + z}
end

function b3d_camsetrot(r) -- puts camera to given rotation
  b3dcam_rot = r
end

function b3d_camrot(r) -- rotates camera by given rotation
  b3dcam_rot = b3dcam_rot + r
end


function b3d_drawobj(object,x,y,z)
  local b3d_xrel = x - b3dcam_pos[1]
  local b3d_yrel = y - b3dcam_pos[2]
  local b3d_zrel = z - b3dcam_pos[3]
  local b3d_camrot = complex.new(math.cos(b3dcam_rot),math.sin(b3dcam_rot))
  for i in ipairs(object) do -- for all triangles/squares in given object table
    local b3d_objtype = object[i][1][1]
    if b3d_objtype == 0 then
      local b3d_ptrans = {{object[i][2][1]+b3d_xrel,object[i][2][3]+b3d_zrel},{object[i][3][1]+b3d_xrel,object[i][3][3]+b3d_zrel},{object[i][4][1]+b3d_xrel,object[i][4][3]+b3d_zrel}} -- (x,z) format bc y is irrelevant
      for g=1,3,1 do
        local b3d_cmtrns = complex.new(b3d_ptrans[g][1],b3d_ptrans[g][2])
        b3d_cmtrns = complex.mul(b3d_cmtrns,b3d_camrot)
        b3d_ptrans[g] = {b3d_cmtrns.r,b3d_cmtrns.i}
      end
     
    elseif b3d_objtype == 1 then
      for g=1,4,1 do
       
      end
    else
      player.chat("Error: Invalid shape on entry ".. i .."!",0xff0000)
    end
  end
end

this hasn't been tested in any capacity i have no clue if it works lol
i failed the mario twitter challenge
Reply


Messages In This Thread
Using Lua to create games in PR3R - by ThePizzaEater1000 - 22nd September 2020, 8:26 PM
RE: Using Lua to create games in PR3R - by Camer the Dragon - 23rd September 2020, 4:22 PM
RE: Using Lua to create games in PR3R - by ThePizzaEater1000 - 23rd September 2020, 10:03 PM
RE: Using Lua to create games in PR3R - by Mia - 23rd September 2020, 11:15 PM
RE: Using Lua to create games in PR3R - by Northadox - 24th September 2020, 10:12 AM
RE: Using Lua to create games in PR3R - by ThePizzaEater1000 - 26th September 2020, 2:46 PM
RE: Using Lua to create games in PR3R - by ThePizzaEater1000 - 10th October 2020, 6:22 PM
RE: Using Lua to create games in PR3R - by Camer the Dragon - 30th October 2020, 11:20 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)