diff --git a/src/Core/Entities/Entity.m b/src/Core/Entities/Entity.m index b522b1f7..5b80cf5f 100644 --- a/src/Core/Entities/Entity.m +++ b/src/Core/Entities/Entity.m @@ -635,7 +635,7 @@ static NSString * const kOOLogEntityUpdateError = @"entity.linkedList.update. - (void) updateCameraRelativePosition { - cameraRelativePosition = HPVectorToVector(HPvector_subtract(position,[PLAYER viewpointPosition])); + cameraRelativePosition = HPVectorToVector(HPvector_subtract([self absolutePositionForSubentity],[PLAYER viewpointPosition])); } @@ -901,7 +901,7 @@ static NSString * const kOOLogEntityUpdateError = @"entity.linkedList.update. { zero_distance = [[self owner] zeroDistance]; cam_zero_distance = [[self owner] camZeroDistance]; - cameraRelativePosition = [[self owner] cameraRelativePosition]; + [self updateCameraRelativePosition]; } else { diff --git a/src/Core/Entities/OOEntityWithDrawable.m b/src/Core/Entities/OOEntityWithDrawable.m index b077f914..120cadeb 100644 --- a/src/Core/Entities/OOEntityWithDrawable.m +++ b/src/Core/Entities/OOEntityWithDrawable.m @@ -97,19 +97,19 @@ MA 02110-1301, USA. // http://aegidian.org/bb/viewtopic.php?f=3&t=13619 - CIM if (cam_zero_distance > (clipradius+1000)*(clipradius+1000)) { - if (![UNIVERSE viewFrustumIntersectsSphereAt:position withRadius:clipradius]) + if (![UNIVERSE viewFrustumIntersectsSphereAt:cameraRelativePosition withRadius:clipradius]) { return; } } } - else + else // is subentity { // don't bother with frustum culling within 1km, as above - CIM if (cam_zero_distance > (collision_radius+1000)*(collision_radius+1000)) { // check correct sub-entity position - if (![UNIVERSE viewFrustumIntersectsSphereAt:[self absolutePositionForSubentity] withRadius:[self collisionRadius]]) + if (![UNIVERSE viewFrustumIntersectsSphereAt:cameraRelativePosition withRadius:[self collisionRadius]]) { return; } diff --git a/src/Core/Entities/OOLightParticleEntity.m b/src/Core/Entities/OOLightParticleEntity.m index 91efbfd5..023f9b87 100644 --- a/src/Core/Entities/OOLightParticleEntity.m +++ b/src/Core/Entities/OOLightParticleEntity.m @@ -109,29 +109,26 @@ static OOTexture *sBlobTexture = nil; OO_ENTER_OPENGL(); - /*Entity *father = [self owner]; + Entity *father = [self owner]; Entity *last = nil; - Vector abspos = position; + HPVector abspos = position; while (father != nil && father != last && father != NO_TARGET) { OOMatrix rM = [father drawRotationMatrix]; - abspos = vector_add(OOVectorMultiplyMatrix(abspos, rM), [father position]); + abspos = HPvector_add(OOHPVectorMultiplyMatrix(abspos, rM), [father position]); last = father; if (![father isSubEntity]) break; father = [father owner]; - }*/ - HPVector abspos = [self absolutePositionForSubentity]; - + } + OOMatrix temp_matrix = OOMatrixLoadGLMatrix(GL_MODELVIEW_MATRIX); OOGL(glPopMatrix()); OOGL(glPushMatrix()); // restore zero! - // HPVect: camera-relative - HPVector relpos = HPvector_subtract(abspos,[PLAYER viewpointPosition]); - GLTranslateOOVector(HPVectorToVector(relpos)); // move to camera-relative position - + + GLTranslateOOVector(HPVectorToVector(HPvector_subtract(abspos,[PLAYER viewpointPosition]))); // move to camera-relative position [self drawImmediate:immediate translucent:translucent]; - + GLLoadOOMatrix(temp_matrix); } diff --git a/src/Core/Entities/OOPlanetEntity.m b/src/Core/Entities/OOPlanetEntity.m index e9c0fcdf..d546a1fb 100644 --- a/src/Core/Entities/OOPlanetEntity.m +++ b/src/Core/Entities/OOPlanetEntity.m @@ -478,7 +478,7 @@ static OOColor *ColorWithHSBColor(Vector c) if (translucent || [UNIVERSE breakPatternHide]) return; // DON'T DRAW if (_miniature && ![self isFinishedLoading]) return; // For responsiveness, don't block to draw as miniature. - if (![UNIVERSE viewFrustumIntersectsSphereAt:position withRadius:([self radius] + ATMOSPHERE_DEPTH)]) + if (![UNIVERSE viewFrustumIntersectsSphereAt:cameraRelativePosition withRadius:([self radius] + ATMOSPHERE_DEPTH)]) { // Don't draw return; diff --git a/src/Core/Entities/PlanetEntity.m b/src/Core/Entities/PlanetEntity.m index 7fd6aae2..c21051c4 100644 --- a/src/Core/Entities/PlanetEntity.m +++ b/src/Core/Entities/PlanetEntity.m @@ -759,7 +759,7 @@ static const BaseFace kTexturedFaces[][3] = // for some reason this check doesn't work when extremely close to // the planet and with the horizon near the side of the frame (FP // inaccuracy?) - if (![UNIVERSE viewFrustumIntersectsSphereAt:position withRadius:radWithAtmosphere]) + if (![UNIVERSE viewFrustumIntersectsSphereAt:cameraRelativePosition withRadius:radWithAtmosphere]) { // Don't draw return; @@ -969,7 +969,7 @@ static const BaseFace kTexturedFaces[][3] = { OOGL(glPopMatrix()); // get old draw matrix back OOGL(glPushMatrix()); // and store it again - OOGL(glTranslatef(position.x,position.y,position.z)); // centre on the planet + OOGL(glTranslatef(cameraRelativePosition.x,cameraRelativePosition.y,cameraRelativePosition.z)); // centre on the planet // rotate // GLMultOOMatrix([atmosphere rotationMatrix]); // draw atmosphere entity diff --git a/src/Core/Entities/ShipEntity.m b/src/Core/Entities/ShipEntity.m index e102e5ca..d52312a5 100644 --- a/src/Core/Entities/ShipEntity.m +++ b/src/Core/Entities/ShipEntity.m @@ -770,7 +770,7 @@ static ShipEntity *doOctreesCollide(ShipEntity *prime, ShipEntity *other); - (BOOL) setUpOneFlasher:(NSDictionary *) subentDict { OOFlasherEntity *flasher = [OOFlasherEntity flasherWithDictionary:subentDict]; - [flasher setPosition:vectorToHPVector([subentDict oo_vectorForKey:@"position"])]; + [flasher setPosition:[subentDict oo_hpvectorForKey:@"position"]]; [self addSubEntity:flasher]; return YES; } diff --git a/src/Core/Universe.h b/src/Core/Universe.h index e0ebbf10..be537e72 100644 --- a/src/Core/Universe.h +++ b/src/Core/Universe.h @@ -454,7 +454,7 @@ enum - (void) drawUniverse; - (void) defineFrustum; -- (BOOL) viewFrustumIntersectsSphereAt:(HPVector)position withRadius:(GLfloat)radius; +- (BOOL) viewFrustumIntersectsSphereAt:(Vector)position withRadius:(GLfloat)radius; - (void) drawMessage; diff --git a/src/Core/Universe.m b/src/Core/Universe.m index 531c27ff..4d851a36 100644 --- a/src/Core/Universe.m +++ b/src/Core/Universe.m @@ -3815,9 +3815,8 @@ static const OOMatrix starboard_matrix = } -- (BOOL) viewFrustumIntersectsSphereAt:(HPVector)position withRadius:(GLfloat)radius +- (BOOL) viewFrustumIntersectsSphereAt:(Vector)position withRadius:(GLfloat)radius { - return YES; // HPVect: temporarily, while rest of camera-relative is sorted out int p; for (p = 0; p < 6; p++) {