stuck with simple 3d

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
kraftman
Party member
Posts: 277
Joined: Sat May 14, 2011 10:18 am

stuck with simple 3d

Post by kraftman »

So i have this fairly simple code:

Code: Select all

local cubes = {}

for i = 1, 20 do
	local c = {}
	c.x = math.random(0,800)
	c.y = math.random(0,600)
	c.z = math.random(0,255)
	tinsert(cubes, c)
end

function love.draw()
	for i = 1, #cubes do
		love.graphics.setColor(255,255,255,255-cubes[i].z)
		love.graphics.rectangle("fill", cubes[i].x, cubes[i].y,10,10)
	end
end
I want to add a basic 3d affect so that as i move the keys, the boxes move, but obviously at different speeds depending on their distance from the camera.

I'm guessing i need to add in a camera object and then work out the angles from there, but i'm not really sure how to do it.

Has anyone got a link to a decent tutorial on this kind of thing?
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

Re: stuck with simple 3d

Post by GijsB »

you have a camera with a x,y and z position
for every block you draw you do like :

love.graphics.setColor(255,255,255,255-cubes.z+cameraz)
love.graphics.rectangle("fill", cubes.x+camerax/cubes.z, cubes.y+cameray/cubes.z,10,10)

i think this will give you some nice fake 3D effect :D
User avatar
kraftman
Party member
Posts: 277
Joined: Sat May 14, 2011 10:18 am

Re: stuck with simple 3d

Post by kraftman »

GijsB wrote:you have a camera with a x,y and z position
for every block you draw you do like :

love.graphics.setColor(255,255,255,255-cubes.z+cameraz)
love.graphics.rectangle("fill", cubes.x+camerax/cubes.z, cubes.y+cameray/cubes.z,10,10)

i think this will give you some nice fake 3D effect :D



nice one! now how do i rotate them? ^^
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: stuck with simple 3d

Post by Robin »

For 3D rotation, you need matrix multiplication. I tried to do without them in Boids3D, but I couldn't figure out how it should happen then.
Help us help you: attach a .love.
User avatar
kraftman
Party member
Posts: 277
Joined: Sat May 14, 2011 10:18 am

Re: stuck with simple 3d

Post by kraftman »

Robin wrote:For 3D rotation, you need matrix multiplication. I tried to do without them in Boids3D, but I couldn't figure out how it should happen then.
yeh I took a look a look at your code briefly but I couldn't get my head around it, got any tips on getting started?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: stuck with simple 3d

Post by Robin »

If you don't know how matrix multiplication works, I'd start with that.
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Hugues Ross, Semrush [Bot] and 2 guests