Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / 3d camera rotation using 2d

Author
Message
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 14th Aug 2007 19:03
Hello,

I've created a small 3d engine using 2d commands. Right now, I can place and rotate objects, I can move the camera forward and side to side.

My question is, how do I rotate the camera? Do I rotate the world around the camera position, and if so how do I make the world's position relative to the camera and not to 0,0,0 ?

When I rotate an object, I rotate the vertices around 0,0,0 then translate it back based on it's world coordinates. But I can't figure out how to do something similar with the camera.

Thanks for any help on this.

Enjoy your day.
Dark Dragon
17
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 14th Aug 2007 20:49
i dont think thats possible because if the "objects " are 2d then thay will appear paper thin when the cam is rotated...
but if it did work you would rotate the world around the camera
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 14th Aug 2007 20:58 Edited at: 14th Aug 2007 21:01
So you HAVE been working on this idea lol
Can you explain a bit more about how the distance between the camera and object changes the perspective of the vertices' positions. That's the part I got stuck on myself.

The most help I can give at this stage is that the perspective positions of the vertices and the angle of the objects changes when the camera rotates.
I don't know a lot about geometry so this is difficult for me to understand or explain.
The problem I have is that say you wanted to rotate the camera Y30 degrees; I don't really know what would happen in real life!

I am guessing from the lack of code that you are wanting to keep this secret, could you just post the procedure for displaying the objects they I might be able to give some help.

@DD

The objects he is making are 3D, and anyway 2D objects wouldn't appear paper thin side on: they wouldn't appear at all!
Buuut, they probably would appear as a line unless Latch has implemented culling!

Your signature has been erased by a mod because it was rubbish.
Dark Dragon
17
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 14th Aug 2007 20:59
Quote: "So you HAVE been working on this idea lol "

who me? lol, heh, i do my work silently
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 14th Aug 2007 21:06 Edited at: 14th Aug 2007 21:06
So you HAVE been working on this idea lol
Can you explain a bit more about how the distance between the camera and object changes the perspective of the vertices' positions. That's the part I got stuck on myself.

The most help I can give at this stage is that the perspective positions of the vertices and the angle of the objects changes when the camera rotates.
I don't know a lot about geometry so this is difficult for me to understand or explain.
The problem I have is that say you wanted to rotate the camera Y30 degrees; I don't really know what would happen in real life!

I am guessing from the lack of code that you are wanting to keep this secret, could you just post the procedure for displaying the objects they I might be able to give some help.

@DD

The objects he is making are 3D, and anyway 2D objects wouldn't appear paper thin side on: they wouldn't appear at all!
Buuut, they probably would appear as a line unless Latch has implemented culling!

@EVERYONE
IF YOU EDIT A POST AND GET THE "Duplicate Error: A message with the exact same text is already posted in this thread by you."
Change the post and re-try, there is a bug in the forum that doesn't let a failed attempt at editing go, so the next time you post it will delete your original that you failed to edit!

Hmmm, it didnt that time because I wasn't in the edit page. Interesting

Your signature has been erased by a mod because it was rubbish.
Dark Dragon
17
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 14th Aug 2007 21:11
yeah.......
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 16th Aug 2007 00:37
Quote: "i dont think thats possible because if the "objects " are 2d then thay will appear paper thin when the cam is rotated..."

The objects have depth and perspective based on their set of vertices.

Quote: "but if it did work you would rotate the world around the camera "

I was thinking that, I just can't get my brain around how to make the world relative to the camera for camera rotation instead of relative to the origin.

Quote: "I am guessing from the lack of code that you are wanting to keep this secret"

The code is incidental - I'm really after the theory or the method of the camera rotation. If I can grasp the concept, I can eventually come up with the code for this piece. The code that is already written is mostly draft - and I have several sets. Some to force what I want to see - that doesn't need reworking for this post.

Quote: "could you just post the procedure for displaying the objects they I might be able to give some help. "


The camera is a certain distance from the projection plane (where you see stuff). 2d Vertices are calculated by taking into account the camera distance, and the 3d coordinates of the object. These are translated into screen coordinates. Since the camera or the eye is set in the middle of the screen, the screen coordinates are offset by half of the screen height and half of the screen width.

So, like I posted in your other thread, the most basic conversion of 3d to 2d is
screenx = x/z
screeny = y/z

the smaller the z, the wider apart the screen x and y
the larger the z, the closer together the screen x and y
which gives the illusion of perspective.

but accounting for the camera and the screen size:
screenx = ((x-camerax) / (z-cameraz))+ half screen width
screeny = ((y-cameray) / (z-cameraz))+ half screen height

For rotation, use matrix (comes down to trig) rotations or if you're up for it, quaternions, to rotate the points.

I just don't get how to rotate the camera. It seems that I would be rotating the world around the camera position, but I can't get the concept of how to do that.

Enjoy your day.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 16th Aug 2007 03:43
The camera doesn't exist. All you really have is a viewport on which the 3D co-ords are translated to 2D and then plotted.

As you say, you plot the points in different places to give the appearance that the camera is turning using X, Y and Z rotational matrices in turn. You just alter the point of rotation to the viewport which is normally 0,0,0.

TDK_Man

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 16th Aug 2007 15:35 Edited at: 16th Aug 2007 15:37
Quote: "screeny = ((y-cameray) / (z-cameraz))+ half screen height"

I think this would be
Quote: "screeny = ((y+cameray) / (z-cameraz))+ half screen height"

as screeny goes from top to bottom.
I understand the "x/z" thing now, you just need to add more parameters to this equation. I'm not sure but I think its

This doesn't look right to me but you need to use the camera angles in there somewhere.
Like TDK said, the default rotation of the camera is 0,0,0 so try to add in the camera angle variables so that it looks the same with 0,0,0 rotation.

Are you using an object origin and then offsetting each vertex, or are the vertices independent?

Your signature has been erased by a mod because it was rubbish.
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 17th Aug 2007 02:18
@TDK
Quote: "You just alter the point of rotation to the viewport which is normally 0,0,0"

Isn't that just rotating the object around it's own axis? That's what I end up doing. But something came to mind I'll post at the end.

@OBese87
Quote: "screeny = ((y+cameray)/(z-cameraz)) + halfscreen*camera_angleX"


No, I don't want to include the angle there. And yes, y+cameray does make sense from a certain approach. If I'm thinking of absolute positions, then it makes sense to use the +. If I think in terms of screen position and offsets, I want to use the -. If I look at the camera at the center of the screen (800x600) at 400,300 or 0,0 then to move the camera up, I offset it -num . But I'm gonna use your suggestion y+cameray and see how that goes.

One thing that dawned on me, I wasn't including the feild of view in my calculations. If I do, I can think of a way to rotate the points of the world around the camera position.

Enjoy your day.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 17th Aug 2007 03:17
Quote: "If I'm thinking of absolute positions, then it makes sense to use the +. If I think in terms of screen position and offsets, I want to use the -. If I look at the camera at the center of the screen (800x600) at 400,300 or 0,0 then to move the camera up, I offset it -num . But I'm gonna use your suggestion y+cameray and see how that goes."

hmmm "-" does actually make sense, assuming that positive Y is upwards.
I can see how FOV would help a lot with your calculations, it's probably very important actually lol. Then you can add realistic perspective

Your signature has been erased by a mod because it was rubbish.

Login to post a reply

Server time is: 2025-05-30 13:39:22
Your offset time is: 2025-05-30 13:39:22