void RotatingDoor::Opening() { LTBOOL bDoneInX = LTFALSE; LTBOOL bDoneInY = LTFALSE; LTBOOL bDoneInZ = LTFALSE; LTVector vOldAngles(m_fPitch, m_fYaw, m_fRoll); // Calculate new pitch, yaw, and roll... bDoneInX = CalcAngle(m_fPitch, m_vClosedAngles.x, m_vOpenAngles.x, m_vOpenDir.x, m_fSpeed); bDoneInY = CalcAngle(m_fYaw, m_vClosedAngles.y, m_vOpenAngles.y, m_vOpenDir.y, m_fSpeed); bDoneInZ = CalcAngle(m_fRoll, m_vClosedAngles.z, m_vOpenAngles.z, m_vOpenDir.z, m_fSpeed); LTVector vPos; LTRotation rRot; // Calcuate the new pos/rot for the door (testing object collisions)... // If we collide with an object in the new position, don't move // the door (if force move isn't set)... if (!CalcPosAndRot(vPos, rRot, LTTRUE) && !(m_dwStateFlags & DF_FORCEMOVE)) { // Restore our angles... m_fPitch = vOldAngles.x; m_fYaw = vOldAngles.y; m_fRoll = vOldAngles.z; // Since we hit something, try to close... //SetClosing(); // Doesn't work... m_bStuck = LTTRUE; return; } // Set the object's new rotation and position... g_pLTServer->RotateObject(m_hObject, &rRot); g_pLTServer->MoveObject(m_hObject, &vPos); // Update the light animation. float fPercent = GetRotatingLightAnimPercent(); ReallySetLightAnimPos(fPercent); if (bDoneInX && bDoneInY && bDoneInZ) { SetOpen(); } }
short CCDInfo::GetTrackFromPoint(const POINT& pt) { POINT ptCenter; short nTracks, nTrack, nTotalLength; double dblAngle, dblNewAngle, dblCursorAngle; nTracks = m_cd.GetNumberOfTracks(); nTotalLength = m_cd.GetTotalLength(); if (!InEllipse(m_rcEllipse, pt) || nTracks==0) return 0; ptCenter.x = (m_rcEllipse.right + m_rcEllipse.left) / 2; ptCenter.y = (m_rcEllipse.bottom + m_rcEllipse.top) / 2; dblAngle = m_dblCurrentAngle; dblCursorAngle = CalcAngle(ptCenter, pt); // Ensure the angle will be in the range that we are checking for if (dblCursorAngle < dblAngle) dblCursorAngle += 2 * PI; for (nTrack=1; nTrack<=nTracks; nTrack++) { dblNewAngle = dblAngle + m_cd.GetTrackLength(nTrack) / (double)nTotalLength * 2 * PI; if (dblAngle < dblCursorAngle && dblCursorAngle < dblNewAngle) break; dblAngle = dblNewAngle; } return nTrack; }
unsigned int CMath::SetReturnFOV(FloatArray4x3 vecAngle, FloatArray4x3 vecSrc, FloatArray4x3 vecEnd) { FloatArray4x3 vecAng, vecAim; CalcAngle(vecSrc, vecEnd, vecAng); MakeFloatArray4x3(vecAngle, vecAim); MakeFloatArray4x3(vecAng, vecAng); return RAD2DEG(acos(vecAim.Dot(vecAng)) / vecAim.Length()); }
void ofxCell::draw(){ if(alive){ ofSetColor(color.r, color.g, color.b); ofFill(); ofCircle(ringRadius*cos(CalcAngle(ring, steps )*PI/180.)+ofGetWidth()/2,-ringRadius*sin(CalcAngle(ring, steps)*PI/180.)+ofGetHeight()/2,circle_radius-2); //ofDrawBitmapString(ofToString(ring), ringRadius*cos(angle*PI/180.)+ofGetWidth()/2, -ringRadius*sin(angle*PI/180.)+ofGetHeight()/2+20); //ofDrawBitmapString(ofToString(steps), ringRadius*cos(angle*PI/180.)+ofGetWidth()/2, -ringRadius*sin(angle*PI/180.)+ofGetHeight()/2+40); //ofDrawBitmapString(ofToString(CalcTotSteps(ring) ), ringRadius*cos(angle*PI/180.)+ofGetWidth()/2, -ringRadius*sin(angle*PI/180.)+ofGetHeight()/2+60); //ofDrawBitmapString(ofToString(condition ), ringRadius*cos(angle*PI/180.)+ofGetWidth()/2, -ringRadius*sin(angle*PI/180.)+ofGetHeight()/2+80); } }
// **************************************************************************** // // Function Name: RRotateSelectionTracker::Render( ) // // Description: Called to render the tracker feedback // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RRotateSelectionTracker::Render( RDrawingSurface& drawingSurface, const R2dTransform& transform, const RRealPoint& point ) const { // Calculate the angle YAngle angle = CalcAngle( point ); // Draw the feedback line drawingSurface.MoveTo( m_TrackingRotationCenter, transform ); drawingSurface.LineTo( point, transform ); // Render the tracking rectangle m_pSelection->DrawRotateTrackingFeedback( drawingSurface, transform, m_TrackingRotationCenter, angle ); }
BOOL ArrowRec::GetArrowMatrix(const DocCoord& ArrowCentre, const DocCoord& Direction, INT32 ParentLineWidth, Trans2DMatrix* pMatrix) { if (IsNullArrow()) return FALSE; TRACEUSER( "DavidM", wxT("ArrowRec::GetArrowMatrix %d\n"), m_bExtendPath ); ANGLE RotateAngle = CalcAngle(ArrowCentre, Direction); // Now we work how much we need to scale the path DocRect ArrowBounds = ArrowShape->GetBoundingRect(); double TempLineWidth = ParentLineWidth; if (TempLineWidth == 0) TempLineWidth = ZEROWIDTH_ARROW_LINEWIDTH; BOOL DoScale = ScaleWithLineWidth; FIXED16 xscale = DoScale ? ((ArrowWidth.MakeDouble() * TempLineWidth) / LineWidth) : (ArrowWidth); FIXED16 yscale = DoScale ? ((ArrowHeight.MakeDouble() * TempLineWidth) / LineWidth) : (ArrowWidth); // move the centre of the arrow DocRect ArrowRect = ArrowShape->GetBoundingRect(); DocCoord centre; if (!m_bExtendPath) { centre.x = ArrowRect.hi.x; centre.y = (ArrowRect.lo.y + ArrowRect.hi.y) / 2; } else { centre = Centre; } Matrix Mat = Matrix(-centre.x, -centre.y); // Move shape to origin Mat *= Matrix(xscale, yscale); // Scale it Mat *= Matrix(RotateAngle); // Rotate it Mat *= Matrix(ArrowCentre); // Move it to the line point Trans2DMatrix Trans(Mat); *pMatrix = Trans; return TRUE; }
tFloat32 LaneAngleCalculator::CalculateDrivingAngle(const Mat &map, const tFloat32 currentSpeed, const tFloat32 reactionDistance) { //Mat a = Mat(range, range, CV_8UC1); // Mat_<double>(3,3); // imread("c:/full/path/to/lena.jpg"); pair<int, int> origin = make_pair(map.rows / 2, map.cols / 2); pair<int, int> rightPoint; pair<int, int> leftPoint; rightPoint = searchForCorner(origin, dirRight, map); leftPoint = searchForCorner(origin, dirLeft, map); return CalcAngle(rightPoint.first, rightPoint.second); }
// **************************************************************************** // // Function Name: RRotateSelectionTracker::EndTracking( ) // // Description: Called when tracking ends; ie. when the mouse button goes // up. // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RRotateSelectionTracker::EndTracking( const RRealPoint& mousePoint, YModifierKey modifierKeys ) { // Constrain the mouse point RRealPoint constrainedPoint = mousePoint; ApplyConstraint( constrainedPoint ); // Call the base class RSelectionTracker::EndTracking( constrainedPoint, modifierKeys ); // Calculate the angle YAngle angle = CalcAngle( constrainedPoint ); // Create and do a rotate selection action RRotateSelectionAction* pAction = new RRotateSelectionAction( m_pSelection, m_TrackingRotationCenter, angle ); m_pView->GetRDocument( )->SendAction( pAction ); }
// Action_Angle::action() Action::RetType Action_Angle::DoAction(int frameNum, Frame* currentFrame, Frame** frameAddress) { Vec3 a1, a2, a3; if (useMass_) { a1 = currentFrame->VCenterOfMass( Mask1_ ); a2 = currentFrame->VCenterOfMass( Mask2_ ); a3 = currentFrame->VCenterOfMass( Mask3_ ); } else { a1 = currentFrame->VGeometricCenter( Mask1_ ); a2 = currentFrame->VGeometricCenter( Mask2_ ); a3 = currentFrame->VGeometricCenter( Mask3_ ); } double aval = CalcAngle( a1.Dptr(), a2.Dptr(), a3.Dptr() ); aval *= Constants::RADDEG; ang_->Add(frameNum, &aval); return Action::OK; }
// Action_Angle::action() Action::RetType Action_Angle::DoAction(int frameNum, ActionFrame& frm) { Vec3 a1, a2, a3; if (useMass_) { a1 = frm.Frm().VCenterOfMass( Mask1_ ); a2 = frm.Frm().VCenterOfMass( Mask2_ ); a3 = frm.Frm().VCenterOfMass( Mask3_ ); } else { a1 = frm.Frm().VGeometricCenter( Mask1_ ); a2 = frm.Frm().VGeometricCenter( Mask2_ ); a3 = frm.Frm().VGeometricCenter( Mask3_ ); } double aval = CalcAngle( a1.Dptr(), a2.Dptr(), a3.Dptr() ); aval *= Constants::RADDEG; ang_->Add(frameNum, &aval); return Action::OK; }
// **************************************************************************** // // Function Name: RRotateSelectionTracker::GetFeedbackBoundingRect( ) // // Description: Returns the feedback bounding rect // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // RRealRect RRotateSelectionTracker::GetFeedbackBoundingRect( const RRealPoint& point ) const { // Get the view transform R2dTransform transform; m_pView->GetViewTransform( transform, TRUE ); // Calculate the angle YAngle angle = CalcAngle( point ); // Get the bounding rect, in device units RRealRect boundingRect = m_pSelection->GetRotateTrackingFeedbackBoundingRect( transform, m_TrackingRotationCenter, angle ); // Convert back to logical units transform.Invert( ); boundingRect *= transform; // Add the feedback line boundingRect.AddPointToRect( point ); return boundingRect; }
LTBOOL RotatingDoor::GetMoveTestPosRot(LTVector & vTestPos, LTRotation & rTestRot) { LTVector vFinalPos(0.0f, 0.0f, 0.0f); LTFLOAT fSpeed = 0.0f; LTVector vOldAngles(m_fPitch, m_fYaw, m_fRoll); switch (m_dwDoorState) { case DOORSTATE_CLOSING: { // Calculate new pitch, yaw, and roll... CalcAngle(m_fPitch, m_fPitch, m_vOpenAngles.x, m_vOpenDir.x, m_fSpeed); CalcAngle(m_fYaw, m_fYaw, m_vOpenAngles.y, m_vOpenDir.y, m_fSpeed); CalcAngle(m_fRoll, m_fRoll, m_vOpenAngles.z, m_vOpenDir.z, m_fSpeed); } break; case DOORSTATE_OPENING: { // Calculate new pitch, yaw, and roll... CalcAngle(m_fPitch, m_fPitch, m_vClosedAngles.x, -m_vOpenDir.x, m_fClosingSpeed); CalcAngle(m_fYaw, m_fYaw, m_vClosedAngles.y, -m_vOpenDir.y, m_fClosingSpeed); CalcAngle(m_fRoll, m_fRoll, m_vClosedAngles.z, -m_vOpenDir.z, m_fClosingSpeed); } break; default: return LTFALSE; break; } // Rotate the object... CalcPosAndRot(vTestPos, rTestRot); // Restore real angles... m_fPitch = vOldAngles.x; m_fYaw = vOldAngles.y; m_fRoll = vOldAngles.z; return LTTRUE; }
void CPathObject::Draw(CDC* pDC){ COLORREF color; if(IsSelected) color=COLORREF(RGB(255,0,0)); else color=COLORREF(RGB(0,0,0)); CPen pen(PS_SOLID,2,color); CPen *pOldPen=NULL; pOldPen=pDC->SelectObject(&pen); double angle=CalcAngle(headnode->centre.x-endnode->centre.x, headnode->centre.y-endnode->centre.y); CPoint pt1,pt2; pt1=GetAnglePoint(headnode->centre.x,headnode->centre.y,radius,radius,(int)(angle+180)); pt2=GetAnglePoint(endnode->centre.x,endnode->centre.y,radius,radius,(int)(angle)); pDC->MoveTo(pt1); pDC->LineTo(pt2); CPoint point(endnode->centre.x/3+headnode->centre.x*2/3, endnode->centre.y/3+headnode->centre.y*2/3); CPoint point1(endnode->centre.x/8+headnode->centre.x*7/8, endnode->centre.y/8+headnode->centre.y*7/8-5); pt1=GetAnglePoint(point.x,point.y,arrow,arrow,(int)(angle+14)); pt2=GetAnglePoint(point.x,point.y,arrow,arrow,(int)(angle-14)); pDC->MoveTo(point); pDC->LineTo(pt1); pDC->MoveTo(point); pDC->LineTo(pt2); char buf[20]; sprintf(buf,"%d",weight); pDC->SetTextColor(RGB(0,0,255)); pDC->TextOut( point1.x, point1.y ,buf ); }
//컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴 //Procedure ProcessPistonEngine //Author Craig Beeston //Date Tue 11 Aug 98 // //Description Processes a piston engine // Calculates Thrust, Torque, Engine power and Engine speed // //Inputs // //Returns // //------------------------------------------------------------------------------ void Engine::ProcessPistonEngine (AirStrucPtr const ControlledAC) { AircraftAnimData* adptr = (AircraftAnimData *)ControlledAC->Anim; SWord iDamage = 255 - (255 - UWord(adptr->ENGINELEFT)) * (255 - UWord(adptr->FRONT)) / 255; if(pThrustPoint->Pos.x > 0) iDamage = adptr->ENGINERIGHT; FP MaxSpeed = 2 * Rpm100 * 0.001047197; //RPM 2 Rads/cs if(iDamage == 254) MaxSpeed = 0; FP fDamage = 1.0 - FP(iDamage) * (1.0 / 255.0); //DEADCODE CB 04/11/99 FP MinSpeed = Rpm0 * 0.001047197; //RPM 2 Rads/cs //DEADCODE CB 04/11/99 if (Speed < MinSpeed) Speed = MinSpeed; if (Speed > MaxSpeed) Speed = MaxSpeed; FP EngRPM = Speed * 954.9296586; FP PropSpeed = Speed * GearRatio; FP PropSwirl = SlipRot * 0.5; const FP BladeFract = 0.60; FCRD Vel; CPrd(Vel, pThrustPoint->Pos, pModel->RotVel); Vel.z -= pModel->AirVel.z; //Velocity of air ahead of prop FP PropAirVel = BladeFract * (PropSpeed - PropSwirl) * BladeRadius; FP InflowAng = CalcAngle (PropAirVel, PropVel); //Automatic prop control for AI aircraft if((!Save_Data.flightdifficulty [FD_PROPPITCH]) || (ControlledAC != Persons2::PlayerSeenAC)) { switch(PropType) { case PT_FIXED: break; case PT_2PITCH: if(EngRPM > 1.15 * Rpm100) PropSetting = 0; if(EngRPM < 0.7 * Rpm100) PropSetting = 1; break; case PT_VARIABLE: PropSetting = 1.0 - 1.15 * ControlledAC->vel_ / ControlledAC->classtype->maxvel; MODMAXMIN(PropSetting, 0.01, 1); break; case PT_CONSTSPEED: if(ThrottleSetting <= 75) PropSetting = 0; else PropSetting = (ThrottleSetting - 75.0) / 25.0; //DEADCODE CSB 31/01/00 PropSetting = FP(ThrottleSetting) * 0.01; //DEADCODE CSB 31/01/00 PropSetting = PropSetting * PropSetting * PropSetting; break; } } switch(PropType) { case PT_FIXED: { PropInc = PropMaxPitch; break; } case PT_2PITCH: { FP DesiredInc = PropMaxPitch; if(PropSetting > 0.5) DesiredInc = PropMinPitch; if(DesiredInc > PropInc) { PropInc += 0.002 * MODEL_ENGINE_DT; //AMM 24Nov99 if(PropInc > DesiredInc) PropInc = DesiredInc; } if(DesiredInc < PropInc) { PropInc -= 0.002 * MODEL_ENGINE_DT; //AMM 24Nov99 if(PropInc < DesiredInc) PropInc = DesiredInc; } break; } case PT_VARIABLE: { FP DesiredInc = PropMaxPitch; if(PropSetting > 0) { FP Ratio = 0.5 * (PropSetting + 1.0); DesiredInc = PropMinPitch * Ratio + PropMaxPitch * (1 - Ratio); } if(DesiredInc > PropInc) { PropInc += 0.002 * MODEL_ENGINE_DT; //AMM 24Nov99 if(PropInc > DesiredInc) PropInc = DesiredInc; } if(DesiredInc < PropInc) { PropInc -= 0.002 * MODEL_ENGINE_DT; //AMM 24Nov99 if(PropInc < DesiredInc) PropInc = DesiredInc; } break; } case PT_CONSTSPEED: { FP DesiredRpm = Rpm100 * (0.7 + 0.45 * PropSetting); FP PropPitchRate = (EngRPM - DesiredRpm) * 0.00001; PropInc += PropPitchRate * MODEL_ENGINE_DT; //AMM 24Nov99 break; } } MODMAXMIN(PropInc, PropMinPitch, PropMaxPitch); FP BladeSpeed = FSqrt(PropAirVel * PropAirVel + PropVel * PropVel); FP BladeQS = 0.5 * pModel->AmbDensity * BladeSpeed * BladeArea; //DeadCode AMM 29Jun99 J = PropVel / ((PropSpeed - PropSwirl) * 0.75 * BladeRadius); //Only Used for Text Screen FP BladeL = 4.53 * (PropInc - InflowAng); FP BladeD = 0.005 + (0.071 * BladeL * BladeL); MODMAXMIN(BladeL, -1.0, 1.5); BladeL *= BladeQS; BladeD *= BladeQS; Thrust = BladeL * PropAirVel - BladeD * PropVel; Torque = BladeD * PropAirVel + BladeL * PropVel; Torque *= BladeRadius * 0.5; //effective overall moment //Engine Power Output Power100 = pPower100->GetValue (EngRPM / Rpm100); Power0 = pPower0->GetValue (EngRPM / Rpm100); FP fPower = 0; FP dTorque = 0; ComplexEngineProcess(ControlledAC, fDamage, fPower, dTorque); const FP MinThrottle = 0.125; FP PowerFract = MinThrottle + ThrottleSetting * (1 - MinThrottle) * 0.01; PowerFract *= fPower; FP oldpower = Power; Power = Power0 + ((Power100 - Power0) * PowerFract); if((oldpower <= 0) && (Power > 0)) Trans_Obj.LaunchEngineStartup((mobileitem*)ControlledAC, *ControlledAC->currworld); if((oldpower > 0) && (Power <= 0) && (ControlledAC == Persons2::PlayerSeenAC)) _Miles.PlayOnce(FIL_SFX_ENGINE_COUGH,Save_Data.vol.engine); //RJS 27Sep00 Power *= pPowerAlt->GetValue(pModel->Pos.y * 0.01); Power *= p0; //#define ENGINE_DATA #ifdef ENGINE_DATA //DeadCode CSB 27/10/99 /* TEST CODE CSB 27/10/99 */if(pModel->bACM) /* TEST CODE CSB 27/10/99 */{ //DEADCODE CSB 11/01/00 /* TEST CODE CSB 29/09/99 */ PrintVar(40, 15, "Gravity %.3f ", FP(pModel->Inst.I_NormalAcc)); //DEADCODE CSB 11/01/00 /* TEST CODE CSB 29/09/99 */ PrintVar(40, 16, "IAS %.2f ", FP(pModel->Speed * FSqrt (pModel->AmbDensity / 0.0001225))); //DEADCODE CSB 11/01/00 /* TEST CODE CSB 29/09/99 */ PrintVar(40, 17, "Vel %.2f ", FP(ControlledAC->vel_ * 0.0001)); //DEADCODE CSB 11/01/00 /* TEST CODE CSB 29/09/99 */ PrintVar(40, 18, "DesRpm %.2f ", FP(pModel->ModelPropSetting)); /* TEST CODE CSB 29/09/99 */ PrintVar(20, 15, "Power %.0f ", FP(Power / 745.7)); /* TEST CODE CSB 29/09/99 */ PrintVar(20, 16, "RPM %.0f ", FP(EngRPM)); /* TEST CODE CSB 29/09/99 */ PrintVar(20, 17, "Prop Inc %.2f ", FP(Rads2Degs(PropInc))); /* TEST CODE CSB 29/09/99 */ PrintVar(20, 18, "Vel %.2f ", FP(-pModel->AirVel.z)); /* TEST CODE CSB 29/09/99 */ PrintVar(20, 19, "PropVel %.2f ", FP(PropVel)); /* TEST CODE CSB 29/09/99 */ PrintVar(20, 20, "SlipVel %.2f ", FP(SlipVel)); /* TEST CODE CSB 29/09/99 */ PrintVar(20, 21, "Alpha %.2f ", FP(Rads2Degs(PropInc - InflowAng))); /* TEST CODE CSB 29/09/99 */ PrintVar(20, 24, "ROC fpm %.0f ", FP(pModel->Vel.y * 3.2808 * 60.0)); /* TEST CODE CSB 29/09/99 */ PrintVar(20, 22, "Thrust %.1f ", FP(Thrust)); /* TEST CODE CSB 29/09/99 */ PrintVar(20, 23, "Eff %.3f ", FP(Thrust * -pModel->AirVel.z / Power)); /* TEST CODE CSB 27/10/99 */} #endif FP EngTorque = 0; if(Speed > 0) EngTorque = Power / Speed; EngTorque += dTorque; //Slipstream Conditions FP OldSlipRot = SlipRot; FP SlipInertia = BladeRadius * BladeRadius * BladeRadius * BladeRadius * 0.5 * FPIE * PropVel * pModel->AmbDensity; if(SlipInertia > 0) SlipRot = (Torque / SlipInertia + OldSlipRot) * 0.5; else SlipRot = 0; if(SlipRot > PropSpeed) SlipRot = PropSpeed; FP OldSlipVel = SlipVel; FP PropArea = FPIE * BladeRadius * BladeRadius; FP TempSlip = 2 * Thrust / (pModel->AmbDensity * PropArea) + Vel.z * Vel.z; if (TempSlip < 0) SlipVel = -Vel.z; else SlipVel = sqrt(TempSlip); SlipVel = (SlipVel + OldSlipVel) * 0.5; PropVel = 0.5 * (0.5 * (Vel.z + SlipVel) + PropVel); // calc engine speed FP EngRotAcc = (EngTorque - Torque * GearRatio) / MoI; //DeadCode CSB 27/10/99 if (!Save_Data.flightdifficulty [FD_THRUSTPOWERCONTROL]) //DeadCode CSB 27/10/99 EngRotAcc *= 2; //Fast Spooling //DEADCODE AMM 24/11/99 Speed += pModel->MODEL_DT * EngRotAcc; Speed += MODEL_ENGINE_DT * EngRotAcc; //AMM 24/11/99 if(Speed < 0) Speed = 0; //DEADCODE CB 04/11/99 if (Speed < MinSpeed) Speed = MinSpeed; if (Speed > MaxSpeed) Speed = MaxSpeed; Torque = -Torque * RotateDirection;//(EngTorque - Torque / GearRatio); //Reacted into Airframe if (Save_Data.flightdifficulty [FD_SLIPSTREAMEFFECTS]) { FCRD TempRot; CopyVec(pModel->RotVel, TempRot); TempRot.z += Speed * RotateDirection; moment.x = TempRot.x * PropInertia.x; moment.y = TempRot.y * PropInertia.y; moment.z = TempRot.z * PropInertia.z; CPrd(moment, moment, TempRot); moment.x *= -1; moment.y *= -1; moment.z *= -1; } else NullVec(moment); }
/* ================ sdScriptedEntityHelper_Aimer::SetTarget ================ */ void sdScriptedEntityHelper_Aimer::SetTarget( const idVec3& _target ) { const idMat3& bindAxes = _owner->GetRenderEntity()->axis; const idVec3& bindOrg = _owner->GetRenderEntity()->origin; idMat3 yawJointAxis; idVec3 yawJointOrg; if ( gunJoints[ AIMER_JOINT_SHOULDER ] != INVALID_JOINT ) { idMat3 currentAxes; idVec3 currentOrigin; _owner->GetAnimator()->GetJointTransform( gunJoints[ AIMER_JOINT_SHOULDER ], gameLocal.time, currentOrigin, currentAxes ); idMat3 transform; TransposeMultiply( baseAxes[ AIMER_JOINT_SHOULDER ], currentAxes, transform ); idMat3 shoulderAxis = bindAxes; idVec3 shoulderOrg = bindOrg + ( currentOrigin * shoulderAxis ); yawJointAxis = transform * shoulderAxis; yawJointOrg = shoulderOrg + ( yawJointAxis * ikPaths[ AIMER_IK_BASE ] ); } else { yawJointAxis = bindAxes; yawJointOrg = bindOrg + ( yawJointAxis * ikPaths[ AIMER_IK_BASE ] ); } { idVec3 target = _target; target -= yawJointOrg; target *= yawJointAxis.Transpose(); target.z = 0.f; yawInfo.ideal = RAD2DEG( atan2( target.y, target.x ) ); float angle; if ( CalcAngle( target.Length(), yawInfo.arcLength, yawInfo.offsetAngle, angle ) ) { yawInfo.ideal += angle - yawInfo.initialAngle; } } if ( yawInfo.clamp.flags.enabled ) { yawInfo.ideal = idMath::ClampFloat( yawInfo.clamp.extents[ 0 ], yawInfo.clamp.extents[ 1 ], yawInfo.ideal ); } idMat3 yawAxes; idAngles::YawToMat3( yawInfo.ideal, yawAxes ); idMat3 pitchJointAxis = yawAxes * yawJointAxis; idVec3 pitchJointOrg = yawJointOrg + ( pitchJointAxis * ikPaths[ AIMER_IK_YAW ] ); { idVec3 target = _target; target -= pitchJointOrg; target *= pitchJointAxis.Transpose(); target.y = 0.f; pitchInfo.ideal = RAD2DEG( atan2( target.z, target.x ) ); float angle; if ( CalcAngle( target.Length(), pitchInfo.arcLength, pitchInfo.offsetAngle, angle ) ) { pitchInfo.ideal += angle - pitchInfo.initialAngle; } pitchInfo.ideal = -pitchInfo.ideal; // pitch is inverted for some reason... } if ( pitchInfo.clamp.flags.enabled ) { pitchInfo.ideal = idMath::ClampFloat( pitchInfo.clamp.extents[ 0 ], pitchInfo.clamp.extents[ 1 ], pitchInfo.ideal ); } }
void CLeanMgr::UpdateCenter( ) { float fCenterFromAngle = m_fCenterFromAngle; LTVector vCamPos; g_pLTClient->GetObjectPos( g_pPlayerMgr->GetCamera(), &vCamPos ); // Develop the rotation values... m_vRotationPt.Init( vCamPos.x, vCamPos.y - g_vtLeanRadius.GetFloat(), vCamPos.z ); m_vRotationPtOffset.Init( 0.0f, g_vtLeanRadius.GetFloat(), 0.0f ); // Did we try to lean but went back to centering before we finished... if( m_bFailedToLean ) { m_bFailedToLean = false; // Recalculate the time... if( m_fMaxLeanAngle > 0.0f ) { float fMovePercent = float(m_kLeanDir) * (m_fLastLeanAngle / m_fMaxLeanAngle); m_fEndTime = g_vtLeanCenterTime.GetFloat() * fMovePercent; } m_fStartTime = 0.0f; fCenterFromAngle = m_fLastLeanAngle; } // Find the angle based on the percentage of lean we should be at... m_fStartTime += g_pLTClient->GetFrameTime(); float fT = (m_fStartTime / m_fEndTime); bool bDone = CalcAngle( m_fLeanAngle, fCenterFromAngle, 0.0f, eLeanDirection(-m_kLeanDir), m_fEndTime, fT ); // Save our current lean angle... m_fLastLeanAngle = m_fLeanAngle; LTRotation rRot; LTVector vPos; CalculateNewPosRot( vPos, rRot, m_fLeanAngle ); // [KLS 3/22/03] Only adjust the camera in first person... if (g_pPlayerMgr->IsFirstPerson()) { g_pLTClient->SetObjectPosAndRotation( g_pPlayerMgr->GetCamera(), &vPos, &rRot ); } if( bDone ) { // We are centered. m_kLeanDir = kLean_Center; m_bFailedToCenter = false; m_bDoneMoving = false; return; } m_bFailedToCenter = true; }
void CLeanMgr::UpdateLean( ) { if( !IsLeaning() ) return; // Don't start leaning untill we are done moving... if( !m_bDoneMoving && (g_pMoveMgr->GetMovementPercent() > MATH_EPSILON) ) { BeginLean( m_kLeanDir ); } else { m_bDoneMoving = true; } LTVector vCamPos; g_pLTClient->GetObjectPos( g_pPlayerMgr->GetCamera(), &vCamPos ); // Develop the rotation values... m_vRotationPt.Init( vCamPos.x, vCamPos.y - g_vtLeanRadius.GetFloat(), vCamPos.z ); m_vRotationPtOffset.Init( 0.0f, g_vtLeanRadius.GetFloat(), 0.0f ); float fLeanFromAngle = m_fLeanFromAngle; // Did we try to center but went back to leaning before we finished... if( m_bFailedToCenter ) { m_bFailedToCenter = false; // Recalculate the time... if( m_fMaxLeanAngle > 0.0f ) { float fMovePercent = 1.0f - (float(m_kLeanDir) * (m_fLastLeanAngle / m_fMaxLeanAngle)); m_fEndTime = g_vtLeanOutTime.GetFloat() * fMovePercent; } m_fStartTime = 0.0f; fLeanFromAngle = m_fLastLeanAngle; } // Find the angle based on the percentage of lean we should be at... m_fStartTime += g_pLTClient->GetFrameTime(); float fT = (m_fStartTime / m_fEndTime); bool bDone = CalcAngle( m_fLeanAngle, fLeanFromAngle, m_fMaxLeanAngle, m_kLeanDir, m_fEndTime, fT ); // Save our last lean angle... m_fLastLeanAngle = m_fLeanAngle; LTRotation rRot; LTVector vPos; CalculateNewPosRot( vPos, rRot, m_fLeanAngle ); // [KLS 3/22/03] Only adjust the camera in first person... if (g_pPlayerMgr->IsFirstPerson()) { g_pLTClient->SetObjectPosAndRotation( g_pPlayerMgr->GetCamera(), &vPos, &rRot ); } if( bDone ) { if( !m_bLeanedOut ) { // We are completely leaned out. m_bLeanedOut = true; // Send a message to the server to register a stimulus. CAutoMessage cMsg; cMsg.Writeuint8( MID_PLAYER_CLIENTMSG ); cMsg.Writeuint8( CP_PLAYER_LEAN ); cMsg.Writeuint8( m_kLeanDir == kLean_Left ? PL_LEFT : PL_RIGHT ); cMsg.WriteLTVector( vPos ); g_pLTClient->SendToServer( cMsg.Read(), MESSAGE_GUARANTEED ); } m_bFailedToLean = false; return; } m_bFailedToLean = true; }
//컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴 //Procedure DerivativeBase //Author Andrew McRae //Date Tue 17 Jun 1997 // //Description Used to calibrate model with linearized // stability derivatives // // This model is aerodynamically accurate // for small disturbances from level flight. // //Inputs // //Returns // //------------------------------------------------------------------------------ void Model::DerivativeBase () { /* Stability Derivatives Forces X,Y,Z Moments L,M,N Velocity u,v,w Angular Velocity p,q,r Roll, Pitch, Yaw inputs a,b,c Downward Acceleration wd (za) (r = density) (everything has 0.5) Forces Moments Forward Stbd Down Roll Pitch Yaw Xu rVS Yu ... Zu rVS Lu ... Mu rVSc Nu ... Xv ... Yv rVS Zv ... Lv rVSb Mv ... Nv rVSb Xw rVS Yw ... Zw rVS Lw ... Mw rVSc Nw ... Xp ... Yp rVSb Zp ... Lp rVSb2 Mp ... Np rVSb2 Xq rVSc Yq ... Zq rVSc Lq ... Mq rVSc2 Nq ... Xr ... Yr rVSb Zr ... Lr rVSb2 Mr ... Nr rVSb2 Xa ... Ya rV2S Za ... La rV2Sb Ma ... Na rV2Sb Xb rV2S Yb ... Zb rV2S Lb ... Mb rV2Sc Nb ... Xc ... Yc rV2S Zc ... Lc rV2Sb Mc ... Nc rV2Sb Xwd rSc Ywd ... Zwd rSc Lwd ... Mwd rSc2 Nwd ... */ typedef struct vel { FP u,v,w; } VEL; typedef struct rotvel { FP p,q,r; } ROTVEL; typedef struct ctrl { FP a,b,c; } CTRL; typedef struct acc { FP ud,vd,wd; } ACC; typedef struct veldervs { VEL X,Y,Z,L,M,N; } VELDERVS; typedef struct rotveldervs { ROTVEL X,Y,Z,L,M,N; } ROTVELDERVS; typedef struct ctrldervs { CTRL X,Y,Z,L,M,N; } CTRLDERVS; typedef struct accdervs { ACC X,Y,Z,L,M,N; } ACCDERVS; VELDERVS V; ROTVELDERVS RV; CTRLDERVS C; ACCDERVS A; //DeadCode AMM 24Nov99 MODEL_DT = 3; MODEL_LOOPS = 1; static Bool setup = TRUE; FP testalpha = -Degs2Rads ((FP)Elevator / 3000); if (testalpha > DEGS2RADS(10)) testalpha = DEGS2RADS(10); if (testalpha < DEGS2RADS(-10)) testalpha = DEGS2RADS(-10); if (setup) { // temp Pos.y = FT_3000; Vel.x = 0; Vel.y = 0; Vel.z = 150; Ori.x.x = 1; Ori.x.y = 0; Ori.x.z = 0; Ori.y.x = 0; Ori.y.y = 1; Ori.y.z = 0; Ori.z.x = 0; Ori.z.y = 0; Ori.z.z = 1; // RotOriXVec (Ori, testalpha); // RotOriXVec (Ori, DEGS2RADS(5)); RotOriYVec (Ori, DEGS2RADS(10)); RotVel.x = 0; RotVel.y = 0; RotVel.z = 0; RotVel.y = 0.00105; // 1 rpm RotVel.z = -0.00105; // temp end setup = FALSE; } // UpdateAirStruc (); Sky.Ambient (Pos.y, AmbDensity, AmbTemp, AmbPres); CalcAirVel (); GearTouched = FALSE; // Set Mass and Rot Inertia Mass = 0; NullVec (RotInertia); PMODEL pModel = ControlledAC->fly.pModel; PMASSPOINT pMass = MassList; while (pMass != NULL) { pMass->Process (pModel); pMass = pMass->List.NextItem (); } // ProcessEngines (); Mass = 617415; RotInertia.x = 1.49534e10; RotInertia.y = 3.59877e10; RotInertia.z = 4.98958e10; // WORK IN STANDARD UNITS // Calc Derivative Mutipliers FP B = (MainPlaneList->Area / MainPlaneList->Chord) * 0.01; FP Ch = MainPlaneList->Chord * 0.01; FP rS = 0.5 * (AmbDensity * 10000) * (MainPlaneList->Area * 0.0001); FP rVS = rS * AirSpeed; FP rVSb = rVS * B; FP rVSc = rVS * Ch; FP rVSb2 = rVSb * B; FP rVSc2 = rVSc * Ch; FP rV2S = rVS * AirSpeed; FP rV2Sb = rV2S * B; FP rV2Sc = rV2S * Ch; FP rSc = rS * Ch; FP rSc2 = rSc * Ch; // Get derivative inputs // Velocities FP u = -AirVel.z; FP v = -AirVel.x; FP w = AirVel.y; // Rotational velocities FP p = RotVel.z * 100; FP q = RotVel.x * 100; FP r = -RotVel.y * 100; // Calc Control inputs FP a = -((FP)Aileron * F2PIE * 20) / (32768 * 360); FP b = ((FP)Elevator * F2PIE * 20) / (32768 * 360); FP c = -((FP)Rudder * F2PIE * 20) / (32768 * 360); // Acceleration FP ud = 0; FP vd = 0; FP wd = 0; // Calc alpha FP alpha = CalcAngle (VecLen2D (u,v), w); if (alpha > DEGS2RADS(180)) alpha -= DEGS2RADS(360); alpha += DEGS2RADS (3); // alpha = testalpha; // if (alpha > DEGS2RADS(10)) alpha = DEGS2RADS(10); // if (alpha < DEGS2RADS(-10)) alpha = DEGS2RADS(-10); FP Sin = FSin (alpha); FP Cos = FCos (alpha); // Calc Cl, Cd FP Cl = alpha * 5.27; FP Cd = alpha * 0.29; #ifdef PRINT_DERV_DATA PrintVar (30, 16, "alp %.2f ", Rads2Degs(alpha)); PrintVar (45, 16, "Cl %.2f ", Cl); PrintVar (60, 16, "Cd %.2f ", Cd); PrintVar (30, 18, "u %.4f ", u); PrintVar (45, 18, "v %.4f ", v); PrintVar (60, 18, "w %.4f ", w); PrintVar (30, 19, "p %.4f ", p); PrintVar (45, 19, "q %.4f ", q); PrintVar (60, 19, "r %.4f ", r); #endif // Force Velocity dervs V.X.u = -Cd * u * rVS; V.Y.u = 0 * u * rVS; V.Z.u = -Cl * u * rVS; V.X.v = 0 * v * rVS; V.Y.v = -0.546 * v * rVS; V.Z.v = 0 * v * rVS; V.X.w = Cl * w * rVS; V.Y.w = 0 * w * rVS; V.Z.w = -Cd * w * rVS; // Moment Velocity dervs V.L.u = 0 * u * rVSb; V.M.u = 0 * u * rVSc; V.N.u = 0 * u * rVSb; V.L.v = -0.0654 * v * rVSb; V.M.v = 0 * v * rVSc; V.N.v = 0.118 * v * rVSb; V.L.w = 0 * w * rVSb; V.M.w = -0.44 * w * rVSc; V.N.w = 0 * w * rVSb; // ***************** // * V.M.w is iffy * // ***************** // Force RotVel dervs RV.X.p = 0; RV.Y.p = 0 * p * rVSb; RV.Z.p = 0; RV.X.q = 0 * q * rVSc; RV.Y.q = 0; RV.Z.q = 0 * q * rVSc; RV.X.r = 0; RV.Y.r = 0.1435 * r * rVSb; RV.Z.r = 0; // Moment RotVel dervs RV.L.p = -0.195 * p * rVSb2; RV.M.p = 0; RV.N.p = -0.008 * p * rVSb2; RV.L.q = 0; RV.M.q = -0.032 * q * rVSc2; RV.N.q = 0; RV.L.r = 0.0575 * r * rVSb2; RV.M.r = 0; RV.N.r = -0.067 * r * rVSb2; // Check M.q (c/2U ?????) // Force Control dervs C.X.a = 0; C.Y.a = 0 * a * rV2S; C.Z.a = 0; C.X.b = 0.43 * Sin * b * rV2S; C.Y.b = 0; C.Z.b = 0.43 * b * Cos * rV2S; C.X.c = 0; C.Y.c = 0.149 * c * rV2S; C.Z.c = 0; // Moment Control dervs C.L.a = -0.114 * a * rV2Sb; C.M.a = 0; C.N.a = 0.009 * a * rV2Sb; C.L.b = 0; C.M.b = -0.934 * b * rV2Sc; C.N.b = 0; C.L.c = 0.0057 * c * rV2Sb; C.M.c = 0; C.N.c = -0.069 * c * rV2Sb; // Z Acc dervs // use Cm alpha dot in F94A derv tables #ifdef PRINT_DERV_DATA PrintVar (30, 0, "V.X.u %.0f ", V.X.u); PrintVar (45, 0, "V.Y.u %.0f ", V.Y.u); PrintVar (60, 0, "V.Z.u %.0f ", V.Z.u); PrintVar (30, 1, "V.X.v %.0f ", V.X.v); PrintVar (45, 1, "V.Y.v %.0f ", V.Y.v); PrintVar (60, 1, "V.Z.v %.0f ", V.Z.v); PrintVar (30, 2, "V.X.w %.0f ", V.X.w); PrintVar (45, 2, "V.Y.w %.0f ", V.Y.w); PrintVar (60, 2, "V.Z.w %.0f ", V.Z.w); PrintVar (30, 4, "V.L.u %.0f ", V.L.u); PrintVar (45, 4, "V.M.u %.0f ", V.M.u); PrintVar (60, 4, "V.N.u %.0f ", V.N.u); PrintVar (30, 5, "V.L.v %.0f ", V.L.v); PrintVar (45, 5, "V.M.v %.0f ", V.M.v); PrintVar (60, 5, "V.N.v %.0f ", V.N.v); PrintVar (30, 6, "V.L.w %.0f ", V.L.w); PrintVar (45, 6, "V.M.w %.0f ", V.M.w); PrintVar (60, 6, "V.N.w %.0f ", V.N.w); PrintVar (30, 8, "RV.X.p %.0f ", RV.X.p); PrintVar (45, 8, "RV.Y.p %.0f ", RV.Y.p); PrintVar (60, 8, "RV.Z.p %.0f ", RV.Z.p); PrintVar (30, 9, "RV.X.q %.0f ", RV.X.q); PrintVar (45, 9, "RV.Y.q %.0f ", RV.Y.q); PrintVar (60, 9, "RV.Z.q %.0f ", RV.Z.q); PrintVar (30, 10, "RV.X.r %.0f ", RV.X.r); PrintVar (45, 10, "RV.Y.r %.0f ", RV.Y.r); PrintVar (60, 10, "RV.Z.r %.0f ", RV.Z.r); PrintVar (30, 12, "RV.L.p %.0f ", RV.L.p); PrintVar (45, 12, "RV.M.p %.0f ", RV.M.p); PrintVar (60, 12, "RV.N.p %.0f ", RV.N.p); PrintVar (30, 13, "RV.L.q %.0f ", RV.L.q); PrintVar (45, 13, "RV.M.q %.0f ", RV.M.q); PrintVar (60, 13, "RV.N.q %.0f ", RV.N.q); PrintVar (30, 14, "RV.L.r %.0f ", RV.L.r); PrintVar (45, 14, "RV.M.r %.0f ", RV.M.r); PrintVar (60, 14, "RV.N.r %.0f ", RV.N.r); #endif // calc forces FCRD force; force.x = V.X.u + V.X.v + V.X.w + RV.X.p + RV.X.q + RV.X.r + C.X.a + C.X.b + C.X.c; force.y = V.Y.u + V.Y.v + V.Y.w + RV.Y.p + RV.Y.q + RV.Y.r + C.Y.a + C.Y.b + C.Y.c; force.z = V.Z.u + V.Z.v + V.Z.w + RV.Z.p + RV.Z.q + RV.Z.r + C.Z.a + C.Z.b + C.Z.c; NettForce.x = force.y; NettForce.y = -force.z; NettForce.z = force.x; // calc moments FCRD moment; moment.x = V.L.u + V.L.v + V.L.w + RV.L.p + RV.L.q + RV.L.r + C.L.a + C.L.b + C.L.c; moment.y = V.M.u + V.M.v + V.M.w + RV.M.p + RV.M.q + RV.M.r + C.M.a + C.M.b + C.M.c; moment.z = V.N.u + V.N.v + V.N.w + RV.N.p + RV.N.q + RV.N.r + C.N.a + C.N.b + C.N.c; NettMoment.x = moment.y * 100; NettMoment.y = -moment.z * 100; NettMoment.z = moment.x * 100; // Engines PTHRUSTPOINT pThrust = ThrustList; while (pThrust != NULL) { pThrust->Process (); NettForce.x += pThrust->Force.x; NettForce.y += pThrust->Force.y; NettForce.z += pThrust->Force.z; pThrust = pThrust->List.NextItem (); } MODLIMIT (NettForce.x, 600000); MODLIMIT (NettForce.y, 2500000); MODLIMIT (NettForce.z, 600000); MODLIMIT (NettMoment.x, 250000000); MODLIMIT (NettMoment.y, 250000000); MODLIMIT (NettMoment.z, 250000000); CalcAcc (); //TempCode ARM 15Jul97 { //TempCode ARM 15Jul97 OldAcc.x = Acc.x; //TempCode ARM 15Jul97 OldAcc.y = Acc.y; //TempCode ARM 15Jul97 OldAcc.z = Acc.z; //TempCode ARM 15Jul97 //TempCode ARM 15Jul97 Acc.x = (NettForce.x / Mass); //TempCode ARM 15Jul97 Acc.y = (NettForce.y / Mass); //TempCode ARM 15Jul97 Acc.z = (NettForce.z / Mass); //TempCode ARM 15Jul97 } CalcRotAcc (); //TempCode ARM 15Jul97 { //TempCode ARM 15Jul97 OldRotAcc.x = RotAcc.x; //TempCode ARM 15Jul97 OldRotAcc.y = RotAcc.y; //TempCode ARM 15Jul97 OldRotAcc.z = RotAcc.z; //TempCode ARM 15Jul97 //TempCode ARM 15Jul97 RotAcc.x = (NettMoment.x / RotInertia.x); //TempCode ARM 15Jul97 RotAcc.y = (NettMoment.y / RotInertia.y); //TempCode ARM 15Jul97 RotAcc.z = (NettMoment.z / RotInertia.z); //TempCode ARM 15Jul97 } TransInt (ALL); //TempCode ARM 15Jul97 { //TempCode ARM 15Jul97 FCRD acc; //TempCode ARM 15Jul97 //TempCode ARM 15Jul97 acc.x = (OldAcc.x + Acc.x) * 0.5; //TempCode ARM 15Jul97 acc.y = (OldAcc.y + Acc.y) * 0.5; //TempCode ARM 15Jul97 acc.z = (OldAcc.z + Acc.z) * 0.5; //TempCode ARM 15Jul97 //TempCode ARM 15Jul97 TnsPnt (acc, acc, Ori); //TempCode ARM 15Jul97 //TempCode ARM 15Jul97 OldVel.x = Vel.x; //TempCode ARM 15Jul97 OldVel.y = Vel.y; //TempCode ARM 15Jul97 OldVel.z = Vel.z; //TempCode ARM 15Jul97 //TempCode ARM 15Jul97 Vel.x += acc.x * MODEL_DT; //TempCode ARM 15Jul97 Vel.y += (acc.y - GRAVITY) * MODEL_DT; //TempCode ARM 15Jul97 Vel.z += acc.z * MODEL_DT; //TempCode ARM 15Jul97 //TempCode ARM 15Jul97 OldPos.x = Pos.x; //TempCode ARM 15Jul97 OldPos.y = Pos.y; //TempCode ARM 15Jul97 OldPos.z = Pos.z; //TempCode ARM 15Jul97 //TempCode ARM 15Jul97 Pos.x += ((OldVel.x + Vel.x) * MODEL_DT) * 0.5; //TempCode ARM 15Jul97 Pos.y += ((OldVel.y + Vel.y) * MODEL_DT) * 0.5; //TempCode ARM 15Jul97 Pos.z += ((OldVel.z + Vel.z) * MODEL_DT) * 0.5; //TempCode ARM 15Jul97 } RotInt (ALL); //TempCode ARM 15Jul97 { //TempCode ARM 15Jul97 OldRotVel.x = RotVel.x; //TempCode ARM 15Jul97 OldRotVel.y = RotVel.y; //TempCode ARM 15Jul97 OldRotVel.z = RotVel.z; //TempCode ARM 15Jul97 //TempCode ARM 15Jul97 RotVel.x += ((OldRotAcc.x + RotAcc.x) * MODEL_DT) * 0.5; //TempCode ARM 15Jul97 RotVel.y += ((OldRotAcc.y + RotAcc.y) * MODEL_DT) * 0.5; //TempCode ARM 15Jul97 RotVel.z += ((OldRotAcc.z + RotAcc.z) * MODEL_DT) * 0.5; //TempCode ARM 15Jul97 //TempCode ARM 15Jul97 RotVelInt (); //TempCode ARM 15Jul97 } // UpdateAirStruc (); // Ground (); // Instruments (ControlledAC); }
bool CManipRot::UIEventHandler( const ui::Event& EV ) { int ex = EV.miX; int ey = EV.miY; CVector2 posubp = EV.GetUnitCoordBP(); CCamera *pcam = mManager.GetActiveCamera(); bool brval = false; bool isshift = false; //CSystem::IsKeyDepressed(VK_SHIFT ); bool isctrl = false; //CSystem::IsKeyDepressed(VK_CONTROL ); switch( EV.miEventCode ) { case ui::UIEV_PUSH: { mManager.mManipHandler.Init(posubp, pcam->mCameraData.GetIVPMatrix(), pcam->QuatC ); mBaseTransform = mManager.mCurTransform; SelectBestPlane(posubp); brval = true; } break; case ui::UIEV_RELEASE: { mManager.DisableManip(); brval = true; } break; case ui::UIEV_DRAG: { IntersectWithPlanes( posubp ); if ( CheckIntersect() ) { /////////////////////////////////////////// // calc normalvectors from base:origin to point on activeintersection plane (in world space) const CVector3 & Origin = mBaseTransform.GetTransform().GetPosition(); CVector3 D1 = (Origin-mActiveIntersection->mIntersectionPoint).Normal(); CVector3 D0 = (Origin-mActiveIntersection->mBaseIntersectionPoint).Normal(); /////////////////////////////////////////// // calc matrix to put worldspace vector into plane local space CMatrix4 MatWldToObj = mBaseTransform.GetTransform().GetMatrix(); //GetRotation(); MatWldToObj.Inverse(); CVector4 bAxisAngle = mLocalRotationAxis; CQuaternion brq; brq.FromAxisAngle(bAxisAngle); CMatrix4 MatObjToPln = brq.ToMatrix(); MatObjToPln.Inverse(); CMatrix4 MatWldToPln = MatObjToPln*MatWldToObj; //CMatrix4 MatInvRot = InvQuat.ToMatrix(); /////////////////////////////////////////// // calc plane local rotation CVector4 AxisAngle = mLocalRotationAxis; CVector4 D0I = CVector4(D0,CReal(0.0f)).Transform(MatWldToPln); CVector4 D1I = CVector4(D1,CReal(0.0f)).Transform(MatWldToPln); //orkprintf( "D0 <%f %f %f>\n", float(D0.GetX()), float(D0.GetY()), float(D0.GetZ()) ); //orkprintf( "D1 <%f %f %f>\n", float(D1.GetX()), float(D1.GetY()), float(D1.GetZ()) ); //orkprintf( "D0I <%f %f %f>\n", float(D0I.GetX()), float(D0I.GetY()), float(D0I.GetZ()) ); //orkprintf( "D1I <%f %f %f>\n", float(D1I.GetX()), float(D1I.GetY()), float(D1I.GetZ()) ); AxisAngle.SetW( CalcAngle(D0I,D1I) ); CQuaternion RotQ; RotQ.FromAxisAngle( AxisAngle ); /////////////////// // Rot Snap if( isshift ) { CReal SnapAngleVal( PI2/16.0f ); CVector4 NewAxisAngle = RotQ.ToAxisAngle(); CReal Angle = NewAxisAngle.GetW(); Angle = SnapReal( Angle, SnapAngleVal ); NewAxisAngle.SetW( Angle ); RotQ.FromAxisAngle( NewAxisAngle ); } /////////////////// // accum rotation CQuaternion oq = mBaseTransform.GetTransform().GetRotation(); CQuaternion NewQ = RotQ.Multiply(oq); /////////////////// // Rot Reset To Identity if( isctrl && isshift ) { NewQ.FromAxisAngle( CVector4( CReal(0.0f), CReal(1.0f), CReal(0.0f), CReal(0.0f) ) ); } /////////////////// TransformNode mset = mManager.mCurTransform; mset.GetTransform().SetRotation( NewQ ); mManager.ApplyTransform( mset ); /////////////////// } brval = true; } break; default: break; } return brval; }
void Game::PlayGameMode2() { GraphicsEngine* mGe = GetGraphics(); GetGraphics()->ShowLoadingScreen("Media/LoadingScreen/LoadingScreenBG2.png", "Media/LoadingScreen/LoadingScreenPB.png", 1.0f, 1.0f); GetGraphics()->ChangeSkyBox("Media/StarMap.dds"); GetGraphics()->GetCamera()->SetUpVector(Vector3(0, 1, 0)); GetGraphics()->GetCamera()->SetForward(Vector3(1, 0, 0)); GetGraphics()->GetCamera()->SetPosition(Vector3(-17.0f, 56.0f, 0)); GetGraphics()->GetCamera()->LookAt(GetGraphics()->GetCamera()->GetPosition() - Vector3(1, 0.3f, 0)); iLight* mLights[5]; mLights[0] = mGe->CreateLight(Vector3(0, 50, 0)); mLights[1] = mGe->CreateLight(Vector3(0, 50, -20)); mLights[2] = mGe->CreateLight(Vector3(0, 50, 20)); mLights[3] = mGe->CreateLight(Vector3(10, 50, 0)); mLights[4] = mGe->CreateLight(Vector3(-10, 50, 0)); for(int i = 0; i < 5; i++) mLights[i]->SetIntensity(30.0f); GetGraphics()->SetSunLightDisabled(); GetGraphics()->SetSceneAmbientLight(Vector3(0.4f, 0.4f, 0.4f)); Vector3 centerPlatform = Vector3(0,20,0); Map* mPlatform = new Map("Media/MazeMapFixed.obj", centerPlatform); Map* mBox = new Map("Media/MazeMapFrame.obj", centerPlatform + Vector3(0,1,0) ); mPlatform->SetShrinkValue(0.0f); /* set so we cant tilt it more than these angles. */ mPlatform->SetMaxAngleX(10.0f*(PI/180.0f)); mPlatform->SetMaxAngleZ(10.0f*(PI/180.0f)); mPlatform->SetRotate(false); mPlatform->SetTargetAngleX(0.5f); mPlatform->SetTargetAngleZ(-0.5f); PowerBall* mBalls = new PowerBall("Media/Ball.obj", START_POS); mBalls->SetForwardVector(Vector3(0,0,1)); mBalls->SetKnockoutMode(); mBalls->SetAcceleration(mBalls->GetAcceleration()*30.0f); iText* timeTxt = GetGraphics()->CreateText("", Vector2(50, 60), 1.0f, "Media/fonts/new"); iText* scoreTxt = GetGraphics()->CreateText("", Vector2(50, 95), 1.0f, "Media/fonts/new"); iImage* guiStar = GetGraphics()->CreateImage(Vector2(200, 90), Vector2(75, 75), "Media/star.png"); guiStar->SetOpacity(0.0f); float starTimer = 0.0f; GetGraphics()->LoadingScreen("Media/LoadingScreen/LoadingScreenBG2.png", "Media/LoadingScreen/LoadingScreenPB.png", 1.0f, 1.0f, 1.0f, 1.0f); this->FlushQueue(); mGe->GetCamera()->SetPosition(centerPlatform + Vector3(0.0f, 30.0f, 20.0f)); mGe->GetCamera()->LookAt(centerPlatform); // Score / results: float time = 0.0f; bool started = false; int score = 0; float delayTimer = 1000.0f; GetGraphics()->GetKeyListener()->SetCursorVisibility(false); go = true; const Vector3 DefaultDir = Vector3(0.0f, 1.0f, 0.0f); int currentPrev = 0; Vector3 prevVectors[NROFPREV]; for(int i = 0; i < NROFPREV; i++) { prevVectors[i] = DefaultDir; } while(delayTimer > 0) { float diff = GetGraphics()->Update(); delayTimer -= diff; } while(GetGraphics()->IsRunning() && go) { if(mGe->GetKeyListener()->IsPressed('1')) { mGe->GetCamera()->SetPosition(centerPlatform+ Vector3(20.0f, 30.0f, 20.0f)); mGe->GetCamera()->LookAt(centerPlatform ); } if(mGe->GetKeyListener()->IsPressed('2')) { mGe->GetCamera()->SetPosition(centerPlatform+ Vector3(20.0f, 30.0f, -20.0f)); mGe->GetCamera()->LookAt(centerPlatform ); } if(mGe->GetKeyListener()->IsPressed('3')) { mGe->GetCamera()->SetPosition(centerPlatform+ Vector3(-20.0f, 30.0f, 20.0f)); mGe->GetCamera()->LookAt(centerPlatform ); } if(mGe->GetKeyListener()->IsPressed('4')) { mGe->GetCamera()->SetPosition(centerPlatform+ Vector3(-20.0f, 30.0f, -20.0f)); mGe->GetCamera()->LookAt(centerPlatform ); } // Updates GFX float diff = GetGraphics()->Update(); // Handle events such as network packets and client connections this->HandleEvent(diff); if(GetGraphics()->GetKeyListener()->IsPressed(VK_ESCAPE)) go = false; if(GetGraphics()->GetKeyListener()->IsPressed('R') || (this->networkController != NULL && this->networkController->needRestart == true)) { if(this->networkController != NULL) { this->networkController->needRestart = false; } delete mBalls; // Spawn at last score - 1; if(score == 0) mBalls = new PowerBall("Media/Ball.obj", scorePos[0]); else mBalls = new PowerBall("Media/Ball.obj", scorePos[score - 1]); mBalls->SetForwardVector(Vector3(0,0,1)); mBalls->SetKnockoutMode(); mBalls->SetAcceleration(mBalls->GetAcceleration()*15.0f); mPlatform->ResetXZAngles(); mPlatform->RotateX(0); } iPhysicsEngine* pe = GetGraphics()->GetPhysicsEngine(); mBalls->UpdateBallParentMode(mPlatform); mBalls->Update(diff); Vector3 normalPlane; if(pe->DoSpecialPhoneCollisionGame(mBalls, mPlatform, normalPlane, diff)) mBalls->collisionPlatformResponse(mPlatform, normalPlane, diff); mBalls->UpdatePost(); mPlatform->Update(diff); if(this->networkController) { mPlatform->SetRotate(true); Vector3 phoneDirr = Vector3(this->networkController->direction.y, this->networkController->direction.z, -this->networkController->direction.x); //Vector3 phoneDirr = this->networkController->direction; phoneDirr.Normalize(); prevVectors[currentPrev] = phoneDirr; float angle = CalcAngle(phoneDirr, DefaultDir, prevVectors, currentPrev); float angleX = acos(DefaultDir.GetDotProduct(Vector3(0, phoneDirr.y , phoneDirr.z).Normalize())); float angleZ = acos(DefaultDir.GetDotProduct(Vector3(phoneDirr.x, phoneDirr.y, 0).Normalize())); if(phoneDirr.z > 0) { angleX *= -1; } if(phoneDirr.x < 0) { angleZ *= -1; } mPlatform->SetTargetAngleX(angleX/4); mPlatform->SetTargetAngleZ(angleZ/4); angle /= 4; currentPrev++; if(currentPrev >= NROFPREV) currentPrev = 0; } if(mGe->GetKeyListener()->IsPressed('W')) { mPlatform->RotateX(-diff); Vector3 tempPos = mBalls->GetPosition() - mPlatform->GetMesh()->GetPosition(); tempPos.RotateAroundAxis(Vector3(1,0,0), (PI/8.0f)*-diff*0.001f); mBalls->SetPosition(mPlatform->GetMesh()->GetPosition() + tempPos); } if(mGe->GetKeyListener()->IsPressed('S')) { mPlatform->RotateX(diff); Vector3 tempPos = mBalls->GetPosition() - mPlatform->GetMesh()->GetPosition(); tempPos.RotateAroundAxis(Vector3(1,0,0), (PI/8.0f)*diff*0.001f); mBalls->SetPosition(mPlatform->GetMesh()->GetPosition() + tempPos); } if(mGe->GetKeyListener()->IsPressed('A')) { mPlatform->RotateZ(-diff); Vector3 tempPos = mBalls->GetPosition() - mPlatform->GetMesh()->GetPosition(); tempPos.RotateAroundAxis(Vector3(0,0,1), (PI/8.0f)*-diff*0.001f); mBalls->SetPosition(mPlatform->GetMesh()->GetPosition() + tempPos); } if(mGe->GetKeyListener()->IsPressed('D')) { mPlatform->RotateZ(diff); Vector3 tempPos = mBalls->GetPosition() - mPlatform->GetMesh()->GetPosition(); tempPos.RotateAroundAxis(Vector3(0,0,1), (PI/8.0f)*diff*0.001f); mBalls->SetPosition(mPlatform->GetMesh()->GetPosition() + tempPos); } ////////////////////////////////////////////////////////////////////////// static bool posb = true; if(GetGraphics()->GetKeyListener()->IsPressed('Q')) { if(posb) { MaloW::Debug(mBalls->GetPosition()); posb = false; } } else posb = true; ////////////////////////////////////////////////////////////////////////// if(started) { for(int i = score + 1; i < 15; i++) { Vector3 toScore = scorePos[i] - mBalls->GetPosition(); toScore.y = 0.0f; float distanceToScore = toScore.GetLength(); if(distanceToScore < 2.0f) { score = i; starTimer = 2.0f; // Do Vibration if(this->networkController) { this->networkController->cc->sendData("VIB: 100"); } } } time += diff * 0.001f; } else { if((mBalls->GetPosition() - Vector3(-13.0f,25,-13)).GetLength() > 3) { started = true; } } starTimer -= diff * 0.001f; if(starTimer < 0.0f) starTimer = 0.0f; guiStar->SetOpacity(starTimer); // print score and time text scoreTxt->SetText(string("SCORE: " + MaloW::convertNrToString(score)).c_str()); timeTxt->SetText(string("TIME: " + MaloW::convertNrToString(time)).c_str()); // End game after 2 mins if(time > 120.0f || score > 13) { this->FinishScreen(score, "2, Labyrinth", time); go = false; } } if(this->networkController) { this->networkController->cc->sendData("QUITTING"); } for(int i = 0; i < 5; i++) mGe->DeleteLight(mLights[i]); delete mPlatform; delete mBalls; delete mBox; mGe->DeleteText(timeTxt); mGe->DeleteText(scoreTxt); GetGraphics()->DeleteImage(guiStar); }