/* ------------------------------------------------------------------------------------ */ int CCameraManager::GetPosition(geVec3d *thePosition) { // changed RF063 geXForm3d theViewPoint; // changed QD 12/15/05 //geXForm3d_SetIdentity(&theViewPoint); // Clear the matrix //geXForm3d_RotateZ(&theViewPoint, Rotation.Z); // Rotate then translate geXForm3d_SetZRotation(&theViewPoint, Rotation.Z); // end change geXForm3d_RotateX(&theViewPoint, Rotation.X); geXForm3d_RotateY(&theViewPoint, Rotation.Y); geXForm3d_Translate(&theViewPoint, Translation.X, Translation.Y, Translation.Z); if(jerk) { geVec3d Direction; geXForm3d_GetIn(&theViewPoint, &Direction); geVec3d_AddScaled(&theViewPoint.Translation, &Direction, -jerkamt, &theViewPoint.Translation); } //*thePosition = Translation; *thePosition = theViewPoint.Translation; // end change RF063 return RGF_SUCCESS; }
/* ------------------------------------------------------------------------------------ */ geXForm3d CCameraManager::ViewPoint() { geXForm3d theViewPoint; TrackMotion(); // changed QD 10715/05 //geXForm3d_SetIdentity(&theViewPoint); // Clear the matrix //geXForm3d_RotateZ(&theViewPoint, Rotation.Z); // Rotate then translate geXForm3d_SetZRotation(&theViewPoint, Rotation.Z); // end change geXForm3d_RotateX(&theViewPoint, Rotation.X); geXForm3d_RotateY(&theViewPoint, Rotation.Y); geXForm3d_Translate(&theViewPoint, Translation.X, Translation.Y, Translation.Z); return theViewPoint; }
void weapon_mini_rocket_proccess(float timePassed){ #define COLLISION geWorld_Collision(mini_rocketCurrentWorld,&(g->box.Min),&(g->box.Max),&(g->position),&newPos,GE_CONTENTS_SOLID_CLIP,GE_COLLIDE_ALL,0xffffffff, cb_move, 0, &lCol) int i; InfMiniRocket* g; geVec3d newPos; geVec3d to; geVec3d angles; GE_Collision lCol; for( i=0; i<NUMBER_OF_MINIROCKETS; i++){ g = & miniRockets[i]; if( g->active ){ geVec3d_AddScaled(&(g->position), &(g->velocity), timePassed, &(newPos) ); if( COLLISION ) { g->position = lCol.Impact; //geVec3d_Scale(&(g->velocity), -0.8f, &(g->velocity) ); weapon_mini_rocket_destroy(g); } else { g->position = newPos; } geVec3d_Add(&(g->position), &(g->velocity), &to); LookAt(g->position, to, &angles); angles.X += GE_PI/2; // update xform variable geXForm3d_SetIdentity(&(g->xform)); geXForm3d_RotateX(&(g->xform), angles.X); geXForm3d_RotateY(&(g->xform), angles.Y); geXForm3d_RotateZ(&(g->xform), angles.Z); g->xform.Translation = g->position; geActor_ClearPose(g->mini_rocket, &(g->xform) ); } } #undef COLLISION }
/* ------------------------------------------------------------------------------------ */ int CCameraManager::RenderView() { geXForm3d theViewPoint; // changed QD 12/15/05 //geXForm3d_SetIdentity(&theViewPoint); // Clear the matrix //geXForm3d_RotateZ(&theViewPoint, Rotation.Z); // Rotate then translate geXForm3d_SetZRotation(&theViewPoint, Rotation.Z); // end change geXForm3d_RotateX(&theViewPoint, Rotation.X); geXForm3d_RotateY(&theViewPoint, Rotation.Y); geXForm3d_Translate(&theViewPoint, Translation.X+shakex, Translation.Y+shakey, Translation.Z); // changed RF063 GE_Contents ZoneContents; geExtBox ExtBox; geVec3d Direction, Pos; GE_LVertex Vertex; ExtBox.Min.X = ExtBox.Min.Z = -1.0f; ExtBox.Min.Y = 0.0f; ExtBox.Max.Y = 1.0f; ExtBox.Max.X = ExtBox.Max.Z = 1.0f; if(CCD->Collision()->GetContentsOf(Translation, &ExtBox, &ZoneContents) == RGF_SUCCESS) //if(geWorld_GetContents(CCD->World(), &Translation, &ExtBox.Min, //&ExtBox.Max, GE_COLLIDE_MODELS, 0, NULL, NULL, &ZoneContents) == GE_TRUE) { Liquid * LQ = CCD->Liquids()->IsLiquid(ZoneContents.Model); if(LQ) { geXForm3d_GetIn(&theViewPoint, &Direction); geVec3d_AddScaled(&Translation, &Direction, OverlayDist, &Pos); Vertex.r = LQ->TintColor.r; Vertex.g = LQ->TintColor.g; Vertex.b = LQ->TintColor.b; Vertex.a = LQ->Transparency; Vertex.u = 0.0f; Vertex.v = 0.0f; Vertex.X = Pos.X; Vertex.Y = Pos.Y; Vertex.Z = Pos.Z; geWorld_AddPolyOnce(CCD->World(), &Vertex, 1, LQ->Texture, GE_TEXTURED_POINT , GE_RENDER_DO_NOT_OCCLUDE_SELF, 2.0f ); } // changed RF064 else { Overlay * OL = CCD->Overlays()->IsOverlay(ZoneContents.Model); if(OL) { geXForm3d_GetIn(&theViewPoint, &Direction); geVec3d_AddScaled(&Translation, &Direction, OverlayDist, &Pos); Vertex.r = OL->TintColor.r; Vertex.g = OL->TintColor.g; Vertex.b = OL->TintColor.b; Vertex.a = OL->Transparency; Vertex.u = 0.0f; Vertex.v = 0.0f; Vertex.X = Pos.X; Vertex.Y = Pos.Y; Vertex.Z = Pos.Z; geWorld_AddPolyOnce(CCD->World(), &Vertex, 1, OL->Texture, GE_TEXTURED_POINT , GE_RENDER_DO_NOT_OCCLUDE_SELF, 2.0f); } } // end change RF064 } if(jerk) { geVec3d Direction; geXForm3d_GetIn(&theViewPoint, &Direction); geVec3d_AddScaled(&theViewPoint.Translation, &Direction, -jerkamt, &theViewPoint.Translation); } // end change RF063 // Set up camera attributes just prior to rendering the world. geRect Rect; geCamera_SetWorldSpaceXForm(EngineCamera, &theViewPoint); geCamera_GetClippingRect(EngineCamera, &Rect); geCamera_SetAttributes(EngineCamera, FOV, &Rect); // changed RF064 geVec3d_Subtract(&m_OldXForm.Translation, &theViewPoint.Translation, &m_vMoveDif ); m_bPositionMoved = !geVec3d_IsZero(&m_vMoveDif); if( m_bPositionMoved || m_OldXForm.AX != theViewPoint.AX || m_OldXForm.AY != theViewPoint.AY || m_OldXForm.AZ != theViewPoint.AZ || m_OldXForm.BX != theViewPoint.BX || m_OldXForm.BY != theViewPoint.BY || m_OldXForm.BZ != theViewPoint.BZ || m_OldXForm.CX != theViewPoint.CX || m_OldXForm.CY != theViewPoint.CY || m_OldXForm.CZ != theViewPoint.CZ) { m_bViewChanged = true; m_OldXForm = theViewPoint; } // end change RF064 return RGF_SUCCESS; }
/* ------------------------------------------------------------------------------------ */ void CCameraManager::DoIsoTracking() { geXForm3d theViewPoint; geVec3d Pos; GE_Collision Collision; geVec3d Front, Back; geVec3d Direction; geFloat CurrentDistance; geExtBox ActorExtBox; geFloat ActorScale; geVec3d Orient; geFloat x; CCD->ActorManager()->GetScale(theActor, &ActorScale); // Get actor scale CCD->ActorManager()->GetBoundingBox(theActor, &ActorExtBox); CurrentDistance = m_defaultdistance * ActorScale; geVec3d ActorPosition, ActorRotation; CCD->ActorManager()->GetPosition(theActor, &ActorPosition); ActorPosition.Y += CameraOffsetTranslation.Y; CCD->ActorManager()->GetRotation(theActor, &ActorRotation); ActorRotation.X = 0.0f; // changed QD 12/15/05 //geXForm3d_SetIdentity(&theViewPoint); //geXForm3d_RotateZ(&theViewPoint, CameraOffsetRotation.Z); geXForm3d_SetZRotation(&theViewPoint, CameraOffsetRotation.Z); // end change geXForm3d_RotateX(&theViewPoint, CameraOffsetRotation.X+GE_PIOVER180*(m_cameraX)); geXForm3d_RotateY(&theViewPoint, CameraOffsetRotation.Y+GE_PIOVER180*(m_cameraY)); geXForm3d_Translate(&theViewPoint, ActorPosition.X, ActorPosition.Y, ActorPosition.Z); Pos = theViewPoint.Translation; geXForm3d_GetIn(&theViewPoint, &Direction); geVec3d_AddScaled(&Pos, &Direction, CurrentDistance, &Back); // changed QD 12/15/05 // geVec3d_AddScaled(&Pos, &Direction, 0.0f, &Front); geVec3d_Copy(&Pos, &Front); // end change if(IsoCollFlag) { if(geWorld_Collision(CCD->World(), &CameraExtBox.Min, &CameraExtBox.Max, &Front, &Back, /*GE_VISIBLE_CONTENTS*/GE_CONTENTS_SOLID_CLIP, GE_COLLIDE_ALL, 0, NULL, NULL, &Collision)) { // changed QD 01/2004 // can't be negative (sqrt) // CurrentDistance = (geFloat)fabs(geVec3d_DistanceBetween(&Collision.Impact, &Front)); // if(CurrentDistance < 0.0f) // CurrentDistance = 0.0f; CurrentDistance = geVec3d_DistanceBetween(&Collision.Impact, &Front); // end change if(CurrentDistance > (m_defaultdistance*ActorScale)) CurrentDistance = m_defaultdistance*ActorScale; geVec3d_AddScaled(&Pos, &Direction, CurrentDistance, &Back); } // changed QD 01/2004 if(CCD->Meshes()->CollisionCheck(&CameraExtBox.Min, &CameraExtBox.Max, Front, Back, &Collision)) { geFloat CurrentDistance2 = geVec3d_DistanceBetween(&Collision.Impact, &Front); if(CurrentDistance2 > (m_defaultdistance*ActorScale)) CurrentDistance2 = m_defaultdistance*ActorScale; if(CurrentDistance2<CurrentDistance) { CurrentDistance = CurrentDistance2; geVec3d_AddScaled(&Pos, &Direction, CurrentDistance2, &Back); } } // end change } m_currentdistance = CurrentDistance/ActorScale; if(IsoCollFlag) { geFloat fAlpha = 255.0f; if(CurrentDistance < (40.0f*ActorScale)) { fAlpha = (10.0f*((CurrentDistance-((geFloat)fabs(ActorExtBox.Min.Z)+1.0f))/ActorScale))+30.0f; if(fAlpha < (15.0f*ActorScale)) fAlpha = 0.0f; if(fAlpha > 255.0f) fAlpha = 255.0f; } CCD->ActorManager()->SetAlpha(theActor, fAlpha); // Adjust actor alpha } geVec3d_Subtract( &Pos, &Back, &Orient ); // protect from Div by Zero if(CurrentDistance > 0.0f) { x = Orient.X; // changed QD 12/15/05 // Orient.X = GE_PI*0.5f - (geFloat)acos(Orient.Y / CurrentDistance); Orient.X = GE_PIOVER2 - (geFloat)acos(Orient.Y / CurrentDistance); Orient.Y = (geFloat)atan2(x, Orient.Z) + GE_PI; Orient.Z = 0.0f; // roll is zero - always!!? } Rotation = Orient; // Set camera orientation Translation = Back; // Set camera translation return; }
/* ------------------------------------------------------------------------------------ */ void CCameraManager::DoThirdPersonTracking() { geXForm3d theViewPoint; geVec3d Pos; GE_Collision Collision; geVec3d Front, Back; geVec3d Direction; geFloat CurrentDistance; geExtBox ActorExtBox; geFloat ActorScale; geVec3d Orient; geFloat x; // changed QD 01/2004 geFloat PlayerScale = CCD->Player()->GetScale(); // end change CCD->ActorManager()->GetScale(theActor, &ActorScale); // Get actor scale CCD->ActorManager()->GetBoundingBox(theActor, &ActorExtBox); CurrentDistance = m_defaultdistance * ActorScale; geVec3d ActorPosition, ActorRotation; CCD->ActorManager()->GetPosition(theActor, &ActorPosition); ActorPosition.Y += CameraOffsetTranslation.Y; CCD->ActorManager()->GetRotation(theActor, &ActorRotation); // Start Nov2003DCS geVec3d_Add(&ActorRotation, &CameraOffsetRotation, &ActorRotation); // End Nov2003DCS ActorRotation.X = 0.0f; // changed QD 12/15/05 //geXForm3d_SetIdentity(&theViewPoint); //geXForm3d_RotateZ(&theViewPoint, ActorRotation.Z+CameraOffsetRotation.Z); geXForm3d_SetZRotation(&theViewPoint, ActorRotation.Z+CameraOffsetRotation.Z); // end change geXForm3d_RotateX(&theViewPoint, ActorRotation.X+CameraOffsetRotation.X+GE_PIOVER180*(m_cameraX)); geXForm3d_RotateY(&theViewPoint, ActorRotation.Y+CameraOffsetRotation.Y+GE_PIOVER180*(m_cameraY)); geXForm3d_Translate(&theViewPoint, ActorPosition.X, ActorPosition.Y, ActorPosition.Z); Pos = theViewPoint.Translation; geXForm3d_GetIn(&theViewPoint, &Direction); geVec3d_AddScaled(&Pos, &Direction, CurrentDistance, &Back); // changed QD 12/15/05 // geVec3d_AddScaled(&Pos, &Direction, 0.0f, &Front); geVec3d_Copy(&Pos, &Front); // end change if(geWorld_Collision(CCD->World(), &CameraExtBox.Min, &CameraExtBox.Max, &Front, &Back, /*GE_VISIBLE_CONTENTS*/GE_CONTENTS_SOLID_CLIP, GE_COLLIDE_ALL, 0, NULL, NULL, &Collision)) { // changed QD 01/2004 // can't be negative (sqrt!) // CurrentDistance = (geFloat)fabs(geVec3d_DistanceBetween(&Collision.Impact, &Front)); // if(CurrentDistance < 0.0f) // CurrentDistance = 0.0f; CurrentDistance = geVec3d_DistanceBetween(&Collision.Impact, &Front); // end change if(CurrentDistance > (m_defaultdistance*ActorScale)) CurrentDistance = m_defaultdistance*ActorScale; geVec3d_AddScaled(&Pos, &Direction, CurrentDistance, &Back); } // changed QD 01/2004 geVec3d_AddScaled(&Pos, &Direction, playermindistance*ActorScale, &Front); if(CCD->Meshes()->CollisionCheck(&CameraExtBox.Min, &CameraExtBox.Max, Front, Back, &Collision)) { // changed QD distance can't be negative // geFloat CurrentDistance2 = (geFloat)fabs(geVec3d_DistanceBetween(&Collision.Impact, &Front));//-4.0f; geFloat CurrentDistance2 = geVec3d_DistanceBetween(&Collision.Impact, &Front); CurrentDistance2 += playermindistance*ActorScale; if(theActor == CCD->Player()->GetActor()) { if(CurrentDistance2 < (playermindistance*ActorScale)) CurrentDistance2 = playermindistance*ActorScale; if(CurrentDistance2 > (playermaxdistance*ActorScale)) CurrentDistance2 = playermaxdistance*ActorScale; } else { if(CurrentDistance2 > (m_defaultdistance*ActorScale)) CurrentDistance2 = m_defaultdistance*ActorScale; } if(CurrentDistance2 < CurrentDistance) { CurrentDistance = CurrentDistance2; geVec3d_AddScaled(&Pos, &Direction, CurrentDistance2, &Back); } } // end change m_currentdistance = CurrentDistance/ActorScale; // Ok, here's the implementation of Ralph Deane's too-cool // ..third-person Actor Fading code. As the camera approaches // ..the player avatar, the AVATAR IS FADED OUT until finally // ..it's rendering is shut down. This is one Way Cool Effect. // 03/22/2000 eaa3 Added Ralph Deane's scaling fixes. geFloat fAlpha = 255.0f; if(CurrentDistance < (40.0f*ActorScale)) { fAlpha = (10.0f*((CurrentDistance-((geFloat)fabs(ActorExtBox.Min.Z)+1.0f))/ActorScale))+30.0f; if(fAlpha < (15.0f*ActorScale)) fAlpha = 0.0f; if(fAlpha > 255.0f) fAlpha = 255.0f; } CCD->ActorManager()->SetAlpha(theActor, fAlpha); // Adjust actor alpha geVec3d_Subtract( &Pos, &Back, &Orient ); // protect from Div by Zero if(CurrentDistance > 0.0f) { x = Orient.X; // changed QD 12/15/05 // Orient.X = (geFloat)( GE_PI*0.5 ) - (geFloat)acos(Orient.Y / CurrentDistance); Orient.X = GE_PIOVER2 - (geFloat)acos(Orient.Y / CurrentDistance); Orient.Y = (geFloat)atan2(x, Orient.Z) + GE_PI; Orient.Z = 0.0f; // roll is zero - always!!? } Rotation = Orient; // Set camera orientation Translation = Back; // Set camera translation return; }
/* ------------------------------------------------------------------------------------ */ geBoolean CDSpotLight::Tick(geFloat dwTicks) { geEntity_EntitySet *pSet; geEntity *pEntity; if(CCD->World() == NULL) return GE_TRUE; pSet = geWorld_GetEntitySet(CCD->World(), "DSpotLight"); if(!pSet) return GE_TRUE; for(pEntity=geEntity_EntitySetGetNextEntity(pSet, NULL); pEntity; pEntity=geEntity_EntitySetGetNextEntity(pSet, pEntity)) { DSpotLight *Light; geFloat Radius; geFloat Percentage; int Index; geVec3d Pos; int32 Leaf; Light = (DSpotLight*)geEntity_GetUserData(pEntity); if(!EffectC_IsStringNull(Light->TriggerName)) { if(GetTriggerState(Light->TriggerName)) { if(Light->active == GE_FALSE) { Light->DynLight = geWorld_AddLight(CCD->World()); Light->active = GE_TRUE; } } else { if(Light->active == GE_TRUE) geWorld_RemoveLight(CCD->World(), Light->DynLight); Light->active = GE_FALSE; } } else { if(Light->active == GE_FALSE) { Light->DynLight = geWorld_AddLight(CCD->World()); Light->active = GE_TRUE; // CCD->ReportError("DSpotLight light added", false); } } if(Light->active == GE_TRUE) { // pass the OriginOffset to SetOrigin // so that the light will stay in the same position relative to the model. Light->origin = Light->OriginOffset; SetOriginOffset(Light->EntityName, Light->BoneName, Light->Model, &(Light->origin)); geWorld_GetLeaf(CCD->World(), &(Light->origin), &Leaf); Pos = Light->origin; if(Light->Rotate) { if(Light->Model) { geXForm3d Xf; geVec3d Tmp; geWorld_GetModelXForm(CCD->World(), Light->Model, &Xf); geXForm3d_GetEulerAngles(&Xf, &Tmp); geVec3d_Add(&(Light->RealAngle), &Tmp, &(Light->angles)); geVec3d_Scale(&(Light->angles), GE_180OVERPI, &(Light->angles)); } else if(!EffectC_IsStringNull(Light->EntityName)) { // changed QD 07/15/06 /* geXForm3d BoneXForm; geActor *theActor; theActor = GetEntityActor(Light->EntityName); if(!EffectC_IsStringNull(Light->BoneName)) { if(geActor_GetBoneTransform(theActor, Light->BoneName, &BoneXForm) != GE_TRUE) continue; // No such bone } else { if(geActor_GetBoneTransform(theActor, RootBoneName(theActor), &BoneXForm) != GE_TRUE) continue; // No such bone } geXForm3d_RotateY(&BoneXForm, Light->RealAngle.Y); geXForm3d_GetEulerAngles(&BoneXForm, &(Light->angles)); Light->angles.Z += Light->RealAngle.Z; */ SetAngle(Light->EntityName, Light->BoneName, &(Light->angles)); if(Light->RealAngle.X || Light->RealAngle.Y || Light->RealAngle.Z) { geXForm3d XForm, BoneXForm; geXForm3d_SetZRotation(&XForm, Light->RealAngle.Z); geXForm3d_RotateX(&XForm, Light->RealAngle.X); geXForm3d_RotateY(&XForm, Light->RealAngle.Y); geXForm3d_SetZRotation(&BoneXForm, Light->angles.Z); geXForm3d_RotateX(&BoneXForm, Light->angles.X); geXForm3d_RotateY(&BoneXForm, Light->angles.Y); geXForm3d_Multiply(&BoneXForm, &XForm, &XForm); geXForm3d_GetEulerAngles(&XForm, &(Light->angles)); } // end change QD 07/15/06 // convert to degrees geVec3d_Scale(&(Light->angles), GE_180OVERPI, &(Light->angles)); } } Percentage = Light->LastTime / Light->RadiusSpeed; Index = (int)(Percentage * Light->NumFunctionValues); if(Light->InterpolateValues && Index < Light->NumFunctionValues - 1) { geFloat Remainder; geFloat InterpolationPercentage; int DeltaValue; geFloat Value; Remainder = (geFloat)fmod(Light->LastTime, Light->IntervalWidth); InterpolationPercentage = Remainder / Light->IntervalWidth; DeltaValue = Light->RadiusFunction[Index + 1] - Light->RadiusFunction[Index]; Value = Light->RadiusFunction[Index] + DeltaValue * InterpolationPercentage; Percentage = ((geFloat)(Value - 'a')) / ((geFloat)('z' - 'a')); } else Percentage = ((geFloat)(Light->RadiusFunction[Index] - 'a')) / ((geFloat)('z' - 'a')); Radius = Percentage * (Light->MaxRadius - Light->MinRadius) + Light->MinRadius; // angles in degrees geWorld_SetSpotLightAttributes(CCD->World(), Light->DynLight, &Pos, &(Light->Color), Radius, Light->arc, &(Light->angles), Light->style, Light->CastShadows); Light->LastTime = (geFloat)fmod(Light->LastTime + dwTicks, Light->RadiusSpeed); if(EffectC_IsPointVisible(CCD->World(), CCD->CameraManager()->Camera(), &Pos, Leaf, EFFECTC_CLIP_LEAF ) == GE_FALSE) { geWorld_RemoveLight(CCD->World(), Light->DynLight); Light->active = GE_FALSE; } } } return GE_TRUE; }