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.

Newcomers DBPro Corner / Camera Movement Problems

Author
Message
Pbcrazy
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: ...pillow room...
Posted: 15th Jan 2009 04:01
well, im sure you might be asking yourself, "Why the hell can't PB figure this shiz out on his own?!?!" lol, but alas, i can't

anyway, after a good 6 hours of trying different stuff, i still can't get my camera movement to work quite right.

for the most part, i can look around and move forwards and backwords (using the cameras Z axis for that)

however every time i try to make it strafe left or right, it will just move along the main axis (the X one i believe.), when i'd like it to move along the camera's local X axis.

:S, so ive tried several things and i've deleted all of them (didnt work so...)

but, ive tried: POSITION CAMERA, MOVE CAMERA/ROTATE CAMERA. Neither of these really worked.

so don't suppose anybody can tell me the correct command i should be using, or how i should really be using one of those?

also, if anyone can tell me if there is anything i could do better code wise, i'd like to know.



Pillarofire
20
Years of Service
User Offline
Joined: 31st Dec 2003
Location: Good Question, <looks around.>
Posted: 15th Jan 2009 09:46 Edited at: 15th Jan 2009 09:48


You are only increasing the x and z values by 1 for every cycle the key is pressed. Which is on the right track, but ideally you will want to increase them by a ratio that is determined by the angle of the camera.

Start by thinking of the new coordinate as a vertex on a 90 degree angle triangle. Its first vertex is the camera's current position (x#,z#), the second vertex is the point we are trying to calculate (newx#,newz#) and the angle between the horizontal leg and the longest leg is the camera's Y angle:



What you need is Trigonometry for Sine=sin() and Cosine=cos():

First rule is:
sin( angle# ) = opposite# / hypotenuse#

Use algebra to find opposite:
opposite# = hypotenuse# * sin( angle# )

Secondly:
cos( angle# ) = adjacent# / hypotenuse#

Algebra again for the adjacent:
adjacent# = hypotenuse# * sin( angle# )

As you can see from the picture the horizontal leg is the same length as the distance into the x axis that we need to calculate, so:
adjacent# = newx# - x#
so
newx# = x# + adjacent#

The same holds true for the opposite, or the distance on the z axis:
opposite# = newz# - z#
so
newz# = z# + opposite#

So now we just plug in the trig portion to end up with:
newx# = x# + (hypotenuse# * sin( angle# ))
newz# = z# + (hypotenuse# * cos( angle# ))

So uh, well, what is the hypotenuse#? Well if the hypotenuse is zero then the new point will just equal the old point. Right? And if the hypotenuse is one, then newx# will be sin(angle#) and newz# will be cos(angle#). So in effect the hypotenuse is the distance we want to move.

So what actually happens when the angle changes? Well since sin(angle#) is a ratio of the opposite to the hypotenuse, it is pretty apparent that the angle will change when the opposite leg changes in length and the hypotenuse remains the same. So in reverse, if the angle changes, the opposite will change with it according to the ratio of sin(angle#). Same is true for cosine, only with adjacent and hypotenuse being the players.

So how can you use this in your code? Just like this:

Attachments

Login to view attachments
Cloggy
19
Years of Service
User Offline
Joined: 31st Oct 2004
Location: Rayleigh, Essex
Posted: 15th Jan 2009 11:17
Probably the easiest way to move the camera is to use the turn camera left/right command in conjunction with the move camera command. For example



The turn camera command also works on the local cameras local axis not the global one.

Pbcrazy
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: ...pillow room...
Posted: 15th Jan 2009 14:27 Edited at: 15th Jan 2009 14:39
pillarofire - thanks for the little tut! although a bit confusing (i havent taken trig yet, and not quite sure what sin and cos really do)

i think i might be able to figure it out after reading a time or 5, although, i think i understand your code example better than the english explanation XD

cloggy - aye, ill prolly end up using that until i can figure out what goes on with pillar's way lol

edit: alrighty, i tried out both ways, and niether worked quite right. Cloggy's way, made it end up having two models that looked like they had been flipped horizontially across the screen. and it had kinda a wierd...uhh updating screen affect. :S

pillar's way worked pretty well, except i couldn't make it move up or down based on the cameras X angle (if thats a way to put it:S)

Cloggy
19
Years of Service
User Offline
Joined: 31st Oct 2004
Location: Rayleigh, Essex
Posted: 15th Jan 2009 14:42
That maybe bacause you are using sync but have not called sync on. It is probably syncing after turning then syncing when it turns back so you get 2 quick displays.

If you're using sync you should use sync on as well.

Pbcrazy
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: ...pillow room...
Posted: 16th Jan 2009 01:19
nope still muffed up, its wierd, idk whats wrong

maybe i didn't plug it in right idk,

try compiling this code and tell me what you get.



Cloggy
19
Years of Service
User Offline
Joined: 31st Oct 2004
Location: Rayleigh, Essex
Posted: 16th Jan 2009 01:52
PbCrazy,

I've had a quick look and this is what I've come up with so far.



I's a little late at the moment so I'm not thinking so clearly, but it should give you some ideas.

Cloggy
19
Years of Service
User Offline
Joined: 31st Oct 2004
Location: Rayleigh, Essex
Posted: 16th Jan 2009 13:38
I've update this a little. Don't be alarmed but this code was written using DGDK.Net so it looks a little different, but I haven't got DBPro installed on this work machine. The commands relate directly to the DBPro ones so conversion shouldn't be too difficult for you.

The code uses a cube object to represent the camera location and rotation on the x/z axis. By using an object you can isolate the camera up down look code from the movement code, otherwise if you look up/down and then move you will start moveing up/down which we don't want.

The first step is to apply the look left/right and movement code. We then position and orient the camera to match the object and apply the up/down angle.



Hope this helps

Pbcrazy
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: ...pillow room...
Posted: 16th Jan 2009 14:30
aye, but thats kinda what i want, if you look up then press forward, you will move up, etc

like the camera controls on 3D World Studio, if you are familiar with them.

either way, i dont have time to look over the code right now, i will when i get back from school.

Login to post a reply

Server time is: 2024-09-28 00:19:52
Your offset time is: 2024-09-28 00:19:52