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.

Dark GDK / rotate camera around object question

Author
Message
Gatorules
15
Years of Service
User Offline
Joined: 17th Dec 2008
Location:
Posted: 17th Feb 2009 04:06
I wrote this code and it worked fine at first but then I began having trouble when i added a second part to it. the code is meant to rotate the camera in a circle around an object. It is able to rotate around the y-axis, but when i tried having it rotate around the x-axis it began to function strangely. also the speeds when you rotate are faster one way than the other and slower at certain points. help is greatly appreciated. here is my code

Matty H
16
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 17th Feb 2009 14:21
Sometimes when things aren't going right with sin and cos I try swapping them around and changing negative values to positive values etc..
This is not a good solution but it sometimes works.

The two functions are identical so I cant see why it wouldn't work other than getting the axis mixed up or some other part of your program interfering.
Gatorules
15
Years of Service
User Offline
Joined: 17th Dec 2008
Location:
Posted: 17th Feb 2009 17:16
if no can answer my first question is there a way to rotate an object independent of the axises. i need it to rotate relative to the way it is facing
Gatorules
15
Years of Service
User Offline
Joined: 17th Dec 2008
Location:
Posted: 18th Feb 2009 08:16
i think my problem is that the distance around the object on the z axis gets smaller when it gets smaller when the camera is rotated on the y axis but i still need help. anyone?
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 18th Feb 2009 11:13
Hey aren't ObjectPosition and CameraPosition messed?



At least there is no dbCameraPositionY(id), as 'id' is the object number, and there is no camera 1, right?
Gatorules
15
Years of Service
User Offline
Joined: 17th Dec 2008
Location:
Posted: 18th Feb 2009 21:42
thank you for that. i changed the code but it still doesn't work right so can someone please help me.

Here's my changed code:

#include "DarkGDK.h"

void rotatecameraaroundobjectY(int id, int distance, float speed)
{
if (speed<0)
{
speed=360+speed*5/3;
}
dbPositionCamera(dbObjectPositionX(id), dbCameraPositionY(), dbObjectPositionZ(id));
dbPositionCamera ( dbCameraPositionX()+dbSin(dbCameraAngleY()+180-speed)*distance, dbCameraPositionY(), dbCameraPositionZ()+dbCos(dbCameraAngleY()+180-speed)*distance );
dbPointCamera(dbObjectPositionX(id), dbCameraPositionY(), dbObjectPositionZ(id));
}

void rotatecameraaroundobjectX(int id, int distance, float speed)
{
if (speed<0)
{
speed=360+speed*5/3;
}
dbPositionCamera(dbCameraPositionX(), dbObjectPositionY(id), dbObjectPositionZ(id));
dbPositionCamera ( dbCameraPositionX(), dbCameraPositionY()+dbCos(dbCameraAngleX()+180-speed)*distance, dbCameraPositionZ()+dbSin(dbCameraAngleX()+180-speed)*distance );
dbPointCamera(dbCameraPositionX(), dbObjectPositionY(id), dbObjectPositionZ(id));
}

void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );

dbLoadImage("cube.bmp",1);
dbMakeObjectCube(1,100);
dbTextureObject (1, 1);
dbPositionCamera(0,0,-300);

int distancex, distancey;

while ( LoopGDK ( ) )
{

//camera movement
distancex=dbSQRT( ( dbCameraPositionZ()-dbObjectPositionZ(1) )*( dbCameraPositionZ()-dbObjectPositionZ(1) ) + ( dbCameraPositionY()-dbObjectPositionY(1) )*( dbCameraPositionY()-dbObjectPositionY(1) ) );
distancey=dbSQRT( ( dbCameraPositionZ()-dbObjectPositionZ(1) )*( dbCameraPositionZ()-dbObjectPositionZ(1) ) + ( dbCameraPositionX()-dbObjectPositionX(1) )*( dbCameraPositionX()-dbObjectPositionX(1) ) );
if( dbUpKey() )
{
rotatecameraaroundobjectX(1, distancex, 1);
}
if( dbDownKey() )
{
ro tatecameraaroundobjectX(1, distancex, -1);
}
if( dbRightKey() )
{
rotatecameraaroundobjectY(1, distancey, 1);
}
if( dbLeftKey() )
{
rotatecameraaroundobjectY(1, distancey, -1);
}
dbSync();

}
return;
}
Pharoseer
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: Right behind you
Posted: 19th Feb 2009 01:46
Hey Gator,

Try this code snippet and see if it helps:



Hope this helps,

-Frank
Gatorules
15
Years of Service
User Offline
Joined: 17th Dec 2008
Location:
Posted: 19th Feb 2009 03:04
thank you very much, Pharoseer. your code didnt solve all of my problems but it gave me something that actually functioned somewhat the way i wanted
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 19th Feb 2009 09:45
From my orbit camera class:

orbitOffset.x = cos( orbitRot.x ) * sin( orbitRot.y );
orbitOffset.y = -sin( orbitRot.x );
orbitOffset.z = cos( orbitRot.x ) * cos( orbitRot.y );

Hayer
19
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 20th Feb 2009 00:18
just some off-topic.

Dark coder: Can I use ur lib in commercial products for free?

Keep it simple.
Questions? Mail me

Login to post a reply

Server time is: 2024-11-25 15:35:09
Your offset time is: 2024-11-25 15:35:09