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 Professional Discussion / 3D Camera Rotation about object X axis

Author
Message
OzBot
23
Years of Service
User Offline
Joined: 24th Feb 2003
Location: Sweden
Posted: 2nd May 2003 19:52
I am trying to write some code to rotate a camera around the x-axis of an object, based on the objects X angle. I have managed to code a camera rotation around an objects Y axis but I can't do the same around the X-axis. (I don’t know the algorithm)

The code Snippet is a working example of my Y-axis rotation (this doesn’t need fixing)
If someone could maybe let me know the equivalent code for a X-axis rotation I would be very grateful...


if leftkey()=1 then yrotate object ship,wrapvalue(object angle y(ship)-1)
if rightkey()=1 then yrotate object ship,wrapvalue(object angle y(ship)+1)
if shiftkey()=1 then move object ship,1
if controlkey()=1 then move object ship,-1

DISTANCE = -1.5


objectX# = object POSITION X(ship)
objectZ# = object POSITION z(ship)

objectAngleX# = object ANGLE X(ship)
objectAngleY# = object ANGLE Y(ship)

cameraX# = objectX# + DISTANCE * sin(objectAngleY#)
cameraZY# = objectZ# + DISTANCE * cos(objectAngleY#)


POSITION camera cameraX#,object position y(ship)+.4,cameraZy#
point camera object position x(ship),object position y(ship)+.4,object position z(ship)
APEXnow
Retired Moderator
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 2nd May 2003 19:55
OzBot, seems excessive, use

Point Camera 0, Object Position X(1), Object Position Y(1), Object Position Z(1)
Set Camera To Follow 0, Object Position X(1), Object Position Y(1), Object Position Z(1), fAngle, 4, Object Position Y(1) + 2, 1, 0

But play with the code to suit your object position. fAngle can be changed based on what angle you want the camera to look from.

"Man who looses key to woman's appartment...... He get no nookie" - A wise chinese man.
APEXnow
Retired Moderator
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 2nd May 2003 19:57
Ahh, I see what you're trying to do... <-- Looking at code even further

"Man who looses key to woman's appartment...... He get no nookie" - A wise chinese man.
OzBot
23
Years of Service
User Offline
Joined: 24th Feb 2003
Location: Sweden
Posted: 2nd May 2003 20:02
It may be excessive however it is transferrable to other languages, and I want to learn the algorithms.
APEXnow
Retired Moderator
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 2nd May 2003 20:06
Is it possible to use the Set Camera To Follow command but instead of using a fixed height above or below your object, you use the Sin function with the fAngle to change the location of the camera?

"Man who looses key to woman's appartment...... He get no nookie" - A wise chinese man.
OzBot
23
Years of Service
User Offline
Joined: 24th Feb 2003
Location: Sweden
Posted: 2nd May 2003 20:20
Just to make sure you understand. The code above is a working example of y axis rotation I need the same sort of code but based on the X axis.

I tried the following but it is wrong:
if upkey()=1 then xrotate object ship,wrapvalue(object angle x(ship)+1)
if downkey()=1 then xrotate object ship,wrapvalue(object angle x(ship)-1)
if shiftkey()=1 then move object ship,1
if controlkey()=1 then move object ship,-1

DISTANCE = -1.5

objectY# = object POSITION y(ship)
objectZ# = object POSITION z(ship)

objectAngleX# = object ANGLE X(ship)

cameraY# = objectY# + DISTANCE * sin(objectAngleX#)
cameraZX# = objectZ# + DISTANCE * cos(objectAngleX#):rem i think this is wrong

POSITION camera object position x(ship), cameraY#,cameraZX#
point camera object position x(ship),object position y(ship),object position z(shiP)


All my experiments with Set Camera To Follow only seem to work on y axis rotations..
APEXnow
Retired Moderator
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 2nd May 2003 20:46
OzBot, I tried the code, the camera does indeed rotate around the X axis of the object but if I'm right in thinking that you want the object to remain fixed within the camera view as the object moves, I did it by modifying the line

objectAngleX# = object ANGLE X(ship)

to

objectAngleX# = 180 - object ANGLE X(ship)

I hope that this is what you mean.

The thing with Sin is that it doesn't go all the way to 360, only 180.
I haven't done Trigonometry for some time, need to brush up on it I think lol.

Tell me if this is what you're attempting to achieve.

"Man who looses key to woman's appartment...... He get no nookie" - A wise chinese man.
OzBot
23
Years of Service
User Offline
Joined: 24th Feb 2003
Location: Sweden
Posted: 2nd May 2003 21:31
Yes that is much closer to what I am trying to achieve, however I need it to go all the way around as oppose to inverting when it gets to 180, also it views the object from the front as opposed to the back but I changed the distance value to +1.5 and it sorted that out...

Funny that the code works perfect all the way around the y axis.
APEXnow
Retired Moderator
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 2nd May 2003 21:35
You may need to apply a condition to change the angle depending on whether the actual angle exceeds 180, I did this ages ago in C++ but I need to fish out the code to remember lol.

"Man who looses key to woman's appartment...... He get no nookie" - A wise chinese man.
OzBot
23
Years of Service
User Offline
Joined: 24th Feb 2003
Location: Sweden
Posted: 2nd May 2003 21:48
Need a worm

Yeh i was thinking of that very same thing (Applying a condition). However I want to be able to do it based on a formula, it must be possible.

I can't understand how the code works perfect around the y axis but not the X axis.
APEXnow
Retired Moderator
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 2nd May 2003 21:49
I'll see if I can fish out that ol code

"Man who looses key to woman's appartment...... He get no nookie" - A wise chinese man.
APEXnow
Retired Moderator
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 2nd May 2003 22:00
It's just occurred to me that the problem is not your formular, it's the camera, if you think about it, as you rotate past the 180 degree mark, the camera automatically rotates 180 so that the Top angle is always up, in your condition, you need to Roll the camera 180 so that the object is always in view even if it's upside down.

"Man who looses key to woman's appartment...... He get no nookie" - A wise chinese man.
OzBot
23
Years of Service
User Offline
Joined: 24th Feb 2003
Location: Sweden
Posted: 2nd May 2003 23:26
Hey I did it,
instead of using the point camera command I SET CAMERA TO OBJECT ORIENTATION ship.

Point camera must automatically flip the camera when over 90 degrees and flips back over 270.

Cheers for the help APEXnow...
APEXnow
Retired Moderator
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 2nd May 2003 23:31
Glad it worked

"Man who looses key to woman's appartment...... He get no nookie" - A wise chinese man.

Login to post a reply

Server time is: 2026-07-10 21:40:35
Your offset time is: 2026-07-10 21:40:35