#### Archived

This topic is now archived and is closed to further replies.

# problem with movement dependent on camera pos.

This topic is 6110 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, my problem is I want to move an object(box) for example to the right side of camera view. I don''t want to move it along any axis, but in any direction of the cam. view. I have 2 floats: m_fX and m_fZ, which contain angles of camera rotation. So I used this formula to move the ob- ject: m_object''sX+=sinf(m_fX)*(value determining how much to move the obj.:2,-1,0,3,etc.)*0.1f m_object''sY-=cosf(m_fY)*(as above) It doesn''t work correctly. Can anybody take look at it? Thanks in advance

##### Share on other sites
void CCamera::Render()
{
if (FreeLook) // If the User Controls the View of the Cam
{
glRotatef(Xrot , 1.0 , 0.0 , 0.0 );
glRotatef(Yrot , 0.0 , 1.0 , 0.0 );
glRotatef(Zrot , 0.0 , 0.0 , 1.0 );
glTranslatef( -position.x , -position.y , -position.z );
}
else
{
// Camera Looking at an Object
// The View of the Cam --> CamPosition - Object( that we are looking)
Vector3f view = Get3DVector( &LookAt , &position );
Normalize3DVector( &view ); // Len of the Vector to 1

Vector2f XZ; // 2 Dimensional Vecor & Scaling them to the Len of 1!
GLfloat c;
c = (float)1/sqrt( view.x * view.x + view.z * view.z );
XZ.x = (float)view.x * c;
XZ.y = (float)view.z * c;

// Calculate the Rotation to the Object the Cam is Fixed at!
Xrot = -asin( view.y ) * RADtoDEG;
Yrot = RADtoDEG * atan2( XZ.y , XZ.x ) + 90;
Zrot = 0.0;

glRotatef(Xrot , 1.0 , 0.0 , 0.0 );
glRotatef(Yrot , 0.0 , 1.0 , 0.0 );
glRotatef(Zrot , 0.0 , 0.0 , 1.0 );
glTranslatef( -position.x , -position.y , -position.z );
}

}

I think that was what you needed ...

And if you need it in the Other Direction ... From Angles to a Vector ( for Collision Detection Maybe )

Direction.x = -sin(Yrot*PI_OVER_180) * cos (Xrot * PI_OVER_180);
Direction.y = sin(Xrot*PI_OVER_180);
Direction.z = cos(Yrot*PI_OVER_180) * cos (Xrot * PI_OVER_180);

J@n

##### Share on other sites
Does anybody have an example in DX8?

##### Share on other sites
I meant object moving with mouse like in 3dsmax4.

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 10
• 14
• 30
• 13
• 11
• ### Forum Statistics

• Total Topics
631788
• Total Posts
3002356
×