Further work on matrix reform. Kinda.
git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@1390 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
parent
f8cb607c60
commit
1df2a18a3d
@ -207,6 +207,7 @@ typedef struct
|
||||
|
||||
- (void) setOrientation:(Quaternion) quat;
|
||||
- (Quaternion) orientation;
|
||||
- (void) orientationChanged;
|
||||
|
||||
- (void) setVelocity:(Vector)vel;
|
||||
- (Vector) velocity;
|
||||
|
@ -575,7 +575,7 @@ static NSString * const kOOLogEntityUpdateError = @"entity.linkedList.update.
|
||||
- (void) setOrientation:(Quaternion) quat
|
||||
{
|
||||
orientation = quat;
|
||||
quaternion_into_gl_matrix(orientation, rotMatrix);
|
||||
[self orientationChanged];
|
||||
}
|
||||
|
||||
|
||||
@ -585,6 +585,13 @@ static NSString * const kOOLogEntityUpdateError = @"entity.linkedList.update.
|
||||
}
|
||||
|
||||
|
||||
- (void) orientationChanged
|
||||
{
|
||||
quaternion_normalize(&orientation);
|
||||
quaternion_into_gl_matrix(orientation, rotMatrix);
|
||||
}
|
||||
|
||||
|
||||
- (void) setVelocity:(Vector) vel
|
||||
{
|
||||
velocity = vel;
|
||||
@ -672,9 +679,8 @@ static NSString * const kOOLogEntityUpdateError = @"entity.linkedList.update.
|
||||
quaternion_rotate_about_z(&orientation, -roll);
|
||||
if (climb)
|
||||
quaternion_rotate_about_x(&orientation, -climb);
|
||||
|
||||
quaternion_normalize(&orientation);
|
||||
quaternion_into_gl_matrix(orientation, rotMatrix);
|
||||
|
||||
[self orientationChanged];
|
||||
}
|
||||
|
||||
|
||||
@ -690,8 +696,7 @@ static NSString * const kOOLogEntityUpdateError = @"entity.linkedList.update.
|
||||
if (yaw)
|
||||
quaternion_rotate_about_y(&orientation, -yaw);
|
||||
|
||||
quaternion_normalize(&orientation);
|
||||
quaternion_into_gl_matrix(orientation, rotMatrix);
|
||||
[self orientationChanged];
|
||||
}
|
||||
|
||||
|
||||
@ -729,10 +734,11 @@ static NSString * const kOOLogEntityUpdateError = @"entity.linkedList.update.
|
||||
Vector offset = [self viewpointOffset];
|
||||
|
||||
// FIXME: this ought to be done with matrix or quaternion functions.
|
||||
OOMatrix r = OOMatrixFromGLMatrix(rotMatrix);
|
||||
|
||||
viewpoint.x += offset.x * rotMatrix[0]; viewpoint.y += offset.x * rotMatrix[4]; viewpoint.z += offset.x * rotMatrix[8];
|
||||
viewpoint.x += offset.y * rotMatrix[1]; viewpoint.y += offset.y * rotMatrix[5]; viewpoint.z += offset.y * rotMatrix[9];
|
||||
viewpoint.x += offset.z * rotMatrix[2]; viewpoint.y += offset.z * rotMatrix[6]; viewpoint.z += offset.z * rotMatrix[10];
|
||||
viewpoint.x += offset.x * r.m[0][0]; viewpoint.y += offset.x * r.m[1][0]; viewpoint.z += offset.x * r.m[2][0];
|
||||
viewpoint.x += offset.y * r.m[0][1]; viewpoint.y += offset.y * r.m[1][1]; viewpoint.z += offset.y * r.m[2][1];
|
||||
viewpoint.x += offset.z * r.m[0][2]; viewpoint.y += offset.z * r.m[1][2]; viewpoint.z += offset.z * r.m[2][2];
|
||||
|
||||
return viewpoint;
|
||||
}
|
||||
|
@ -2033,6 +2033,29 @@ double scoopSoundPlayTime = 0.0;
|
||||
}
|
||||
|
||||
|
||||
- (void) orientationChanged
|
||||
{
|
||||
quaternion_normalize(&orientation); // probably not strictly necessary but good to do to keep orientation sane
|
||||
quaternion_into_gl_matrix(orientation, rotMatrix);
|
||||
|
||||
v_right.x = rotMatrix[0];
|
||||
v_right.y = rotMatrix[4];
|
||||
v_right.z = rotMatrix[8];
|
||||
|
||||
v_up.x = rotMatrix[1];
|
||||
v_up.y = rotMatrix[5];
|
||||
v_up.z = rotMatrix[9];
|
||||
|
||||
v_forward.x = rotMatrix[2];
|
||||
v_forward.y = rotMatrix[6];
|
||||
v_forward.z = rotMatrix[10];
|
||||
|
||||
orientation.w = -orientation.w;
|
||||
quaternion_into_gl_matrix(orientation, playerRotMatrix); // this is the rotation similar to ordinary ships
|
||||
orientation.w = -orientation.w;
|
||||
}
|
||||
|
||||
|
||||
- (void) applyRoll:(GLfloat) roll1 andClimb:(GLfloat) climb1
|
||||
{
|
||||
if (roll1 == 0.0 && climb1 == 0.0 && hasRotated == NO)
|
||||
@ -2058,24 +2081,7 @@ double scoopSoundPlayTime = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
quaternion_normalize(&orientation); // probably not strictly necessary but good to do to keep orientation sane
|
||||
quaternion_into_gl_matrix(orientation, rotMatrix);
|
||||
|
||||
v_right.x = rotMatrix[0];
|
||||
v_right.y = rotMatrix[4];
|
||||
v_right.z = rotMatrix[8];
|
||||
|
||||
v_up.x = rotMatrix[1];
|
||||
v_up.y = rotMatrix[5];
|
||||
v_up.z = rotMatrix[9];
|
||||
|
||||
v_forward.x = rotMatrix[2];
|
||||
v_forward.y = rotMatrix[6];
|
||||
v_forward.z = rotMatrix[10];
|
||||
|
||||
orientation.w = -orientation.w;
|
||||
quaternion_into_gl_matrix(orientation, playerRotMatrix); // this is the rotation similar to ordinary ships
|
||||
orientation.w = -orientation.w;
|
||||
[self orientationChanged];
|
||||
}
|
||||
|
||||
/*
|
||||
@ -2086,25 +2092,8 @@ double scoopSoundPlayTime = 0.0;
|
||||
- (void) applyYaw:(GLfloat) yaw
|
||||
{
|
||||
quaternion_rotate_about_y(&orientation, -yaw);
|
||||
|
||||
quaternion_normalize(&orientation); // probably not strictly necessary but good to do to keep orientation sane
|
||||
quaternion_into_gl_matrix(orientation, rotMatrix);
|
||||
|
||||
v_right.x = rotMatrix[0];
|
||||
v_right.y = rotMatrix[4];
|
||||
v_right.z = rotMatrix[8];
|
||||
|
||||
v_up.x = rotMatrix[1];
|
||||
v_up.y = rotMatrix[5];
|
||||
v_up.z = rotMatrix[9];
|
||||
|
||||
v_forward.x = rotMatrix[2];
|
||||
v_forward.y = rotMatrix[6];
|
||||
v_forward.z = rotMatrix[10];
|
||||
|
||||
orientation.w = -orientation.w;
|
||||
quaternion_into_gl_matrix(orientation, playerRotMatrix); // this is the rotation similar to ordinary ships
|
||||
orientation.w = -orientation.w;
|
||||
|
||||
[self orientationChanged];
|
||||
}
|
||||
|
||||
|
||||
|
@ -2675,6 +2675,16 @@ static GLfloat mascem_color2[4] = { 0.4, 0.1, 0.4, 1.0}; // purple
|
||||
}
|
||||
|
||||
|
||||
- (void) orientationChanged
|
||||
{
|
||||
[super orientationChanged];
|
||||
|
||||
v_forward = vector_forward_from_quaternion(orientation);
|
||||
v_up = vector_up_from_quaternion(orientation);
|
||||
v_right = vector_right_from_quaternion(orientation);
|
||||
}
|
||||
|
||||
|
||||
- (void) applyRoll:(GLfloat) roll1 andClimb:(GLfloat) climb1
|
||||
{
|
||||
Quaternion q1 = kIdentityQuaternion;
|
||||
@ -2685,12 +2695,7 @@ static GLfloat mascem_color2[4] = { 0.4, 0.1, 0.4, 1.0}; // purple
|
||||
if (climb1) quaternion_rotate_about_x(&q1, -climb1);
|
||||
|
||||
orientation = quaternion_multiply(q1, orientation);
|
||||
quaternion_normalize(&orientation); // probably not strictly necessary but good to do to keep orientation sane
|
||||
quaternion_into_gl_matrix(orientation, rotMatrix);
|
||||
|
||||
v_forward = vector_forward_from_quaternion(orientation);
|
||||
v_up = vector_up_from_quaternion(orientation);
|
||||
v_right = vector_right_from_quaternion(orientation);
|
||||
[self orientationChanged];
|
||||
}
|
||||
|
||||
|
||||
@ -4500,9 +4505,7 @@ BOOL class_masslocks(int some_class)
|
||||
}
|
||||
|
||||
quaternion_rotate_about_axis(&orientation, axis_to_track_by, thrust * delta_t);
|
||||
|
||||
quaternion_normalize(&orientation);
|
||||
quaternion_into_gl_matrix(orientation, rotMatrix);
|
||||
[self orientationChanged];
|
||||
|
||||
status = STATUS_ACTIVE;
|
||||
|
||||
@ -4526,21 +4529,20 @@ BOOL class_masslocks(int some_class)
|
||||
GLfloat range2 = magnitude2(vector_to_target);
|
||||
GLfloat targetRadius = 0.75 * target->collision_radius;
|
||||
GLfloat max_cos = sqrt(1 - targetRadius*targetRadius/range2);
|
||||
//
|
||||
|
||||
if (dp > max_cos)
|
||||
return; // ON TARGET!
|
||||
//
|
||||
|
||||
if (vector_to_target.x||vector_to_target.y||vector_to_target.z)
|
||||
vector_to_target = unit_vector(&vector_to_target);
|
||||
else
|
||||
vector_to_target.z = 1.0;
|
||||
//
|
||||
|
||||
q_minarc = quaternion_rotation_between(v_forward, vector_to_target);
|
||||
//
|
||||
|
||||
orientation = quaternion_multiply(q_minarc, orientation);
|
||||
quaternion_normalize(&orientation);
|
||||
quaternion_into_gl_matrix(orientation, rotMatrix);
|
||||
//
|
||||
[self orientationChanged];
|
||||
|
||||
flightRoll = 0.0;
|
||||
flightPitch = 0.0;
|
||||
}
|
||||
@ -4608,9 +4610,7 @@ BOOL class_masslocks(int some_class)
|
||||
}
|
||||
|
||||
quaternion_rotate_about_axis(&orientation, axis_to_track_by, thrust * delta_t);
|
||||
|
||||
quaternion_normalize(&orientation);
|
||||
quaternion_into_gl_matrix(orientation, rotMatrix);
|
||||
[self orientationChanged];
|
||||
|
||||
status = STATUS_ACTIVE;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user