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 / Need advice please. I can't work out how to circle the camera around a point or object.

Author
Message
SpiritX
20
Years of Service
User Offline
Joined: 15th Jan 2004
Location:
Posted: 16th Jan 2004 02:36
I'm trying to get the camera to circle, with a fixed y value,a point in space but I can't get my head around how I can calculate the distance from the camera to the point as the crow flies if you see what I mean. I think the answer may be in the newxvalue(point,angle,distance) command but I really don't have a good grasp of how the angle part of it works. Are the angles measured as if the z axis represents 0 180 degrees while the x axis represents 090 and 270 (in the case of a y rotation) or am I thinking about it in the wrong way?

Thanks in advance for your help. Oh yeah and its normal DB btw.
Bishop
21
Years of Service
User Offline
Joined: 18th Dec 2002
Location: In my favorite chair...
Posted: 16th Jan 2004 05:09
hey SpiritX,
here use this code....i used the set camera to follow commands and just made it so you can change the angle that you are looking....

cheers,
Bishop

"When you were born, you cried and the world rejoiced. Live so when you die, the world cries and you rejoice."
walaber
20
Years of Service
User Offline
Joined: 22nd Oct 2003
Location: Los Angeles, CA
Posted: 16th Jan 2004 05:41
or just whip up some trig...

basically, if you want to rotate around the Y axis, then you need an angle to represent this. for example:

camera_angle# = 30.0

then you need a distance from the target:

camera_distance# = 150.0 (any appropriate number will do)

then all you have to do it use cos() and sin() to find the X and Z values. have a look at this triangle diagram:



here we are looking DOWN at the game world (Y axis is coming straight at us). the + sign is the camera location. A is the angle, d is the distance. we can turn these values into an X and Z component. with simple trig.

sin(A) = z/d
cos(A) = x/d

then we solve for x and z (the values we're looking for)

z = sin(A) * d
x = cos(A) * d

now slap this into code:

camera_x# = sin(camera_angle#) * camera_distance#
camera_z# = cos(camera_angle#) * camera_distance#

then just do this:

position camera camera_x,100.0,camera_z
point camera 0,0,0

note: you can change the 100.0 to any value, adjusting the height of the camera.

to make the camera follow an ombject, just add the following code:

position camera object_x+camera_x,object_y+100.0,object_z+camera_z
point camera object_x,object_y,object_z

then you can just change the camera_angle value, and the camera will spin around the object!!!

p.s. I'm not around DB right now, so if there is any syntax errors in this code I apologize.

good luck!!

Go Go Gadget DBPRO!
SpiritX
20
Years of Service
User Offline
Joined: 15th Jan 2004
Location:
Posted: 17th Jan 2004 04:07 Edited at: 17th Jan 2004 04:16
Thanks a lot for the help, both ideas are very useful. Unfortunately Walaber it's been about 10 years since I had any need to use trig and I'm just starting to get back up to speed with it, but I do just about follow your approach. Also the simplicity of your suggestion Bishop is a breath of fresh air. But could you explain the smoothness and colflag parameters in the SET CAMERA TO FOLLOW command as, for some reason, that command is not in my manual and the help files don't explain how they work.

I have one more question:

I am programming a 3rd person helicopter game where the chopper is mouse controlled. Basically I want it to work so that the chopper turns to face which ever direction you move the mouse in . ie if you move the mouse forward and left the nose will come round to face north west (if z is north-south).

Any advice on how to achieve this would be most welcome, bearing in mind that my camera will be tracking the chopper from position copperX,chopperY,chopperZ-50., possibly with user rotation around the chopper, but this would complicate things alot due to the controls having a different point of reference, or am I wrong?

I know about the mousemove commands but what I want is to interpret the mouse input as an angle for the nose to turn to. But How?

It's like an old Amiga game called Zeewolf, anyone remember that?
zircher
21
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 17th Jan 2004 05:51
Save your old mouse postion between each loop. The difference between the old values and mouseX and mouseY is your 'control vector'.


I'd use the X delta to control the amount of turning and the Y delta to control forwards and backwards.
--
TAZ

Login to post a reply

Server time is: 2024-09-21 15:34:49
Your offset time is: 2024-09-21 15:34:49