void CPlayerCamera::SetRotation ( CVector & vecRotation ) { // Rotate a 1000,0,0 vector with the given rotation vector CVector vecRotationCopy = vecRotation; vecRotationCopy.fX = 0.0f; CVector vecNormal = CVector ( 1000.0f, 0.0f, 0.0f ); RotateVector ( vecNormal, vecRotationCopy ); // Add it with our current position vecNormal += m_vecPosition; // Set the calculated vector as the target m_vecLookAt = vecNormal; }
bool CRigidBody::Contains(const PAVECTOR* pPoint) { D3DXVECTOR3 localPoint = (*pPoint) - m_position; localPoint = RotateVector(localPoint, true); for (std::list<Ptr<IHitbox>>::iterator it = m_lHitbox.begin(); it != m_lHitbox.end(); it++) { if ((*it)->Contains(&PAVector(localPoint))) return true; } return false; }
BOOL CGeometry::TransformLights(D3DVECTOR *CameraRotation,D3DVECTOR *CameraPosition) { HRESULT ddrval; for(int i=0; i<MAXLIGHTS; i++) { if(m_Lights[i].InUse) { D3DVECTOR RelVec = m_Lights[i].Position; RelVec.x -= CameraPosition->x; RelVec.y -= CameraPosition->y; RelVec.z -= CameraPosition->z; SetWorldMatrix(CameraRotation); RotateVector(&RelVec,&m_Lights[i].LightDesc.dvPosition); if(m_Lights[i].Transform) { RelVec = m_Lights[i].Direction; RotateVector(&RelVec,&m_Lights[i].LightDesc.dvDirection); } DXCALL(m_Lights[i].Light->SetLight(&m_Lights[i].LightDesc)); } } return TRUE; }
void CClientCamera::SetRotation ( const CVector& vecRotation ) { // Rotate a 1000,0,0 vector with the given rotation vector CVector vecRotationCopy = vecRotation; vecRotationCopy.fX = 0.0f; CVector vecNormal = CVector ( 1000.0f, 0.0f, 0.0f ); RotateVector ( vecNormal, vecRotationCopy ); // Add it with our current position CVector vecPosition; GetPosition ( vecPosition ); vecPosition += vecNormal; // Set the calculated vector as the target SetTarget ( vecPosition ); }
void TMercury::Reflect(value_type x1, state_type y1, value_type &x2, state_type &y2, int &polarisation, const double normal[3], solid *leaving, solid *entering, bool &trajectoryaltered, bool &traversed){ value_type vnormal = y1[3]*normal[0] + y1[4]*normal[1] + y1[5]*normal[2]; // velocity normal to reflection plane //particle was neither transmitted nor absorbed, so it has to be reflected double prob = mc->UniformDist(0,1); material *mat = vnormal < 0 ? &entering->mat : &leaving->mat; double diffprob = mat->DiffProb; // cout << "prob: " << diffprob << '\n'; if (prob >= diffprob){ //************** specular reflection ************** // printf("Specular reflection! Erefl=%LG neV\n",Enormal*1e9); x2 = x1; for (int i = 0; i < 6; i++) y2[i] = y1[i]; y2[3] -= 2*vnormal*normal[0]; // reflect velocity y2[4] -= 2*vnormal*normal[1]; y2[5] -= 2*vnormal*normal[2]; } else{ //************** diffuse reflection no MR model ************ double phi_r, theta_r; phi_r = mc->UniformDist(0, 2*pi); // generate random reflection angles (Lambert's law) theta_r = mc->SinCosDist(0, 0.5*pi); if (vnormal > 0) theta_r = pi - theta_r; // if velocity points out of volume invert polar angle x2 = x1; for (int i = 0; i < 3; i++) y2[i] = y1[i]; value_type vabs = sqrt(y1[3]*y1[3] + y1[4]*y1[4] + y1[5]*y1[5]); y2[3] = vabs*cos(phi_r)*sin(theta_r); // new velocity with respect to z-axis y2[4] = vabs*sin(phi_r)*sin(theta_r); y2[5] = vabs*cos(theta_r); RotateVector(&y2[3], normal, &y1[3]); // rotate velocity into coordinate system defined by incoming velocity and plane normal // printf("Diffuse reflection! Erefl=%LG neV w_e=%LG w_s=%LG\n",Enormal*1e9,phi_r/conv,theta_r/conv); } if (mc->UniformDist(0,1) < entering->mat.SpinflipProb){ polarisation *= -1; Nspinflip++; } traversed = false; trajectoryaltered = true; } // end reflect method
void ScanHModelForDecals(DISPLAYBLOCK *objectPtr, SECTION_DATA *sectionDataPtr) { SECTION *sectionPtr = sectionDataPtr->sempai; /* Unreal things aren't drawn... */ if (!(sectionDataPtr->flags§ion_data_notreal) && (sectionPtr->Shape!=NULL)) { /* does the object have decals? */ extern MODULE *playerPherModule; if(sectionDataPtr->NumberOfDecals && playerPherModule) { int d; for(d=0; d<sectionDataPtr->NumberOfDecals; d++) { int i; DECAL decal; decal.DecalID = sectionDataPtr->Decals[d].DecalID; decal.ModuleIndex = playerPherModule->m_index; decal.UOffset = 0; for(i=0; i<5; i++) { decal.Vertices[i] = sectionDataPtr->Decals[d].Vertices[i]; RotateVector(&(decal.Vertices[i]),&(sectionDataPtr->SecMat)); decal.Vertices[i].vx += sectionDataPtr->World_Offset.vx; decal.Vertices[i].vy += sectionDataPtr->World_Offset.vy; decal.Vertices[i].vz += sectionDataPtr->World_Offset.vz; } RenderDecal(&decal); } } } /* Now call recursion... */ if (sectionDataPtr->First_Child!=NULL) { SECTION_DATA *childrenListPtr = sectionDataPtr->First_Child; while (childrenListPtr!=NULL) { ScanHModelForDecals(objectPtr,childrenListPtr); childrenListPtr=childrenListPtr->Next_Sibling; } } }
void NtlGetDestination_Keyboard_TURN_R(float fCurrentHeadingVectorX, float fCurrentHeadingVectorZ, float fSpeedInSecs, float fCurrentPositionX, float fCurrentPositionY, float fCurrentPositionZ, DWORD dwDeltaTimeInMillisecs, float fTurningSpeedRatio, CNtlVector* pNewHeadingVector, CNtlVector* pDestination) { UNREFERENCED_PARAMETER( fSpeedInSecs ); pNewHeadingVector->x = fCurrentHeadingVectorX; pNewHeadingVector->y = 0.0f; pNewHeadingVector->z = fCurrentHeadingVectorZ; pDestination->x = fCurrentPositionX; pDestination->y = fCurrentPositionY; pDestination->z = fCurrentPositionZ; float fRadian = 2 * NTL_PI * ((float)dwDeltaTimeInMillisecs / (float)NTL_REQUIRED_TIME_FOR_COMPLETE_CIRCULAR_MOVEMENT_IN_MILLISECS); fRadian *= fTurningSpeedRatio; *pNewHeadingVector = RotateVector(pNewHeadingVector, -fRadian); }
/** * Drive method for Mecanum wheeled robots. * * A method for driving with Mecanum wheeled robots. There are 4 wheels * on the robot, arranged so that the front and back wheels are toed in 45 degrees. * When looking at the wheels from the top, the roller axles should form an X across the robot. * * This is designed to be directly driven by joystick axes. * * @param x The speed that the robot should drive in the X direction. [-1.0..1.0] * @param y The speed that the robot should drive in the Y direction. * This input is inverted to match the forward == -1.0 that joysticks produce. [-1.0..1.0] * @param rotation The rate of rotation for the robot that is completely independent of * the translation. [-1.0..1.0] * @param gyroAngle The current angle reading from the gyro. Use this to implement field-oriented controls. */ void RobotDrive::MecanumDrive_Cartesian(float x, float y, float rotation, float gyroAngle) { double xIn = x; double yIn = y; // Negate y for the joystick. yIn = -yIn; // Compenstate for gyro angle. RotateVector(xIn, yIn, gyroAngle); double wheelSpeeds[kMaxNumberOfMotors]; wheelSpeeds[kFrontLeftMotor] = xIn + yIn + rotation; wheelSpeeds[kFrontRightMotor] = -xIn + yIn - rotation; wheelSpeeds[kRearLeftMotor] = -xIn + yIn + rotation; wheelSpeeds[kRearRightMotor] = xIn + yIn - rotation; Normalize(wheelSpeeds); m_frontLeftMotor->Set(wheelSpeeds[kFrontLeftMotor] * m_invertedMotors[kFrontLeftMotor]); m_frontRightMotor->Set(wheelSpeeds[kFrontRightMotor] * m_invertedMotors[kFrontRightMotor]); m_rearLeftMotor->Set(wheelSpeeds[kRearLeftMotor] * m_invertedMotors[kRearLeftMotor]); m_rearRightMotor->Set(wheelSpeeds[kRearRightMotor] * m_invertedMotors[kRearRightMotor]); }
/** * Drive method for Mecanum wheeled robots. * * A method for driving with Mecanum wheeled robots. There are 4 wheels * on the robot, arranged so that the front and back wheels are toed in 45 * degrees. * When looking at the wheels from the top, the roller axles should form an X * across the robot. * * This is designed to be directly driven by joystick axes. * * @param x The speed that the robot should drive in the X direction. * [-1.0..1.0] * @param y The speed that the robot should drive in the Y direction. * This input is inverted to match the forward == -1.0 that joysticks produce. * [-1.0..1.0] * @param rotation The rate of rotation for the robot that is completely * independent of * the translation. [-1.0..1.0] * @param gyroAngle The current angle reading from the gyro. Use this to * implement field-oriented controls. */ void RobotDrive::MecanumDrive_Cartesian(float x, float y, float rotation, float gyroAngle) { static bool reported = false; if (!reported) { HALReport(HALUsageReporting::kResourceType_RobotDrive, GetNumMotors(), HALUsageReporting::kRobotDrive_MecanumCartesian); reported = true; } double xIn = x; double yIn = y; // Negate y for the joystick. yIn = -yIn; // Compenstate for gyro angle. RotateVector(xIn, yIn, gyroAngle); double wheelSpeeds[kMaxNumberOfMotors]; wheelSpeeds[kFrontLeftMotor] = xIn + yIn + rotation; wheelSpeeds[kFrontRightMotor] = -xIn + yIn - rotation; wheelSpeeds[kRearLeftMotor] = -xIn + yIn + rotation; wheelSpeeds[kRearRightMotor] = xIn + yIn - rotation; Normalize(wheelSpeeds); m_frontLeftMotor->Set(wheelSpeeds[kFrontLeftMotor] * m_maxOutput, m_syncGroup); m_frontRightMotor->Set(wheelSpeeds[kFrontRightMotor] * m_maxOutput, m_syncGroup); m_rearLeftMotor->Set(wheelSpeeds[kRearLeftMotor] * m_maxOutput, m_syncGroup); m_rearRightMotor->Set(wheelSpeeds[kRearRightMotor] * m_maxOutput, m_syncGroup); if (m_syncGroup != 0) { CANJaguar::UpdateSyncGroup(m_syncGroup); } m_safetyHelper->Feed(); }
TParticle* TSurfaceSource::CreateParticle(){ double t = fmc->UniformDist(0, fActiveTime); double RandA = fmc->UniformDist(0,sourcearea); double SumA = 0; vector<TTriangle>::iterator i; for (i = sourcetris.begin(); i != sourcetris.end(); i++){ SumA += i->area(); if (RandA <= SumA) break; } double a = fmc->UniformDist(0,1); // generate random point on triangle (see Numerical Recipes 3rd ed., p. 1114) double b = fmc->UniformDist(0,1); if (a+b > 1){ a = 1 - a; b = 1 - b; } CVector nv = i->normal(); CPoint p = i->tri[0] + a*(i->tri[1] - i->tri[0]) + b*(i->tri[2] - i->tri[0]) + nv*REFLECT_TOLERANCE; double Ekin = fmc->Spectrum(fParticleName); double phi_v = fmc->UniformDist(0, 2*pi); // generate random velocity angles in upper hemisphere double theta_v = fmc->SinCosDist(0, 0.5*pi); // Lambert's law! if (Enormal > 0){ double vnormal = sqrt(Ekin*cos(theta_v)*cos(theta_v) + Enormal); // add E_normal to component normal to surface double vtangential = sqrt(Ekin)*sin(theta_v); theta_v = atan2(vtangential, vnormal); // update angle Ekin = vnormal*vnormal + vtangential*vtangential; // update energy } double v[3] = {cos(phi_v)*sin(theta_v), sin(phi_v)*sin(theta_v), cos(theta_v)}; double n[3] = {nv[0], nv[1], nv[2]}; RotateVector(v, n); phi_v = atan2(v[1],v[0]); theta_v = acos(v[2]); int polarisation = fmc->DicePolarisation(fParticleName); return TParticleSource::CreateParticle(t, p[0], p[1], p[2], Ekin, phi_v, theta_v, polarisation); }
void NtlGetDestination_Keyboard_B_TURN_R(float fCurrentHeadingVectorX, float fCurrentHeadingVectorZ, float fSpeedInSecs, float fCurrentPositionX, float fCurrentPositionY, float fCurrentPositionZ, DWORD dwDeltaTimeInMillisecs, float fTurningSpeedRatio, CNtlVector* pNewHeadingVector, CNtlVector* pDestination) { pNewHeadingVector->x = fCurrentHeadingVectorX; pNewHeadingVector->y = 0.0f; pNewHeadingVector->z = fCurrentHeadingVectorZ; float fRadian = 2 * NTL_PI * ((float)dwDeltaTimeInMillisecs / (float)NTL_REQUIRED_TIME_FOR_COMPLETE_CIRCULAR_MOVEMENT_IN_MILLISECS); fRadian *= fTurningSpeedRatio; *pNewHeadingVector = RotateVector(pNewHeadingVector, -fRadian); float fRadius = 0.0f; fRadius = (fSpeedInSecs * NTL_BACKWARD_MOVEMENT_SPEED_RATE) * ((float)NTL_REQUIRED_TIME_FOR_COMPLETE_CIRCULAR_MOVEMENT_IN_MILLISECS / (float)1000) / (2 * NTL_PI); float fTempX = fCurrentHeadingVectorX * fRadius / sqrt(fCurrentHeadingVectorX * fCurrentHeadingVectorX + fCurrentHeadingVectorZ * fCurrentHeadingVectorZ); float fTempZ = fCurrentHeadingVectorZ * fRadius / sqrt(fCurrentHeadingVectorX * fCurrentHeadingVectorX + fCurrentHeadingVectorZ * fCurrentHeadingVectorZ); pDestination->x = fCurrentPositionX - fTempX * sin(fRadian) + fTempZ * (1 - cos(fRadian)); pDestination->y = fCurrentPositionY; pDestination->z = fCurrentPositionZ - fTempZ * sin(fRadian) - fTempX * (1 - cos(fRadian)); }
void TeleportPreservedSBsToNewEnvModule(MODULE *new_pos, MODULE* old_pos, int orient_change) { int i; VECTORCH mod_offset; mod_offset.vx = new_pos->m_world.vx - old_pos->m_world.vx; mod_offset.vy = new_pos->m_world.vy - old_pos->m_world.vy; mod_offset.vz = new_pos->m_world.vz - old_pos->m_world.vz; for(i = 0; i < Num_SB_Preserved; i++) { VECTORCH obj_world; VECTORCH pos_rel; STRATEGYBLOCK *sbptr; DYNAMICSBLOCK *dynptr; sbptr = &SB_Preserved[i]; dynptr = sbptr->DynPtr; GLOBALASSERT(dynptr); obj_world = sbptr->DynPtr->Position; { // okay we need to find our relative position to the moduke int cos; int sin; int angle; MATRIXCH mat; pos_rel.vx = dynptr->Position.vx - old_pos->m_world.vx; pos_rel.vy = dynptr->Position.vy - old_pos->m_world.vy; pos_rel.vz = dynptr->Position.vz - old_pos->m_world.vz; if(orient_change == 1 || orient_change == -3) angle = 1024; else if(orient_change == 2 || orient_change == -2) angle = 2048; else if(orient_change == 3 || orient_change == -1) angle = 3072; else angle = 0; cos = GetCos(angle); sin = GetSin(angle); mat.mat11 = cos; mat.mat12 = 0; mat.mat13 = -sin; mat.mat21 = 0; mat.mat22 = 65536; mat.mat23 = 0; mat.mat31 = sin; mat.mat32 = 0; mat.mat33 = cos; // rotate the relative object about the center of the // module and rotate the abject about its own y-axis RotateVector(&pos_rel, &mat); MatrixMultiply(&dynptr->OrientMat,&mat,&dynptr->OrientMat); MatrixToEuler(&dynptr->OrientMat, &dynptr->OrientEuler); } #if 0 dynptr->Position.vx = mod_offset.vx; dynptr->Position.vy = mod_offset.vy; dynptr->Position.vz = mod_offset.vz; dynptr->PrevPosition.vx = mod_offset.vx; dynptr->PrevPosition.vy = mod_offset.vy; dynptr->PrevPosition.vz = mod_offset.vz; #endif dynptr->Position.vx = pos_rel.vx + new_pos->m_world.vx; dynptr->Position.vy = pos_rel.vy + new_pos->m_world.vy; dynptr->Position.vz = pos_rel.vz + new_pos->m_world.vz; dynptr->PrevPosition.vx = -pos_rel.vx + old_pos->m_world.vx; dynptr->PrevPosition.vy = -pos_rel.vy + old_pos->m_world.vy; dynptr->PrevPosition.vz = -pos_rel.vz + old_pos->m_world.vz; } }
bool DexMouseTracker::GetCurrentMarkerFrame( CodaFrame &frame ) { POINT mouse_position; GetCursorPos( &mouse_position ); RECT rect; GetWindowRect( GetDesktopWindow(), &rect ); Vector3 position, rotated; Vector3 x_dir, y_span, z_span; Vector3 x_displacement, y_displacement, z_displacement; double x, y, z; Quaternion Ry, Rz, Q, nominalQ, midQ; Matrix3x3 xform = {{-1.0, 0.0, 0.0},{0.0, 0.0, 1.0},{0.0, 1.0, 0.0}}; int mrk, id; // Just set the target frame markers at their nominal fixed positions. for ( mrk = 0; mrk < nFrameMarkers; mrk++ ) { id = FrameMarkerID[mrk]; CopyVector( frame.marker[id].position, TargetFrameBody[mrk] ); } // Shift the vertical bar markers to simulate being in the left position. if ( IsDlgButtonChecked( dlg, IDC_LEFT ) ) { frame.marker[DEX_NEGATIVE_BAR_MARKER].position[X] += 300.0; frame.marker[DEX_POSITIVE_BAR_MARKER].position[X] += 300.0; } // Transform the marker positions of the target box and frame according // to whether the system was upright or supine when it was aligned and // according to whether the system is currently installed in the upright // or supine configuration. if ( ( IsDlgButtonChecked( dlg, IDC_SUPINE ) && TRACKER_ALIGNED_SUPINE != SendDlgItemMessage( dlg, IDC_ALIGNMENT, CB_GETCURSEL, 0, 0 ) ) || ( IsDlgButtonChecked( dlg, IDC_SEATED ) && TRACKER_ALIGNED_UPRIGHT != SendDlgItemMessage( dlg, IDC_ALIGNMENT, CB_GETCURSEL, 0, 0 ) ) ) { for ( mrk = 0; mrk < nFrameMarkers; mrk++ ) { id = FrameMarkerID[mrk]; position[X] = - frame.marker[id].position[X]; position[Z] = frame.marker[id].position[Y]; position[Y] = frame.marker[id].position[Z]; CopyVector( frame.marker[id].position, position ); } MatrixToQuaternion( nominalQ, xform ); } else CopyQuaternion( nominalQ, nullQuaternion ); // Now set the visibility flag as a funciton of the GUI. if ( IsDlgButtonChecked( dlg, IDC_BAR_OCCLUDED ) ) { frame.marker[DEX_NEGATIVE_BAR_MARKER].visibility = false; frame.marker[DEX_POSITIVE_BAR_MARKER].visibility = false; } else { frame.marker[DEX_NEGATIVE_BAR_MARKER].visibility = true; frame.marker[DEX_POSITIVE_BAR_MARKER].visibility = true; } if ( IsDlgButtonChecked( dlg, IDC_BOX_OCCLUDED ) ) { frame.marker[DEX_NEGATIVE_BOX_MARKER].visibility = false; frame.marker[DEX_POSITIVE_BOX_MARKER].visibility = false; } else { frame.marker[DEX_NEGATIVE_BOX_MARKER].visibility = true; frame.marker[DEX_POSITIVE_BOX_MARKER].visibility = true; } // Map mouse coordinates to world coordinates. The factors used here are empirical. y = (double) ( mouse_position.y - rect.top ) / (double) ( rect.bottom - rect.top ); z = (double) (mouse_position.x - rect.right) / (double) ( rect.left - rect.right ); x = 0.0; // By default, the orientation of the manipulandum is the nominal orientation. CopyQuaternion( Q, nominalQ ); // Simulate wobbly movements of the manipulandum. This has not really been tested. if ( IsDlgButtonChecked( dlg, IDC_CODA_WOBBLY ) ) { // We will make the manipulandum rotate in a strange way as a function of the distance from 0. // This is just so that we can test the routines that compute the manipulandum position and orientation. double theta = y * 45.0; double gamma = - z * 45.0; SetQuaterniond( Ry, theta, iVector ); SetQuaterniond( Rz, gamma, jVector ); MultiplyQuaternions( midQ, Rz, nominalQ ); MultiplyQuaternions( Q, Ry, midQ ); // Make the movement a little bit in X as well so that we test the routines in 3D. x = 0.0 + 5.0 * sin( y / 80.0); } // Map screen position of the mouse pointer to 3D position of the wrist and manipulandum. // Top of the screen corresponds to the bottom of the bar and vice versa. It's inverted to protect the right hand rule. // Right of the screen correponds to the nearest horizontal target and left corresponds to the farthest. // The X position is set to be just to the right of the box. SubtractVectors( y_span, frame.marker[DEX_POSITIVE_BAR_MARKER].position, frame.marker[DEX_NEGATIVE_BAR_MARKER].position ); SubtractVectors( x_dir, frame.marker[DEX_POSITIVE_BOX_MARKER].position, frame.marker[DEX_NEGATIVE_BOX_MARKER].position ); NormalizeVector( x_dir ); ComputeCrossProduct( z_span, x_dir, y_span ); ScaleVector( y_displacement, y_span, y ); ScaleVector( z_displacement, z_span, z ); ScaleVector( x_displacement, x_dir, x ); // Reference position is the bottom target on the vertical target bar. CopyVector( position, frame.marker[DEX_NEGATIVE_BAR_MARKER].position ); // Place the manipulandum to the right of the box, even if the target bar is in the left position. position[X] = frame.marker[DEX_NEGATIVE_BOX_MARKER].position[X]; // Shift the position in X if the is any wobble to it. AddVectors( position, position, x_displacement ); // Shift the position in Y and Z according to the displacements computed from the mouse position. AddVectors( position, position, y_displacement ); AddVectors( position, position, z_displacement ); frame.time = DexTimerElapsedTime( acquisitionTimer ); // Displace the manipulandum with the mouse and make it rotate. for ( mrk = 0; mrk < nManipulandumMarkers; mrk++ ) { id = ManipulandumMarkerID[mrk]; RotateVector( rotated, Q, ManipulandumBody[mrk] ); AddVectors( frame.marker[id].position, position, rotated ); frame.marker[id].visibility = true; } // Displace the wrist with the mouse, but don't rotate it. for ( mrk = 0; mrk < nWristMarkers; mrk++ ) { id = WristMarkerID[mrk]; AddVectors( frame.marker[id].position, position, WristBody[mrk] ); frame.marker[id].visibility = true; } // Output the position and orientation used to compute the simulated // marker positions. This is for testing only. fprintf( fp, "%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\n", frame.time, position[X], position[Y], position[Z], Q[X], Q[Y], Q[Z], Q[M] ); return( true ); }
void drawGLScene(void) { int i, j; float TmpShade; MATRIX TmpMatrix; VECTOR TmpVector, TmpNormal; glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity (); if (True == outlineSmooth) { glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); glEnable (GL_LINE_SMOOTH); } else glDisable (GL_LINE_SMOOTH); glTranslatef (0.0f, 0.0f, -2.0f); glRotatef (modelAngle, 0.0f, 1.0f, 0.0f); glGetFloatv (GL_MODELVIEW_MATRIX, TmpMatrix.Data); glEnable (GL_TEXTURE_1D); glBindTexture (GL_TEXTURE_1D, shaderTexture[0]); glColor3f (1.0f, 1.0f, 1.0f); glBegin (GL_TRIANGLES); for (i = 0; i < polyNum; i++) { for (j = 0; j < 3; j++) { TmpNormal.X = polyData[i].Verts[j].Nor.X; TmpNormal.Y = polyData[i].Verts[j].Nor.Y; TmpNormal.Z = polyData[i].Verts[j].Nor.Z; RotateVector (&TmpMatrix, &TmpNormal, &TmpVector); Normalize (&TmpVector); TmpShade = DotProduct (&TmpVector,&lightAngle); if (TmpShade < 0.0f) TmpShade = 0.0f; glTexCoord1f (TmpShade); glVertex3fv (&polyData[i].Verts[j].Pos.X); } } glEnd (); glDisable (GL_TEXTURE_1D); if (True == outlineDraw) { glEnable (GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glPolygonMode (GL_BACK, GL_LINE); glLineWidth (outlineWidth); glCullFace (GL_FRONT); glDepthFunc (GL_LEQUAL); glColor3fv (&outlineColor[0]); glBegin (GL_TRIANGLES); for (i = 0; i < polyNum; i++) { for (j = 0; j < 3; j++) { glVertex3fv (&polyData[i].Verts[j].Pos.X); } } glEnd (); glDepthFunc (GL_LESS); glCullFace (GL_BACK); glPolygonMode (GL_BACK, GL_FILL); glDisable (GL_BLEND); } }
dVector dMatrix::TransformPlane (const dVector & localPlane) const { dVector tmp (RotateVector (localPlane)); tmp.m_w = localPlane.m_w - (localPlane % UnrotateVector (m_posit)); return tmp; }
HRESULT CRotate2DTool::RotateSelectedObjects( float flDeltaX ) { HRESULT hr = S_OK; CRotateObject * pCTrans = NULL; BOOL bHandled = FALSE; static DWORD dwTime = - 1; DWORD dwTimeNow; CComBSTR bstr1, bstr2, bstr3; CString tmpStr; D3DVECTOR vec; int i; if (IsPressed('S')) { flDeltaX *= SLOWKEY_SLOWFACTOR; } m_fDeltaTotal += flDeltaX; for( POSITION pos = m_TransformList.GetHeadPosition(); pos != NULL; ) { bHandled = TRUE; pCTrans = m_TransformList.GetNext( pos ); if(NULL != pCTrans) { for (i = 0; i < pCTrans->m_nPoints; i++) { vec.x = pCTrans->m_pPoints[i].x; vec.y = 0.0f; vec.z = pCTrans->m_pPoints[i].y; RotateVector(m_fDeltaTotal, &vec); vec.x += pCTrans->m_fCenter.x; vec.z += pCTrans->m_fCenter.y; hr = pCTrans->m_pVWFrame->InverseTransform(AXIS_Y, &vec.x, &vec.y, &vec.z, vec.x, vec.y, vec.z); if(FAILED( hr )) goto EXIT_FAIL; hr = pCTrans->m_pBoundary->SetVertexXY(i, vec.x, vec.z); if(FAILED( hr )) goto EXIT_FAIL; } InvokeToolEvent(TOOLEVENT_BOUNDARYUPDATE, pCTrans->m_pBoundary, bstrNULL, bstrNULL, bstrNULL, VARIANT_FALSE); dwTimeNow = GetTickCount(); if (dwTimeNow - dwTime > 200) { tmpStr.Format("%0.3f", m_fDeltaTotal / PI * 180.0f); bstr1 = tmpStr; tmpStr = ""; bstr2 = tmpStr; bstr3 = tmpStr; InvokeToolEvent(TOOLEVENT_2DOBJECTROTATED, pCTrans->m_pPickData, bstr1, bstr2, bstr3, VARIANT_TRUE); dwTime = dwTimeNow; } } } EXIT_FAIL: return hr; }
bool NtlGetDestination(float fCurrentHeadingVectorX, float fCurrentHeadingVectorZ, float fSpeedInSecs, float fCurrentPositionX, float fCurrentPositionY, float fCurrentPositionZ, float fDestinationX, float fDestinationY, float fDestinationZ, BYTE byMoveDirection, DWORD dwDeltaTimeInMillisecs, float fAttackDistance, float* pfNewHeadingVectorX, float* pfNewHeadingVectorZ, float* pfDestinationX, float* pfDestinationY, float* pfDestinationZ, float fTurningSpeedRatio) { if (0 == fCurrentHeadingVectorX && 0 == fCurrentHeadingVectorZ) return false; *pfNewHeadingVectorX = fCurrentHeadingVectorX; *pfNewHeadingVectorZ = fCurrentHeadingVectorZ; *pfDestinationX = fCurrentPositionX; *pfDestinationY = fCurrentPositionY; *pfDestinationZ = fCurrentPositionZ; float fDistanceInTick = fSpeedInSecs * (float)dwDeltaTimeInMillisecs / 1000.0f; switch (byMoveDirection) { case NTL_MOVE_NONE : break; case NTL_MOVE_F : case NTL_MOVE_B : // DON'T delete these lines permanently! // 완전히 삭제하지 마시오! // by YOSHIKI(2006-09-22) // case NTL_MOVE_L : // case NTL_MOVE_R : // case NTL_MOVE_F_L : // case NTL_MOVE_F_R : // case NTL_MOVE_B_L : // case NTL_MOVE_B_R : { float fMovementVectorX = 0.0f; float fMovementVectorZ = 0.0f; if (NTL_MOVE_F == byMoveDirection) { fMovementVectorX = fCurrentHeadingVectorX; fMovementVectorZ = fCurrentHeadingVectorZ; } else if (NTL_MOVE_B == byMoveDirection) { RotateVector180Degree(fCurrentHeadingVectorX, fCurrentHeadingVectorZ, &fMovementVectorX, &fMovementVectorZ); } // DON'T delete these lines permanently! // 완전히 삭제하지 마시오! // by YOSHIKI(2006-09-22) /* else if (NTL_MOVE_L == byMoveDirection) { RotateVector90DegreeToLeft(fCurrentHeadingVectorX, fCurrentHeadingVectorZ, &fMovementVectorX, &fMovementVectorZ); } else if (NTL_MOVE_R == byMoveDirection) { RotateVector90DegreeToRight(fCurrentHeadingVectorX, fCurrentHeadingVectorZ, &fMovementVectorX, &fMovementVectorZ); } else if (NTL_MOVE_F_L == byMoveDirection) { RotateVector45DegreeToLeft(fCurrentHeadingVectorX, fCurrentHeadingVectorZ, &fMovementVectorX, &fMovementVectorZ); } else if (NTL_MOVE_F_R == byMoveDirection) { RotateVector45DegreeToRight(fCurrentHeadingVectorX, fCurrentHeadingVectorZ, &fMovementVectorX, &fMovementVectorZ); } else if (NTL_MOVE_B_L == byMoveDirection) { RotateVector135DegreeToLeft(fCurrentHeadingVectorX, fCurrentHeadingVectorZ, &fMovementVectorX, &fMovementVectorZ); } else if (NTL_MOVE_B_R == byMoveDirection) { RotateVector135DegreeToRight(fCurrentHeadingVectorX, fCurrentHeadingVectorZ, &fMovementVectorX, &fMovementVectorZ); }*/ float fSin = 0.0f; float fCos = 0.0f; if (false == NtlSin(fMovementVectorX, fMovementVectorZ, &fSin)) return true; if (false == NtlCos(fMovementVectorX, fMovementVectorZ, &fCos)) return true; float fDeltaX = fDistanceInTick * fCos; float fDeltaZ = fDistanceInTick * fSin; *pfDestinationX = fCurrentPositionX + fDeltaX; *pfDestinationZ = fCurrentPositionZ + fDeltaZ; } break; case NTL_MOVE_TURN_L : case NTL_MOVE_TURN_R : case NTL_MOVE_F_TURN_L : case NTL_MOVE_F_TURN_R : case NTL_MOVE_B_TURN_L : case NTL_MOVE_B_TURN_R : { float fRadian = 2 * NTL_PI * ((float)dwDeltaTimeInMillisecs / (float)NTL_REQUIRED_TIME_FOR_COMPLETE_CIRCULAR_MOVEMENT_IN_MILLISECS); fRadian *= fTurningSpeedRatio; if (NTL_MOVE_TURN_L == byMoveDirection || NTL_MOVE_F_TURN_L == byMoveDirection || NTL_MOVE_B_TURN_L == byMoveDirection) { RotateVector(fCurrentHeadingVectorX, fCurrentHeadingVectorZ, fRadian, pfNewHeadingVectorX, pfNewHeadingVectorZ); } else if (NTL_MOVE_TURN_R == byMoveDirection || NTL_MOVE_F_TURN_R == byMoveDirection || NTL_MOVE_B_TURN_R == byMoveDirection) { RotateVector(fCurrentHeadingVectorX, fCurrentHeadingVectorZ, -fRadian, pfNewHeadingVectorX, pfNewHeadingVectorZ); } if (NTL_MOVE_TURN_L == byMoveDirection || NTL_MOVE_TURN_R == byMoveDirection) { // The position doesn't change. } else if (NTL_MOVE_F_TURN_L == byMoveDirection || NTL_MOVE_F_TURN_R == byMoveDirection || NTL_MOVE_B_TURN_L == byMoveDirection || NTL_MOVE_B_TURN_R == byMoveDirection) { float fRadius = 0.0f; fRadius = fSpeedInSecs * ((float)NTL_REQUIRED_TIME_FOR_COMPLETE_CIRCULAR_MOVEMENT_IN_MILLISECS / (float)1000) / (2 * NTL_PI); float fTempX = fCurrentHeadingVectorX * fRadius / sqrt(fCurrentHeadingVectorX * fCurrentHeadingVectorX + fCurrentHeadingVectorZ * fCurrentHeadingVectorZ); float fTempZ = fCurrentHeadingVectorZ * fRadius / sqrt(fCurrentHeadingVectorX * fCurrentHeadingVectorX + fCurrentHeadingVectorZ * fCurrentHeadingVectorZ); if (NTL_MOVE_F_TURN_L == byMoveDirection) { *pfDestinationX = fCurrentPositionX + fTempX * sin(fRadian) + fTempZ * (1 - cos(fRadian)); *pfDestinationZ = fCurrentPositionZ + fTempZ * sin(fRadian) - fTempX * (1 - cos(fRadian)); } else if (NTL_MOVE_F_TURN_R == byMoveDirection) { *pfDestinationX = fCurrentPositionX + fTempX * sin(fRadian) - fTempZ * (1 - cos(fRadian)); *pfDestinationZ = fCurrentPositionZ + fTempZ * sin(fRadian) - fTempX * (1 - cos(fRadian)); } else if (NTL_MOVE_B_TURN_L == byMoveDirection) { *pfDestinationX = fCurrentPositionX - fTempX * sin(fRadian) - fTempZ * (1 - cos(fRadian)); *pfDestinationZ = fCurrentPositionZ - fTempZ * sin(fRadian) - fTempX * (1 - cos(fRadian)); } else if (NTL_MOVE_B_TURN_R == byMoveDirection) { *pfDestinationX = fCurrentPositionX - fTempX * sin(fRadian) + fTempZ * (1 - cos(fRadian)); *pfDestinationZ = fCurrentPositionZ - fTempZ * sin(fRadian) - fTempX * (1 - cos(fRadian)); } } } break; case NTL_MOVE_MOUSE_MOVEMENT : { float fDeltaX = fDestinationX - fCurrentPositionX; float fDeltaZ = fDestinationZ - fCurrentPositionZ; // [6/21/2006 zeroera] : 수정 : float 비교 오차 범위 if ( ( fabs( fDeltaX ) < 0.001f ) && ( fabs( fDeltaZ ) < 0.001f ) ) { *pfNewHeadingVectorX = fCurrentHeadingVectorX; *pfNewHeadingVectorZ = fCurrentHeadingVectorZ; *pfDestinationX = fDestinationX; *pfDestinationY = fDestinationY; *pfDestinationZ = fDestinationZ; return true; } CNtlVector vDelta(fDeltaX, 0, fDeltaZ); float fDeltaLength = vDelta.Length(); vDelta.Normalize(fDeltaLength); *pfNewHeadingVectorX = vDelta.x; *pfNewHeadingVectorZ = vDelta.z; if (fDeltaLength <= fDistanceInTick) { *pfDestinationX = fDestinationX; *pfDestinationY = fDestinationY; *pfDestinationZ = fDestinationZ; } else { vDelta *= fDistanceInTick; *pfDestinationX = fCurrentPositionX + vDelta.x; *pfDestinationY = fCurrentPositionY + (fDestinationY - fCurrentPositionY) * fDistanceInTick / fDeltaLength; *pfDestinationZ = fCurrentPositionZ + vDelta.z; } } break; case NTL_MOVE_FOLLOW_MOVEMENT : { float fDeltaX = fDestinationX - fCurrentPositionX; float fDeltaZ = fDestinationZ - fCurrentPositionZ; // [6/21/2006 zeroera] : 수정 : float 비교 오차 범위 if ( ( fabs( fDeltaX ) < 0.001f ) && ( fabs( fDeltaZ ) < 0.001f ) ) { *pfNewHeadingVectorX = fCurrentHeadingVectorX; *pfNewHeadingVectorZ = fCurrentHeadingVectorZ; *pfDestinationX = fCurrentPositionX; *pfDestinationY = fCurrentPositionY; *pfDestinationZ = fCurrentPositionZ; return true; } CNtlVector vDelta(fDeltaX, 0, fDeltaZ); float fDeltaLength = vDelta.Length(); vDelta.Normalize(fDeltaLength); *pfNewHeadingVectorX = vDelta.x; *pfNewHeadingVectorZ = vDelta.z; if ( fDeltaLength <= fAttackDistance ) { *pfDestinationX = fCurrentPositionX; *pfDestinationY = fCurrentPositionY; *pfDestinationZ = fCurrentPositionZ; } else if ( fDeltaLength > fAttackDistance && fDeltaLength < fAttackDistance + fDistanceInTick) { vDelta *= ( fDeltaLength - fAttackDistance * 0.99f ); *pfDestinationX = fCurrentPositionX + vDelta.x; *pfDestinationY = fCurrentPositionY + (fDestinationY - fCurrentPositionY) * (fDeltaLength - fAttackDistance * 0.99f) / fDeltaLength; *pfDestinationY = fDestinationY; *pfDestinationZ = fCurrentPositionZ + vDelta.z; } else { vDelta *= fDistanceInTick; *pfDestinationX = fCurrentPositionX + vDelta.x; *pfDestinationY = fCurrentPositionY + (fDestinationY - fCurrentPositionY) * fDistanceInTick / fDeltaLength; *pfDestinationZ = fCurrentPositionZ + vDelta.z; } } break; default : return false; break; } return true; }
void Renderer::ProtoRender(int flags) { /// // std::vector<unsigned int> tmp_Indices; // for (unsigned int i = 0; i < m_Indices.size(); i += 6) // { // tmp_Indices.push_back( m_Indices[ i + 0 ] ); // tmp_Indices.push_back( m_Indices[ i + 1 ] ); // tmp_Indices.push_back( m_Indices[ i + 2 ] ); // } // m_Indices = tmp_Indices; /// if ( flags & eCellShading_texture1D || flags & eCellShading_color ) { sf::Vector3f lightAngle(0,0,1); // Normalize( lightAngle ); float tmp_matrix[16]; glGetFloatv( GL_MODELVIEW_MATRIX, tmp_matrix ); m_sec_Vertices.clear(); m_sec_Normales.clear(); m_sec_TexCoords.clear(); m_sec_Colors.clear(); m_sec_TexCoords1D.clear(); for (unsigned int i = 0; i < m_Indices.size(); ++i) // for (unsigned int i = 0; i < m_Indices2.size(); ++i) { #define D_IDX m_Indices[i] // #define D_IDX m_Indices2[i] m_sec_Vertices.push_back( m_Vertices[ D_IDX ] ); if ( flags & eNormal ) m_sec_Normales.push_back( m_Normales[ D_IDX ] ); if ( flags & eTexture ) m_sec_TexCoords.push_back( m_TexCoords[ D_IDX ] ); { sf::Vector3f tmp_vector; RotateVector( tmp_matrix, m_Normales[ D_IDX ], tmp_vector ); Normalize( tmp_vector ); float tmp_shade = DotProduct( tmp_vector, lightAngle ); if (tmp_shade < 0.0f) tmp_shade = 0.0f; if ( flags & eCellShading_texture1D ) m_sec_TexCoords1D.push_back( tmp_shade ); if ( flags & eCellShading_color ) m_sec_Colors.push_back( sf::Vector3f(tmp_shade, tmp_shade, tmp_shade) ); } #undef D_IDX } // for (unsigned int i = 0; i < m_Indices.size(); ++i) } { { glEnableClientState( GL_VERTEX_ARRAY ); if ( flags & eCellShading_texture1D || flags & eCellShading_color ) glVertexPointer( 3, GL_FLOAT, 0, &(m_sec_Vertices[0].x) ); else glVertexPointer( 3, GL_FLOAT, 0, &(m_Vertices[0].x) ); } if ( flags & eNormal ) { glEnableClientState( GL_NORMAL_ARRAY ); glEnable(GL_LIGHTING); if ( flags & eCellShading_texture1D || flags & eCellShading_color ) glNormalPointer( GL_FLOAT, 0, &(m_sec_Normales[0].x) ); else glNormalPointer( GL_FLOAT, 0, &(m_Normales[0].x) ); } else glDisable(GL_LIGHTING); if ( flags & eCellShading_color ) { glEnableClientState( GL_COLOR_ARRAY ); glColorPointer( 3, GL_FLOAT, 0, &(m_sec_Colors[0].x) ); } if ( flags & eCellShading_texture1D ) { glClientActiveTexture(GL_TEXTURE1); glActiveTextureARB(GL_TEXTURE1_ARB); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnable(GL_TEXTURE_1D); m_Tex1D.Bind(); glTexCoordPointer( 1, GL_FLOAT, 0, &(m_sec_TexCoords1D[0]) ); } if ( flags & eTexture ) { glClientActiveTexture(GL_TEXTURE0); glActiveTextureARB(GL_TEXTURE0_ARB); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnable(GL_TEXTURE_2D); sf::Texture::bind( m_pTexture ); m_pTexture->setSmooth(false); if ( flags & eCellShading_texture1D || flags & eCellShading_color ) glTexCoordPointer( 2, GL_FLOAT, 0, &(m_sec_TexCoords[0].x) ); else glTexCoordPointer( 2, GL_FLOAT, 0, &(m_TexCoords[0].x) ); } if ( flags & eCellShading_texture1D || flags & eCellShading_color ) glDrawArrays( GL_TRIANGLES, 0, m_sec_Vertices.size() ); else glDrawElements( GL_TRIANGLES, m_Indices.size(), GL_UNSIGNED_INT, &(m_Indices[0]) ); // glDrawElements( GL_TRIANGLES, m_Indices2.size(), GL_UNSIGNED_INT, &(m_Indices2[0]) ); { glDisableClientState( GL_VERTEX_ARRAY ); if ( flags & eNormal ) glDisableClientState( GL_NORMAL_ARRAY ); if ( flags & eCellShading_color ) glDisableClientState( GL_COLOR_ARRAY ); if ( flags & eCellShading_texture1D ) { glClientActiveTexture(GL_TEXTURE1); glActiveTexture(GL_TEXTURE1); glDisable(GL_TEXTURE_1D); glDisableClientState( GL_TEXTURE_COORD_ARRAY ); } glClientActiveTexture( GL_TEXTURE0 ); glActiveTexture(GL_TEXTURE0); if ( flags & eTexture ) { glDisable(GL_TEXTURE_2D); glDisableClientState( GL_TEXTURE_COORD_ARRAY ); } } } if ( flags & eCellShading_bound ) { { glDisable(GL_LIGHTING); glEnable(GL_CULL_FACE); glColor3ub(0,0,0); { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // glCullFace(GL_BACK); glCullFace(GL_FRONT); } glDepthFunc (GL_LEQUAL); glLineWidth(3.0f); } glEnableClientState( GL_VERTEX_ARRAY ); glVertexPointer( 3, GL_FLOAT, 0, &(m_Vertices[0].x) ); glDrawElements( GL_TRIANGLES, m_Indices.size(), GL_UNSIGNED_INT, &(m_Indices[0]) ); // glDrawElements( GL_TRIANGLES, m_Indices2.size(), // GL_UNSIGNED_INT, &(m_Indices2[0]) ); glDisableClientState( GL_VERTEX_ARRAY ); { glLineWidth(1.0f); glDepthFunc(GL_LESS); glCullFace(GL_BACK); { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } glDisable(GL_CULL_FACE); } } // if ( flags & eCellShading_bound ) /** { glColor3f(1,0,1); glPointSize(10); glEnableClientState( GL_VERTEX_ARRAY ); glVertexPointer( 3, GL_FLOAT, 0, &(m_Vertices[0].x) ); glDrawArrays( GL_POINTS, 0, m_Vertices.size() ); glDisableClientState( GL_VERTEX_ARRAY ); } //*/ /** { m_sec_Vertices.clear(); for (unsigned int i = 0; i < m_Vertices.size(); ++i) { m_sec_Vertices.push_back( m_Vertices[ i ] ); m_sec_Vertices.push_back( m_Vertices[ i ] + m_Normales[ i ] ); } glColor3f(1,0,1); // glPointSize(10); glEnableClientState( GL_VERTEX_ARRAY ); glVertexPointer( 3, GL_FLOAT, 0, &(m_sec_Vertices[0].x) ); glDrawArrays( GL_LINES, 0, m_sec_Vertices.size() ); glDisableClientState( GL_VERTEX_ARRAY ); } //*/ }
void AddDecalToHModel(VECTORCH *normalPtr, VECTORCH *positionPtr, SECTION_DATA *sectionDataPtr) { enum DECAL_ID decalID; OBJECT_DECAL *decalPtr; MATRIXCH orientation; VECTORCH v; int decalSize; int theta,sin,cos; if (!LocalDetailLevels.DrawHierarchicalDecals) return; theta = FastRandom()&4095; sin = GetSin(theta); cos = GetCos(theta); LOCALASSERT(sectionDataPtr->NumberOfDecals <= MAX_NO_OF_DECALS_PER_HIERARCHICAL_SECTION); { MATRIXCH mat = sectionDataPtr->SecMat; VECTORCH n = *normalPtr; TransposeMatrixCH(&mat); RotateVector(&n,&mat); MakeMatrixFromDirection(&n,&orientation); v = *positionPtr; v.vx -= sectionDataPtr->World_Offset.vx; v.vy -= sectionDataPtr->World_Offset.vy; v.vz -= sectionDataPtr->World_Offset.vz; RotateVector(&v,&mat); } { SECTION *sectionPtr = sectionDataPtr->sempai; if(sectionPtr->flags§ion_sprays_blood) { decalID = DECAL_HUMAN_BLOOD; } else if(sectionPtr->flags§ion_sprays_predoblood) { decalID = DECAL_PREDATOR_BLOOD; } else if(sectionPtr->flags§ion_sprays_acid) { decalID = DECAL_ALIEN_BLOOD; } else { decalID = DECAL_BULLETHOLE; } } decalPtr = §ionDataPtr->Decals[sectionDataPtr->NextDecalToUse]; if (sectionDataPtr->NextDecalToUse >= MAX_NO_OF_DECALS_PER_HIERARCHICAL_SECTION-1) { sectionDataPtr->NextDecalToUse = 0; } else { sectionDataPtr->NextDecalToUse++; } if (sectionDataPtr->NumberOfDecals < MAX_NO_OF_DECALS_PER_HIERARCHICAL_SECTION) { sectionDataPtr->NumberOfDecals++; } decalPtr->DecalID = decalID; decalSize = 40;//DecalDescription[decalID].MaxSize; decalPtr->Centre = v; decalPtr->Vertices[0].vx = MUL_FIXED(-decalSize,cos) - MUL_FIXED(-decalSize,sin); decalPtr->Vertices[0].vy = MUL_FIXED(-decalSize,sin) + MUL_FIXED(-decalSize,cos); decalPtr->Vertices[0].vz = DECAL_Z_OFFSET; RotateVector(&(decalPtr->Vertices[0]),&orientation); decalPtr->Vertices[0].vx += v.vx; decalPtr->Vertices[0].vy += v.vy; decalPtr->Vertices[0].vz += v.vz; decalPtr->Vertices[1].vx = MUL_FIXED(decalSize,cos) - MUL_FIXED(-decalSize,sin); decalPtr->Vertices[1].vy = MUL_FIXED(decalSize,sin) + MUL_FIXED(-decalSize,cos); decalPtr->Vertices[1].vz = DECAL_Z_OFFSET; RotateVector(&(decalPtr->Vertices[1]),&orientation); decalPtr->Vertices[1].vx += v.vx; decalPtr->Vertices[1].vy += v.vy; decalPtr->Vertices[1].vz += v.vz; decalPtr->Vertices[2].vx = MUL_FIXED(decalSize,cos) - MUL_FIXED(decalSize,sin); decalPtr->Vertices[2].vy = MUL_FIXED(decalSize,sin) + MUL_FIXED(decalSize,cos); decalPtr->Vertices[2].vz = DECAL_Z_OFFSET; RotateVector(&(decalPtr->Vertices[2]),&orientation); decalPtr->Vertices[2].vx += v.vx; decalPtr->Vertices[2].vy += v.vy; decalPtr->Vertices[2].vz += v.vz; decalPtr->Vertices[3].vx = MUL_FIXED(-decalSize,cos) - MUL_FIXED(decalSize,sin); decalPtr->Vertices[3].vy = MUL_FIXED(-decalSize,sin) + MUL_FIXED(decalSize,cos); decalPtr->Vertices[3].vz = DECAL_Z_OFFSET; RotateVector(&(decalPtr->Vertices[3]),&orientation); decalPtr->Vertices[3].vx += v.vx; decalPtr->Vertices[3].vy += v.vy; decalPtr->Vertices[3].vz += v.vz; }
void AddDecal(enum DECAL_ID decalID, VECTORCH *normalPtr, VECTORCH *positionPtr, int moduleIndex) { DECAL *decalPtr; MATRIXCH orientation; int decalSize; int theta = FastRandom()&4095; int sin = GetSin(theta); int cos = GetCos(theta); MakeMatrixFromDirection(normalPtr,&orientation); if (decalID == DECAL_BULLETHOLE) { MakeImpactSmoke(&orientation,positionPtr); } decalPtr = AllocateDecal(); decalPtr->DecalID = decalID; decalPtr->Centre = *positionPtr; if(DecalDescription[decalID].GrowthRate) { decalSize = ONE_FIXED; decalPtr->Direction[0].vx = MUL_FIXED(-decalSize,cos) - MUL_FIXED(-decalSize,sin); decalPtr->Direction[0].vy = MUL_FIXED(-decalSize,sin) + MUL_FIXED(-decalSize,cos); decalPtr->Direction[0].vz = DECAL_Z_OFFSET; RotateVector(&(decalPtr->Direction[0]),&orientation); Normalise(&(decalPtr->Direction[0])); decalPtr->Direction[1].vx = MUL_FIXED(decalSize,cos) - MUL_FIXED(-decalSize,sin); decalPtr->Direction[1].vy = MUL_FIXED(decalSize,sin) + MUL_FIXED(-decalSize,cos); decalPtr->Direction[1].vz = DECAL_Z_OFFSET; RotateVector(&(decalPtr->Direction[1]),&orientation); Normalise(&(decalPtr->Direction[1])); decalPtr->Direction[2].vx = MUL_FIXED(decalSize,cos) - MUL_FIXED(decalSize,sin); decalPtr->Direction[2].vy = MUL_FIXED(decalSize,sin) + MUL_FIXED(decalSize,cos); decalPtr->Direction[2].vz = DECAL_Z_OFFSET; RotateVector(&(decalPtr->Direction[2]),&orientation); Normalise(&(decalPtr->Direction[2])); decalPtr->Direction[3].vx = MUL_FIXED(-decalSize,cos) - MUL_FIXED(decalSize,sin); decalPtr->Direction[3].vy = MUL_FIXED(-decalSize,sin) + MUL_FIXED(decalSize,cos); decalPtr->Direction[3].vz = DECAL_Z_OFFSET; RotateVector(&(decalPtr->Direction[3]),&orientation); Normalise(&(decalPtr->Direction[3])); decalPtr->CurrentSize = DecalDescription[decalID].MinSize; decalPtr->TargetSize = DecalDescription[decalID].MaxSize; if (DecalDescription[decalID].CanCombine) decalPtr->TargetSize/=4; } else { decalSize = DecalDescription[decalID].MinSize; decalPtr->Vertices[0].vx = MUL_FIXED(-decalSize,cos) - MUL_FIXED(-decalSize,sin); decalPtr->Vertices[0].vy = MUL_FIXED(-decalSize,sin) + MUL_FIXED(-decalSize,cos); decalPtr->Vertices[0].vz = DECAL_Z_OFFSET; RotateVector(&(decalPtr->Vertices[0]),&orientation); decalPtr->Vertices[0].vx += positionPtr->vx; decalPtr->Vertices[0].vy += positionPtr->vy; decalPtr->Vertices[0].vz += positionPtr->vz; decalPtr->Vertices[1].vx = MUL_FIXED(decalSize,cos) - MUL_FIXED(-decalSize,sin); decalPtr->Vertices[1].vy = MUL_FIXED(decalSize,sin) + MUL_FIXED(-decalSize,cos); decalPtr->Vertices[1].vz = DECAL_Z_OFFSET; RotateVector(&(decalPtr->Vertices[1]),&orientation); decalPtr->Vertices[1].vx += positionPtr->vx; decalPtr->Vertices[1].vy += positionPtr->vy; decalPtr->Vertices[1].vz += positionPtr->vz; decalPtr->Vertices[2].vx = MUL_FIXED(decalSize,cos) - MUL_FIXED(decalSize,sin); decalPtr->Vertices[2].vy = MUL_FIXED(decalSize,sin) + MUL_FIXED(decalSize,cos); decalPtr->Vertices[2].vz = DECAL_Z_OFFSET; RotateVector(&(decalPtr->Vertices[2]),&orientation); decalPtr->Vertices[2].vx += positionPtr->vx; decalPtr->Vertices[2].vy += positionPtr->vy; decalPtr->Vertices[2].vz += positionPtr->vz; decalPtr->Vertices[3].vx = MUL_FIXED(-decalSize,cos) - MUL_FIXED(decalSize,sin); decalPtr->Vertices[3].vy = MUL_FIXED(-decalSize,sin) + MUL_FIXED(decalSize,cos); decalPtr->Vertices[3].vz = DECAL_Z_OFFSET; RotateVector(&(decalPtr->Vertices[3]),&orientation); decalPtr->Vertices[3].vx += positionPtr->vx; decalPtr->Vertices[3].vy += positionPtr->vy; decalPtr->Vertices[3].vz += positionPtr->vz; } decalPtr->ModuleIndex = moduleIndex; switch (decalID) { case DECAL_HUMAN_BLOOD: case DECAL_PREDATOR_BLOOD: case DECAL_ANDROID_BLOOD: { decalPtr->UOffset = (FastRandom()&1)*(32<<16); if (normalPtr->vy<-32768) { decalPtr->UOffset+=64<<16; } else { decalPtr->TargetSize = DecalDescription[decalID].MaxSize; decalPtr->CurrentSize = decalPtr->TargetSize-1; } break; } default: { decalPtr->UOffset = 0; break; } } }
//Baking //using all rotations scales positions etc, generates the list of triangles that //is represented by the rendered shapes. //similar to instance baking. //remember that this function needed to always reflect what render() does but inverted. void B9SupportStructure::BakeToInstanceGeometry() { unsigned int t; unsigned short int v; Triangle3D* pNewTri; QVector3D topScale; QVector3D topPos; QVector3D midScale; QVector3D midPos; QVector3D bottomScale; QVector3D bottomPos; //first bake the top topScale = QVector3D(topRadius*2.0,topRadius*2.0,topLength + topPenetration); topPos = QVector3D((topPenetrationPoint.x() + topPivot.x())*0.5 ,(topPenetrationPoint.y() + topPivot.y())*0.5 ,(topPenetrationPoint.z() + topPivot.z())*0.5); if(topAttachShape != NULL) for(t = 0; t < topAttachShape->GetTriangles()->size(); t++) { pNewTri = new Triangle3D(topAttachShape->GetTriangles()->at(t)); for(v=0;v<3;v++) { //scale triangle vertices 1st pNewTri->vertex[v] *= topScale; //Rotate 2nd //dont deal with y - not needed in rendering or baking RotateVector(pNewTri->vertex[v], topThetaX, QVector3D(1,0,0));//x RotateVector(pNewTri->vertex[v], topThetaZ, QVector3D(0,0,1));//z //Translate 3rd into global space pNewTri->vertex[v] += topPos; pNewTri->vertex[v] += instanceParent->GetPos(); } //Update the triangle bounds and normal pNewTri->UpdateBounds(); pNewTri->UpdateNormalFromGeom(); //Add To List instanceParent->triList.push_back(pNewTri); } //second bake the middle midScale = QVector3D(midRadius*2.0,midRadius*2.0,midLength); midPos = QVector3D((topMidExtensionPoint.x() + bottomMidExtensionPoint.x())*0.5 ,(topMidExtensionPoint.y() + bottomMidExtensionPoint.y())*0.5 ,(topMidExtensionPoint.z() + bottomMidExtensionPoint.z())*0.5); if(midAttachShape != NULL) for(t = 0; t < midAttachShape->GetTriangles()->size(); t++) { pNewTri = new Triangle3D(midAttachShape->GetTriangles()->at(t)); for(v=0;v<3;v++) { //scale triangle vertices 1st pNewTri->vertex[v] *= midScale; //Rotate 2nd //dont deal with y - not needed in rendering or baking RotateVector(pNewTri->vertex[v], midThetaX, QVector3D(1,0,0));//x RotateVector(pNewTri->vertex[v], midThetaZ, QVector3D(0,0,1));//z //Translate 3rd into global space pNewTri->vertex[v] += midPos; pNewTri->vertex[v] += instanceParent->GetPos(); } //Update the triangle bounds and normal pNewTri->UpdateBounds(); pNewTri->UpdateNormalFromGeom(); //Add To List instanceParent->triList.push_back(pNewTri); } //third bake the bottom bottomScale = QVector3D(bottomRadius*2.0,bottomRadius*2.0,bottomLength + bottomPenetration); bottomPos = QVector3D((bottomPenetrationPoint.x() + bottomPivot.x())*0.5 ,(bottomPenetrationPoint.y() + bottomPivot.y())*0.5 ,(bottomPenetrationPoint.z() + bottomPivot.z())*0.5); if(bottomAttachShape != NULL) for(t = 0; t < bottomAttachShape->GetTriangles()->size(); t++) { pNewTri = new Triangle3D(bottomAttachShape->GetTriangles()->at(t)); for(v=0;v<3;v++) { //scale triangle vertices 1st pNewTri->vertex[v] *= bottomScale; //Rotate 2nd //dont deal with y - not needed in rendering or baking RotateVector(pNewTri->vertex[v], bottomThetaX+180, QVector3D(1,0,0));//x RotateVector(pNewTri->vertex[v], bottomThetaZ, QVector3D(0,0,1));//z //Translate 3rd into global space pNewTri->vertex[v] += bottomPos; pNewTri->vertex[v] += instanceParent->GetPos(); } //Update the triangle bounds and normal pNewTri->UpdateBounds(); pNewTri->UpdateNormalFromGeom(); //Add To List instanceParent->triList.push_back(pNewTri); } }
VOID CDrawingObject::Translate(FLOAT fdx, FLOAT fdy, BOOL bInertia) { m_fdX = fdx; m_fdY = fdy; FLOAT fOffset[2]; fOffset[0] = m_fOX - m_fdX; fOffset[1] = m_fOY - m_fdY; // Translate based on the offset caused by rotating // and scaling in order to vary rotational behavior depending // on where the manipulation started if(m_fAngleApplied != 0.0f) { FLOAT v1[2]; v1[0] = GetCenterX() - fOffset[0]; v1[1] = GetCenterY() - fOffset[1]; FLOAT v2[2]; RotateVector(v1, v2, m_fAngleApplied); m_fdX += v2[0] - v1[0]; m_fdY += v2[1] - v1[1]; } if(m_fFactor != 1.0f) { FLOAT v1[2]; v1[0] = GetCenterX() - fOffset[0]; v1[1] = GetCenterY() - fOffset[1]; FLOAT v2[2]; v2[0] = v1[0] * m_fFactor; v2[1] = v1[1] * m_fFactor; m_fdX += v2[0] - v1[0]; m_fdY += v2[1] - v1[1]; } m_fXI += m_fdX; m_fYI += m_fdY; // The following code handles the effect for // bouncing off the edge of the screen. It takes // the x,y coordinates computed by the inertia processor // and calculates the appropriate render coordinates // in order to achieve the effect. if (bInertia) { ComputeElasticPoint(m_fXI, &m_fXR, m_iBorderX); ComputeElasticPoint(m_fYI, &m_fYR, m_iBorderY); } else { m_fXR = m_fXI; m_fYR = m_fYI; // Make sure it stays on screen EnsureVisible(); } }
BOOL CShockWaveEffect::Process(FLOAT time) { FLOAT fDeltaTime, fProcessedTime; BOOL bRet, bRender; if(!PreProcess(time, bRet, bRender, fDeltaTime, fProcessedTime)) { if(!bRender) SetNotRenderAtThisFrame(); return bRet; } //color 정보 FLOAT fadeVal = this->GetFadeValue(fProcessedTime); if(fadeVal == 1.0f && m_bColorWhite) { //nothing } else { m_vectorGFXColor.clear(); m_vectorGFXColor.reserve(m_iSplitCount*2); UBYTE ubColElement = UBYTE(255.0f * fadeVal); GFXColor col; if( m_eBlendType == PBT_BLEND || m_eBlendType == PBT_ADDALPHA ) { col = 0xFFFFFF00 | ubColElement; //fade by alpha } else if( m_eBlendType == PBT_ADD ) { col = (ubColElement << 24) | (ubColElement << 16) | (ubColElement << 8) | 0x000000FF; //fade by color } else col = 0xFFFFFFFF; //fade 의미 없음. for(INDEX i=0; i<m_iSplitCount; ++i) { m_vectorGFXColor.push_back(col); m_vectorGFXColor.push_back(col); } } //wave 정보 m_ssHeight.Prepare(); FLOAT3D height(0, m_ssHeight.Value(fProcessedTime), 0); FLOAT radiusInner = 0, radiusOuter = 0; m_ssRadius.Prepare(); m_ssWidth.Prepare(); if(m_bInnerBasis) { radiusInner = m_ssRadius.Value(fProcessedTime); radiusOuter = radiusInner + m_ssWidth.Value(fProcessedTime); } else { radiusOuter = m_ssRadius.Value(fProcessedTime); radiusInner = radiusOuter - m_ssWidth.Value(fProcessedTime); } //tag의 정보 if(m_ePosition == EOTT_ALWAYS) m_vTagPos = m_ptrAttachTag->CurrentTagInfo().m_vPos; if(m_eRotation == EOTT_ALWAYS) m_qTagRot = m_ptrAttachTag->CurrentTagInfo().m_qRot; //gfx vertex fill, every frame GFXVertex vtx; FLOAT3D pos; const FLOAT angleUnit = 2 * PI / m_iSplitCount; FLOAT angle = 0; INDEX index = 0; m_vectorGFXVertex.clear(); m_vectorGFXColor.reserve(m_iSplitCount*2); for(INDEX i=0; i<m_iSplitCount; ++i) { index = 2*i+0; pos = m_vectorMoveVector[index] * radiusOuter + height; RotateVector(pos, m_qTagRot); pos += m_vTagPos; vtx.x = pos(1); vtx.y = pos(2); vtx.z = pos(3); m_vectorGFXVertex.push_back(vtx); ++index; pos = m_vectorMoveVector[index] * radiusInner; RotateVector(pos, m_qTagRot); pos += m_vTagPos; vtx.x = pos(1); vtx.y = pos(2); vtx.z = pos(3); m_vectorGFXVertex.push_back(vtx); angle += angleUnit; } PostProcess(); return TRUE; }
/* The main drawing function. */ void DrawGLScene() { int i, j; // Looping Variables float TmpShade; // Temporary Shader Value MATRIX TmpMatrix; // Temporary MATRIX Structure VECTOR TmpVector, TmpNormal; // Temporary VECTOR Structures glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Buffers glLoadIdentity (); // Reset The Matrix // Check To See If We Want Anti-Aliased Lines if (outlineSmooth) { glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); // Use The Good Calculations glEnable (GL_LINE_SMOOTH); // Enable Anti-Aliasing } else { // We Don't Want Smooth Lines // Disable Anti-Aliasing glDisable (GL_LINE_SMOOTH); } // Move 2 Units Away From The Screen glTranslatef (0.0f, 0.0f, -2.0f); // Rotate The Model On It's Y-Axis glRotatef (modelAngle, 0.0f, 1.0f, 0.0f); InitGL(800, 600); // Get The Generated Matrix glGetFloatv(GL_MODELVIEW_MATRIX, TmpMatrix.Data); // Cel-Shading Code // // Enable 1D Texturing glDisable (GL_TEXTURE_3D); glDisable (GL_TEXTURE_2D); glEnable (GL_TEXTURE_1D); // Bind to current texture glBindTexture (GL_TEXTURE_1D, shaderTexture[0]); // Set colour of model glColor3f (0.0, 0.0, 0.0); glBegin (GL_TRIANGLES); for (i = 0; i < polyNum; i++) { for (j = 0; j < 3; j++) { TmpNormal.X = polyData[i].Verts[j].Nor.X; // Fill Up The TmpNormal Structure With TmpNormal.Y = polyData[i].Verts[j].Nor.Y; // The Current Vertices' Normal Values TmpNormal.Z = polyData[i].Verts[j].Nor.Z; RotateVector (TmpMatrix, TmpNormal, TmpVector); // Rotate This By The Matrix Normalize (TmpVector); // Normalize The New Normal TmpShade = DotProduct (TmpVector, lightAngle); // Calculate The Shade Value if (TmpShade < 0.0f) TmpShade = 0.0f; // Clamp The Value to 0 If Negative glTexCoord1f (TmpShade); // Set The Texture Co-ordinate As The Shade Value glVertex3fv(&polyData[i].Verts[j].Pos.X); // Send The Vertex Position } } glEnd(); glDisable (GL_TEXTURE_1D); // Disable 1D Textures // Outline Code // // Check To See If We Want To Draw The Outline if (outlineDraw) { glEnable (GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPolygonMode (GL_BACK, GL_LINE); // Draw Backfacing Polygons As Wireframes glLineWidth (outlineWidth); // Set The Line Width glCullFace (GL_FRONT); // Don't Draw Any Front-Facing Polygons glDepthFunc (GL_LEQUAL); // Change The Depth Mode glColor3fv (&outlineColor[0]); // Set The Outline Color glBegin (GL_TRIANGLES); for (i = 0; i < polyNum; i++) { for (j = 0; j < 3; j++) { glVertex3fv (&polyData[i].Verts[j].Pos.X); // Send The Vertex Position } } glEnd(); glDepthFunc (GL_LESS); // Reset The Depth-Testing Mode glCullFace (GL_BACK); // Reset The Face To Be Culled glPolygonMode (GL_BACK, GL_FILL); // Reset Back-Facing Polygon Drawing Mode glDisable (GL_BLEND); // Disable Blending } // since this is double buffered, swap the buffers to display what just got drawn. //glutSwapBuffers(); // Check To See If Rotation Is Enabled if (modelRotate) { modelAngle += 2.0f; } }
void CBody::AdjustPitch(float radianAngle) { D3DXVECTOR3 right = RotateVector(D3DXVECTOR3(1.0f, 0.0f, 0.0f)); AdjustAxisAngle(right, radianAngle); }
dVector dMatrix::TransformVector (const dVector & v) const { return m_posit + RotateVector (v); }
GLvoid NEHE37::DrawGLScene(){ float TmpShade; MATRIX37 TmpMatrix; VECTOR37 TmpVector, TmpNormal; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); // Check To See If We Want Anti-Aliased Lines if(outlineSmooth){ glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); glEnable (GL_LINE_SMOOTH); } else{ glDisable (GL_LINE_SMOOTH); } glTranslatef (0.0f, 0.0f, -2.0f); glRotatef (modelAngle, 0.0f, 1.0f, 0.0f); glGetFloatv (GL_MODELVIEW_MATRIX, TmpMatrix.Data); // Cel-Shading Code glEnable (GL_TEXTURE_1D); glBindTexture (GL_TEXTURE_1D, shaderTexture[0]); glColor3f (1.0f, 1.0f, 1.0f); glBegin (GL_TRIANGLES); for (int i = 0; i < polyNum; i++){ for (int j = 0; j < 3; j++){ TmpNormal.X = polyData[i].Verts[j].Nor.X; TmpNormal.Y = polyData[i].Verts[j].Nor.Y; TmpNormal.Z = polyData[i].Verts[j].Nor.Z; RotateVector (TmpMatrix, TmpNormal, TmpVector); Normalize (TmpVector); TmpShade = DotProduct (TmpVector, lightAngle); if (TmpShade < 0.0f) TmpShade = 0.0f; glTexCoord1f (TmpShade); glVertex3fv (&polyData[i].Verts[j].Pos.X); } } glEnd (); glDisable (GL_TEXTURE_1D); // Outline Code if (outlineDraw){ glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA ,GL_ONE_MINUS_SRC_ALPHA); glPolygonMode (GL_BACK, GL_LINE); glLineWidth (outlineWidth); glCullFace (GL_FRONT); glDepthFunc (GL_LEQUAL); glColor3fv (&outlineColor[0]); glBegin (GL_TRIANGLES); for (int i = 0; i < polyNum; i++){ for (int j = 0; j < 3; j++){ glVertex3fv (&polyData[i].Verts[j].Pos.X); } } glEnd (); glDepthFunc (GL_LESS); glCullFace (GL_BACK); glPolygonMode (GL_BACK, GL_FILL); glDisable (GL_BLEND); } /* //draw FPS text glDisable(GL_TEXTURE_2D); glLoadIdentity (); glTranslatef(0.0f,0.0f,-1.0f); glColor3f(0.8f,0.8f,0.8f);//set text color computeFPS(); Utils::drawText(-0.54f,-0.4f, GLUT_BITMAP_HELVETICA_12, FPSstr); glEnable(GL_TEXTURE_2D); */ glutSwapBuffers(); //handle key input if(specialKeys[GLUT_KEY_DOWN]){ outlineWidth--; specialKeys[GLUT_KEY_DOWN] = FALSE; } if(specialKeys[GLUT_KEY_UP]){ outlineWidth++; specialKeys[GLUT_KEY_UP] = FALSE; } if(keys[' ']){ modelRotate = !modelRotate; // Toggle Model Rotation On/Off keys[' '] = false; } if(keys['1']){ outlineDraw = !outlineDraw; // Toggle Outline Drawing On/Off keys['1'] = false; } if(keys['2']){ outlineSmooth = !outlineSmooth; // Toggle Anti-Aliasing On/Off keys['2'] = false; } if (modelRotate) modelAngle += 1.0f; }
/* cambia angolo di ROLL (rollio) */ void Camera::roll(GLfloat angle) { up = Normalize(RotateVector(angle,view,up)); }
void RubiksCube::Grab(VECTOR touchVector) { tvf32[0]+=floattof32(touchVector.X); tvf32[1]+=floattof32(touchVector.Y); tvf32[2]=0; if(f32toint(sqrtf32(mulf32(tvf32[0],tvf32[0])+mulf32(tvf32[1],tvf32[1])+mulf32(tvf32[2],tvf32[2])))>5) { VECTOR upv, rightv, rotduv, rotdrv; int32 uvf32[3];//up vector as f32 int32 rvf32[3];//right vector int32 magup, magright; m4x4 grabMatrix;//container for the Position Matrix vectorFromSide(upv, rightv, clicked[0]); //printf ("Initial Vector:\n %f, ", tmpv.X); //printf("%f, ", tmpv.Y); //printf("%f\n", tmpv.Z); glGetFixed(GL_GET_MATRIX_POSITION, (int32*)&grabMatrix); glMatrixMode(GL_MODELVIEW); //rotate the up vector thru the projection matrix //and cast it to f32 RotateVector(grabMatrix, upv, rotduv); uvf32[0]=floattof32(rotduv.X); uvf32[1]=floattof32(rotduv.Y); uvf32[2]=floattof32(rotduv.Z); //rinse and repeat with the right vector RotateVector(grabMatrix, rightv, rotdrv); rvf32[0]=floattof32(rotdrv.X); rvf32[1]=floattof32(rotdrv.Y); rvf32[2]=floattof32(rotdrv.Z); if(controlStyle) { int32 suvf32[3]; int32 srvf32[3]; suvf32[0]=0; suvf32[1]=inttof32(1); suvf32[2]=0; srvf32[0]=inttof32(1); srvf32[1]=0; srvf32[2]=0; magup=dotf32(uvf32, suvf32); magright=dotf32(uvf32, srvf32); if(abs(magup)>abs(magright)) { for(int i=0; i<3; i++) { if(magup>0) { rvf32[i]=srvf32[i]; uvf32[i]=suvf32[i]; } else { rvf32[i]=-srvf32[i]; uvf32[i]=-suvf32[i]; } } } else { for(int i=0; i<3; i++) { if(magright>0) { uvf32[i]=srvf32[i]; rvf32[i]=-suvf32[i]; } else { uvf32[i]=-srvf32[i]; rvf32[i]=suvf32[i]; } } } } magup=dotf32(uvf32, tvf32); magright=dotf32(rvf32, tvf32); if(magup || magright) { int32 tmp[2]; if(abs(magup)>abs(magright)) { tmp[0]=uvf32[0]; tmp[1]=uvf32[1]; unitVector((int32*)tmp); InitTwist(true, tmp); }else{ tmp[0]=rvf32[0]; tmp[1]=rvf32[1]; unitVector((int32*)tmp); InitTwist(false, tmp); } Twisting=true; Grabbing=false; tvf32[0]=0; tvf32[1]=0; } } }
double * IntegratorMulti1D::Getqaccel() { RotateVector(Q, zaccel, qaccel); return qaccel; }