Sign in to follow this  
unlucky

newbie camera problem...couldnt find answer in search...

Recommended Posts

Hello Game Devs, Q1: I have a fps camera class, everything wroks fine except rotating with mouse pointer movement. The problem is it pans the view instead of rotating it, I dont know why. view rotating code...in camera class
if( Mouse.PointX != middleX && Mouse.PointY != middleY )
{
	_rotation.Identity();
	
	_rotation.Rotate( -( float )( Mouse.PointY - middleY ) * 0.0005f, _right );
	_rotation.TransformVector( ref _look );
	_rotation.TransformVector( ref _up );
	
	_rotation.Rotate( -( float )( Mouse.PointX - middleX ) * 0.0005f, new Point3D( 0.0f, 1.0f, 0.0f ) );
	_rotation.TransformVector( ref _look );
	_rotation.TransformVector( ref _up );
}



utility functions... (this is in matrix class)
public void Rotate( float angle, Point3D axis )
{
	float sin = ( float )Math.Sin( Math3D.DegreeToRadian( angle ) );
	float cos = ( float )Math.Cos( Math3D.DegreeToRadian( angle ) );
	
	axis = Math3D.Normalize( axis );
	
	this[ 0 ]  = cos + ( 1.0f - cos ) * axis.X;
	this[ 1 ]  = ( 1.0f - cos ) * axis.X * axis.Y + sin * axis.Z;
	this[ 2 ]  = ( 1.0f - cos ) * axis.X * axis.Z - sin * axis.Y;
	this[ 3 ]  = 0;
				
	this[ 4 ]  = ( 1.0f - cos ) * axis.Y * axis.X - sin * axis.Z;
	this[ 5 ]  = cos + ( 1.0f - cos ) * ( float )Math.Pow( ( double )axis.Y, 2.0d );
	this[ 6 ]  = ( 1.0f - cos ) * axis.Y * axis.Z + sin * axis.X;
	this[ 7 ]  = 0;
	
	this[ 8 ]  = ( 1.0f - cos ) * axis.Z * axis.X + sin * axis.Y;
	this[ 9 ]  = ( 1.0f - cos ) * axis.Z * axis.Z - sin * axis.X;
	this[ 10 ] = cos + ( 1.0f - cos ) * ( float )Math.Pow( ( double )axis.Z, 2.0d );
	this[ 11 ] = 0;
	
	this[ 12 ] = 0;
	this[ 13 ] = 0;
	this[ 14 ] = 0;
	this[ 15 ] = 1.0f;
}

public void TransformPoint( ref Point3D point )
{
	point.X = point.X * this[ 0 ] + point.Y * this[ 4 ] + point.Z * this[ 8 ] + this[ 12 ];
	point.Y = point.X * this[ 1 ] + point.Y * this[ 5 ] + point.Z * this[ 9 ] + this[ 13 ];
	point.Z = point.X * this[ 2 ] + point.Y * this[ 6 ] + point.Z * this[ 10 ] + this[ 14 ];
}

public void TransformVector( ref Point3D vector )
{
	vector.X = vector.X * this[ 0 ] + vector.Y * this[ 4 ] + vector.Z * this[ 8 ];
	vector.Y = vector.X * this[ 1 ] + vector.Y * this[ 5 ] + vector.Z * this[ 9 ];
	vector.Z = vector.X * this[ 2 ] + vector.Y * this[ 6 ] + vector.Z * this[ 10 ];
}

Thanks in advance. :)

Share this post


Link to post
Share on other sites
Hum, personnaly for a simple FPS view you complicate yourseft...

Juste hold que X and Z angles (in 3d max coor system)
and set your view with gluLookAt(position.x, .y, .z, Target.x, .y, .z, 0,0,1);
With sin() and cos()

gluLookAt(position.x, position.y, position.z,
position.x + cos(angleZ)*cos(angleX),
position.y + sin(angleZ)*cos(angleX),
position.z + sin(angleX),
0,0,1);

Share this post


Link to post
Share on other sites
I'm assuming this is C++? If so, why are you accessing the this pointer as an array? It probably won't do what you think.

Enigma

Share this post


Link to post
Share on other sites
Daivuk:
well...I thought this way is better...
_

Enigma:
it is c#...and those "this" are indexer...it is in my matrix class...
_

forget it guys...I am going back directx...I just faced problems with glDrawArrays and so...and there will be lots of other problems in the future till I learn opengl...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this