bool BuildAxesFromNormal( const Vector &vNormal, Vector &vHorz, Vector &vVert ) { vHorz.Init(); vVert.Init(); // find the major axis float bestMin = 99999; int bestAxis = -1; for (int i=0 ; i<3; i++) { float a = fabs(vNormal[i]); if (a < bestMin) { bestAxis = i; bestMin = a; } } if (bestAxis==-1) return false; vHorz[bestAxis] = 1; CrossProduct( vNormal,vHorz,vVert); CrossProduct( vNormal,vVert,vHorz); VectorNormalize( vHorz ); VectorNormalize( vVert ); return true; }
//----------------------------------------------------------------------------- // Computes the spheremap color at a particular (x,y) texcoord //----------------------------------------------------------------------------- static void CalcSphereColor( SphereCalc_t *pCalc, float x, float y ) { Vector normal; float flRadiusSq = x*x + y*y; if (flRadiusSq > pCalc->m_flRadiusSq) { // Force a glancing reflection normal.Init( 0, 1, 0 ); } else { // Compute the z distance based on x*x + y*y + z*z = r*r float z = sqrt( pCalc->m_flRadiusSq - flRadiusSq ); // Here's the untransformed surface normal normal.Init( x, y, z ); normal *= pCalc->m_flOORadius; } // Transform the normal based on the actual view direction TransformNormal( pCalc, normal ); // Compute the reflection vector (full spheremap solution) // R = 2 * (N dot L)N - L Vector vecReflect; float nDotL = DotProduct( normal, pCalc->m_vecLookDir ); VectorMA( pCalc->m_vecLookDir, -2.0f * nDotL, normal, vecReflect ); vecReflect *= -1.0f; int iFace = CalcFaceIndex( vecReflect ); CalcColor( pCalc, iFace, vecReflect, pCalc->m_pColor ); }
static cell_t smn_TRTraceRay(IPluginContext *pContext, const cell_t *params) { cell_t *startaddr, *endaddr; pContext->LocalToPhysAddr(params[1], &startaddr); pContext->LocalToPhysAddr(params[2], &endaddr); g_StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2])); switch (params[4]) { case RayType_EndPoint: { g_EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); break; } case RayType_Infinite: { g_DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); AngleVectors(g_DirAngles, &g_EndVec); /* Make it unitary and get the ending point */ g_EndVec.NormalizeInPlace(); g_EndVec = g_StartVec + g_EndVec * MAX_TRACE_LENGTH; break; } } g_Ray.Init(g_StartVec, g_EndVec); enginetrace->TraceRay(g_Ray, params[3], &g_HitAllFilter, &g_Trace); g_Trace.UpdateEntRef(); return 1; }
static cell_t smn_TRTraceHullFilter(IPluginContext *pContext, const cell_t *params) { cell_t data; IPluginFunction *pFunc; cell_t *startaddr, *endaddr, *mins, *maxs; pFunc = pContext->GetFunctionById(params[6]); if (!pFunc) { return pContext->ThrowNativeError("Invalid function id (%X)", params[5]); } data = params[7]; g_SMTraceFilter.SetFunctionPtr(pFunc, data); pContext->LocalToPhysAddr(params[1], &startaddr); pContext->LocalToPhysAddr(params[2], &endaddr); pContext->LocalToPhysAddr(params[3], &mins); pContext->LocalToPhysAddr(params[4], &maxs); g_StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2])); g_HullMins.Init(sp_ctof(mins[0]), sp_ctof(mins[1]), sp_ctof(mins[2])); g_HullMaxs.Init(sp_ctof(maxs[0]), sp_ctof(maxs[1]), sp_ctof(maxs[2])); g_EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); g_Ray.Init(g_StartVec, g_EndVec, g_HullMins, g_HullMaxs); enginetrace->TraceRay(g_Ray, params[5], &g_SMTraceFilter, &g_Trace); g_Trace.UpdateEntRef(); return 1; }
void C_WeaponSpawner::UpdateGlowEffect() { if ( !m_pGlowEffect ) { m_pGlowEffect = new CGlowObject( this, Vector( 0.6f, 0.6f, 1.0f ), 1.0f, true, true ); } if ( !m_bShouldGlow ) { m_pGlowEffect->SetAlpha( 0.0f ); } else { Vector vecColor; if ( m_bTouchingPlayer ) { // White glow. vecColor.Init( 0.76f, 0.76f, 0.76f ); } else { // Blue glow. vecColor.Init( 0.6f, 0.6f, 1.0f ); } m_pGlowEffect->SetColor( vecColor ); m_pGlowEffect->SetAlpha( 1.0f ); } }
int C_BeamQuadratic::DrawModel( int ) { Vector points[3]; QAngle tmpAngle; if ( !m_active ) return 0; C_BaseEntity *pEnt = cl_entitylist->GetEnt( m_viewModelIndex ); if ( !pEnt ) return 0; pEnt->GetAttachment( 1, points[0], tmpAngle ); points[1] = 0.5 * (m_targetPosition + points[0]); // a little noise 11t & 13t should be somewhat non-periodic looking //points[1].z += 4*sin( gpGlobals->curtime*11 ) + 5*cos( gpGlobals->curtime*13 ); points[2] = m_worldPosition; IMaterial *pMat = materials->FindMaterial( "sprites/physbeam", TEXTURE_GROUP_CLIENT_EFFECTS ); Vector color; if ( m_glueTouching ) { color.Init(1,0,0); } else { color.Init(1,1,1); } float scrollOffset = gpGlobals->curtime - (int)gpGlobals->curtime; materials->Bind( pMat ); DrawBeamQuadratic( points[0], points[1], points[2], 13, color, scrollOffset ); return 1; }
//----------------------------------------------------------------------------- // Purpose: Returns the bounds relative to the origin (render bounds) //----------------------------------------------------------------------------- void C_HopwireExplosion::GetRenderBounds( Vector& mins, Vector& maxs ) { float scale = m_FXCoreScale.Interp( gpGlobals->curtime ); mins.Init( -scale, -scale, -scale ); maxs.Init( scale, scale, scale ); }
void CParticleEffectBinding::BBoxCalcStart( bool bFullBBoxUpdate, Vector &bbMin, Vector &bbMax ) { if ( !GetAutoUpdateBBox() ) return; if ( bFullBBoxUpdate ) { // We're going to fully recompute the bbox. bbMin.Init( FLT_MAX, FLT_MAX, FLT_MAX ); bbMax.Init( -FLT_MAX, -FLT_MAX, -FLT_MAX ); } else { // We're going to push out the bbox using just some of the particles. if ( m_bLocalSpaceTransformIdentity ) { bbMin = m_Min; bbMax = m_Max; } else { ITransformAABB( m_LocalSpaceTransform.As3x4(), m_Min, m_Max, bbMin, bbMax ); } } }
void CModelInfo::GetModelRenderBounds( const model_t *model, int sequence, Vector& mins, Vector& maxs ) const { if (!model) { mins.Init(0,0,0); maxs.Init(0,0,0); return; } switch( model->type ) { case mod_studio: { studiohdr_t *pStudioHdr = ( studiohdr_t * )modelloader->GetExtraData( (model_t*)model ); Assert( pStudioHdr ); // NOTE: We're not looking at the sequence box here, although we could if (!VectorCompare( vec3_origin, pStudioHdr->view_bbmin )) { // clipping bounding box VectorCopy ( pStudioHdr->view_bbmin, mins); VectorCopy ( pStudioHdr->view_bbmin, maxs); } else { // movement bounding box VectorCopy ( pStudioHdr->hull_min, mins); VectorCopy ( pStudioHdr->hull_max, maxs); } // construct the base bounding box for this frame if ( sequence >= pStudioHdr->numseq) { sequence = 0; } mstudioseqdesc_t *pseqdesc = pStudioHdr->pSeqdesc( sequence ); VectorMin( pseqdesc->bbmin, mins, mins ); VectorMax( pseqdesc->bbmax, maxs, maxs ); } break; case mod_brush: VectorCopy( model->mins, mins ); VectorCopy( model->maxs, maxs ); break; default: mins.Init( 0, 0, 0 ); maxs.Init( 0, 0, 0 ); break; } }
static cell_t smn_TRTraceRayFilter(IPluginContext *pContext, const cell_t *params) { cell_t *startaddr, *endaddr; IPluginFunction *pFunc; cell_t data; pFunc = pContext->GetFunctionById(params[5]); if (!pFunc) { return pContext->ThrowNativeError("Invalid function id (%X)", params[5]); } if (params[0] >= 6) { data = params[6]; } else { data = 0; } g_SMTraceFilter.SetFunctionPtr(pFunc, data); pContext->LocalToPhysAddr(params[1], &startaddr); pContext->LocalToPhysAddr(params[2], &endaddr); g_StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2])); switch (params[4]) { case RayType_EndPoint: { g_EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); break; } case RayType_Infinite: { g_DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); AngleVectors(g_DirAngles, &g_EndVec); /* Make it unitary and get the ending point */ g_EndVec.NormalizeInPlace(); g_EndVec = g_StartVec + g_EndVec * MAX_TRACE_LENGTH; break; } } g_Ray.Init(g_StartVec, g_EndVec); enginetrace->TraceRay(g_Ray, params[3], &g_SMTraceFilter, &g_Trace); g_Trace.UpdateEntRef(); return 1; }
void CNeeded::Normalize(Vector &vIn, Vector &vOut) { float flLen = vIn.Length(); if(flLen == 0) { vOut.Init(0, 0, 1); return; } flLen = 1 / flLen; vOut.Init(vIn.x * flLen, vIn.y * flLen, vIn.z * flLen); }
void CTETFParticleEffect::Init( void ) { m_vecOrigin.Init(); m_vecStart.Init(); m_vecAngles.Init(); m_iParticleSystemIndex = 0; m_nEntIndex = -1; m_iAttachType = PATTACH_ABSORIGIN; m_iAttachmentPointIndex = 0; m_bResetParticles = false; }
//----------------------------------------------------------------------------- // Computes the reflectivity //----------------------------------------------------------------------------- void CVTFTexture::ComputeReflectivity( ) { Assert( m_Format == IMAGE_FORMAT_RGBA8888 ); int divisor = 0; m_vecReflectivity.Init( 0.0f, 0.0f, 0.0f ); for( int iFrame = 0; iFrame < m_nFrameCount; ++iFrame ) { for( int iFace = 0; iFace < m_nFaceCount; ++iFace ) { Vector vecFaceReflect; unsigned char* pSrc = ImageData( iFrame, iFace, 0 ); int nNumPixels = m_nWidth * m_nHeight; VectorClear( vecFaceReflect ); for (int i = 0; i < nNumPixels; ++i, pSrc += 4 ) { vecFaceReflect[0] += TextureToLinear( pSrc[0] ); vecFaceReflect[1] += TextureToLinear( pSrc[1] ); vecFaceReflect[2] += TextureToLinear( pSrc[2] ); } vecFaceReflect /= nNumPixels; m_vecReflectivity += vecFaceReflect; ++divisor; } } m_vecReflectivity /= divisor; }
//----------------------------------------------------------------------------- // Computes ambient lighting along a specified ray. //----------------------------------------------------------------------------- void CalcRayAmbientLighting( const Vector &vStart, const Vector &vEnd, Vector color[MAX_LIGHTSTYLES], Vector &colorSum ) { Ray_t ray; ray.Init( vStart, vEnd, vec3_origin, vec3_origin ); directlight_t *pSkyLight = FindAmbientSkyLight(); colorSum.Init(); CLightSurface surfEnum; if (!surfEnum.FindIntersection( ray )) return; // This is the faster path; it looks slightly different though if (surfEnum.m_pSurface->dispinfo == -1) { ComputeLightmapColorFromAverage( surfEnum.m_pSurface, pSkyLight, color, colorSum ); } else { ComputeLightmapColorDisplacement( surfEnum.m_pSurface, pSkyLight, surfEnum.m_LuxelCoord, color, colorSum ); } }
//----------------------------------------------------------------------------- // Purpose: Hack to allow this code to run on a client that's not connected to a server // (i.e., demo playback, or multiplayer game ) // Input : ent_num - // origin - // mins - // maxs - // Output : static void //----------------------------------------------------------------------------- static bool GetEntityOriginClientOrServer( int ent_num, Vector& origin ) { // Assume failure origin.Init(); if ( sv.active ) { edict_t *e = EDICT_NUM( ent_num ); if ( e ) { IServerEntity *serverEntity = e->GetIServerEntity(); if ( serverEntity ) { CM_WorldSpaceCenter( serverEntity->GetCollideable(), &origin ); } return true; } } else { IClientEntity *clent = entitylist->GetClientEntity( ent_num ); if ( clent ) { CM_WorldSpaceCenter( clent->GetClientCollideable(), &origin ); return true; } } return false; }
IMotionEvent::simresult_e CGrabController::Simulate( IPhysicsMotionController *pController, IPhysicsObject *pObject, float deltaTime, Vector &linear, AngularImpulse &angular ) { game_shadowcontrol_params_t shadowParams = m_shadow; if ( InContactWithHeavyObject( pObject, GetLoadWeight() ) ) { m_contactAmount = Approach( 0.1f, m_contactAmount, deltaTime*2.0f ); } else { m_contactAmount = Approach( 1.0f, m_contactAmount, deltaTime*2.0f ); } shadowParams.maxAngular = m_shadow.maxAngular * m_contactAmount * m_contactAmount * m_contactAmount; m_timeToArrive = pObject->ComputeShadowControl( shadowParams, m_timeToArrive, deltaTime ); // Slide along the current contact points to fix bouncing problems Vector velocity; AngularImpulse angVel; pObject->GetVelocity( &velocity, &angVel ); PhysComputeSlideDirection( pObject, velocity, angVel, &velocity, &angVel, GetLoadWeight() ); pObject->SetVelocityInstantaneous( &velocity, NULL ); linear.Init(); angular.Init(); m_errorTime += deltaTime; return SIM_LOCAL_ACCELERATION; }
IMotionEvent::simresult_e CGrabController::Simulate( IPhysicsMotionController *pController, IPhysicsObject *pObject, float deltaTime, Vector &linear, AngularImpulse &angular ) { m_timeToArrive = pObject->ComputeShadowControl( m_shadow, m_timeToArrive, deltaTime ); linear.Init(); angular.Init(); m_errorTime += deltaTime; return SIM_LOCAL_ACCELERATION; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void ExpandBBox(Vector &vecMins, Vector &vecMaxs) { // expand for *any* rotation float maxval = 0; for (int i = 0; i < 3; i++) { float v = fabs( vecMins[i]); if (v > maxval) maxval = v; v = fabs( vecMaxs[i]); if (v > maxval) maxval = v; } vecMins.Init(-maxval, -maxval, -maxval); vecMaxs.Init(maxval, maxval, maxval); }
void DrawSmokeFogOverlay() { if(g_SmokeFogOverlayAlpha == 0 || !g_pSmokeFogMaterial || !materials) return; // Hard-coded for now.. g_SmokeFogOverlayColor.Init( 0.3, 0.3, 0.3 ); CMatRenderContextPtr pRenderContext( materials ); pRenderContext->MatrixMode( MATERIAL_PROJECTION ); pRenderContext->LoadIdentity(); pRenderContext->Ortho( 0, 0, 1, 1, -99999, 99999 ); pRenderContext->MatrixMode( MATERIAL_VIEW ); pRenderContext->LoadIdentity(); pRenderContext->MatrixMode( MATERIAL_MODEL ); pRenderContext->LoadIdentity(); IMesh* pMesh = pRenderContext->GetDynamicMesh( false, NULL, NULL, g_pSmokeFogMaterial ); CMeshBuilder meshBuilder; static float dist = 10; Vector vColor = g_SmokeFogOverlayColor; vColor.x = MIN(MAX(vColor.x, 0), 1); vColor.y = MIN(MAX(vColor.y, 0), 1); vColor.z = MIN(MAX(vColor.z, 0), 1); float alpha = MIN(MAX(g_SmokeFogOverlayAlpha, 0), 1); meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 ); meshBuilder.Position3f( 0, 0, dist ); meshBuilder.Color4f( vColor.x, vColor.y, vColor.z, alpha ); meshBuilder.TexCoord2f( 0, 0.0f, 0.0f ); meshBuilder.AdvanceVertex(); meshBuilder.Position3f( 0, 1, dist ); meshBuilder.Color4f( vColor.x, vColor.y, vColor.z, alpha ); meshBuilder.TexCoord2f( 0, 0.0f, 0.0f ); meshBuilder.AdvanceVertex(); meshBuilder.Position3f( 1, 1, dist ); meshBuilder.Color4f( vColor.x, vColor.y, vColor.z, alpha ); meshBuilder.TexCoord2f( 0, 0.0f, 0.0f ); meshBuilder.AdvanceVertex(); meshBuilder.Position3f( 1, 0, dist ); meshBuilder.Color4f( vColor.x, vColor.y, vColor.z, alpha ); meshBuilder.TexCoord2f( 0, 0.0f, 0.0f ); meshBuilder.AdvanceVertex(); meshBuilder.End(); pMesh->Draw(); }
IMotionEvent::simresult_e CPhysicsNPCSolver::Simulate( IPhysicsMotionController *pController, IPhysicsObject *pObject, float deltaTime, Vector &linear, AngularImpulse &angular ) { if ( IsIntersecting() ) { const float PUSH_SPEED = 150.0f; if ( pObject->GetGameFlags() & FVPHYSICS_PLAYER_HELD ) { CBasePlayer *pPlayer = UTIL_GetLocalPlayer(); if ( pPlayer ) { pPlayer->ForceDropOfCarriedPhysObjects( m_hEntity ); } } ResetCancelTime(); angular.Init(); linear.Init(); // Don't push on vehicles because they won't move if ( pObject->GetGameFlags() & FVPHYSICS_MULTIOBJECT_ENTITY ) { if ( m_hEntity->GetServerVehicle() ) return SIM_NOTHING; } Vector origin, vel; pObject->GetPosition( &origin, NULL ); pObject->GetVelocity( &vel, NULL ); Vector dir = origin - m_hNPC->GetAbsOrigin(); dir.z = dir.z > 0 ? 0.1f : -0.1f; VectorNormalize(dir); AngularImpulse angVel; angVel.Init(); // NOTE: Iterate this object's contact points // if it can't move in this direction, try sliding along the plane/crease Vector pushImpulse; PhysComputeSlideDirection( pObject, dir * PUSH_SPEED, angVel, &pushImpulse, NULL, 0 ); dir = pushImpulse; VectorNormalize(dir); if ( DotProduct( vel, dir ) < PUSH_SPEED * 0.5f ) { linear = pushImpulse; if ( pObject->GetContactPoint(NULL,NULL) ) { linear.z += GetCurrentGravity(); } } return SIM_GLOBAL_ACCELERATION; } return SIM_NOTHING; }
void StudioModel::GetMovement( float prevcycle[5], Vector &vecPos, QAngle &vecAngles ) { vecPos.Init(); vecAngles.Init(); CStudioHdr *pStudioHdr = GetStudioHdr(); if ( !pStudioHdr ) return; // assume that changes < -0.5 are loops.... if (m_cycle - prevcycle[0] < -0.5) { prevcycle[0] = prevcycle[0] - 1.0; } Studio_SeqMovement( pStudioHdr, m_sequence, prevcycle[0], m_cycle, m_poseparameter, vecPos, vecAngles ); prevcycle[0] = m_cycle; int i; for (i = 0; i < 4; i++) { Vector vecTmp; QAngle angTmp; if (m_Layer[i].m_cycle - prevcycle[i+1] < -0.5) { prevcycle[i+1] = prevcycle[i+1] - 1.0; } if (m_Layer[i].m_weight > 0.0) { vecTmp.Init(); angTmp.Init(); if (Studio_SeqMovement( pStudioHdr, m_Layer[i].m_sequence, prevcycle[i+1], m_Layer[i].m_cycle, m_poseparameter, vecTmp, angTmp )) { vecPos = vecPos * ( 1.0 - m_Layer[i].m_weight ) + vecTmp * m_Layer[i].m_weight; } } prevcycle[i+1] = m_Layer[i].m_cycle; } return; }
static cell_t smn_TRTraceHull(IPluginContext *pContext, const cell_t *params) { cell_t *startaddr, *endaddr, *mins, *maxs; pContext->LocalToPhysAddr(params[1], &startaddr); pContext->LocalToPhysAddr(params[2], &endaddr); pContext->LocalToPhysAddr(params[3], &mins); pContext->LocalToPhysAddr(params[4], &maxs); g_StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2])); g_HullMins.Init(sp_ctof(mins[0]), sp_ctof(mins[1]), sp_ctof(mins[2])); g_HullMaxs.Init(sp_ctof(maxs[0]), sp_ctof(maxs[1]), sp_ctof(maxs[2])); g_EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); g_Ray.Init(g_StartVec, g_EndVec, g_HullMins, g_HullMaxs); enginetrace->TraceRay(g_Ray, params[5], &g_HitAllFilter, &g_Trace); g_Trace.UpdateEntRef(); return 1; }
void CAI_Spotlight::UpdateSpotlightDirection( void ) { if ( !m_hSpotlight ) { CreateSpotlightEntities(); } // Compute the current beam direction Vector vTargetDir; VectorSubtract( m_vSpotlightTargetPos, m_hSpotlight->GetAbsStartPos(), vTargetDir ); VectorNormalize(vTargetDir); ConstrainToCone( &vTargetDir ); // Compute the amount to rotate float flDot = DotProduct( vTargetDir, m_vSpotlightDir ); flDot = clamp( flDot, -1.0f, 1.0f ); float flAngle = AngleNormalize( RAD2DEG( acos( flDot ) ) ); float flClampedAngle = clamp( flAngle, 0.0f, 45.0f ); float flBeamTurnRate = SimpleSplineRemapVal( flClampedAngle, 0.0f, 45.0f, 10.0f, 45.0f ); if ( fabs(flAngle) > flBeamTurnRate * gpGlobals->frametime ) { flAngle = flBeamTurnRate * gpGlobals->frametime; } // Compute the rotation axis Vector vecRotationAxis; CrossProduct( m_vSpotlightDir, vTargetDir, vecRotationAxis ); if ( VectorNormalize( vecRotationAxis ) < 1e-3 ) { vecRotationAxis.Init( 0, 0, 1 ); } // Compute the actual rotation amount, using quat slerp blending Quaternion desiredQuat, resultQuat; AxisAngleQuaternion( vecRotationAxis, flAngle, desiredQuat ); QuaternionSlerp( m_vAngularVelocity, desiredQuat, QUAT_BLEND_FACTOR, resultQuat ); m_vAngularVelocity = resultQuat; // If we're really close, and we're not moving very quickly, slam. float flActualRotation = AngleNormalize( RAD2DEG(2 * acos(m_vAngularVelocity.w)) ); if (( flActualRotation < 1e-3 ) && (flAngle < 1e-3 )) { m_vSpotlightDir = vTargetDir; m_vAngularVelocity.Init( 0, 0, 0, 1 ); return; } // Update the desired direction matrix3x4_t rot; Vector vecNewDir; QuaternionMatrix( m_vAngularVelocity, rot ); VectorRotate( m_vSpotlightDir, rot, vecNewDir ); m_vSpotlightDir = vecNewDir; VectorNormalize(m_vSpotlightDir); }
virtual void GetSurfaceNormal( Vector &out ) { if ( m_pContact ) { ConvertDirectionToHL( m_pContact->surf_normal, out ); } else { out.Init(); } }
virtual void GetContactSpeed( Vector &out ) { if ( m_pContact ) { ConvertPositionToHL( m_pContact->speed, out ); } else { out.Init(); } }
void QuaternionAxisAngle( const IVP_U_Quat &q, Vector &axis, float &angle ) { angle = 2 * acos(q.w); if ( angle > M_PI ) { angle -= 2*M_PI; } axis.Init( q.x, q.y, q.z ); VectorNormalize( axis ); }
//----------------------------------------------------------------------------- // Gets the lighting + material color of a static prop //----------------------------------------------------------------------------- void CStaticPropMgr::GetStaticPropMaterialColorAndLighting( trace_t* pTrace, int staticPropIndex, Vector& lighting, Vector& matColor ) { #ifndef SWDS // Invalid static prop? Blow it off! if (staticPropIndex >= m_StaticProps.Size()) { lighting.Init( 0, 0, 0 ); matColor.Init( 1, 1, 1 ); return; } // Get the prop CStaticProp& prop = m_StaticProps[staticPropIndex]; // Ask the model info about what we need to know modelinfoclient->GetModelMaterialColorAndLighting( (model_t*)prop.GetModel(), prop.GetRenderOrigin(), prop.GetRenderAngles(), pTrace, lighting, matColor ); #endif }
//----------------------------------------------------------------------------- // Purpose: // GetLocalTime() is the objects local current time // Input : destTime - new time that is being moved to // moveTime - amount of time to be advanced this frame // Output : float - the actual amount of time to move (usually moveTime) //----------------------------------------------------------------------------- float CBaseMoveBehavior::SetObjectPhysicsVelocity( float moveTime ) { // make sure we have a valid set up if ( !m_pCurrentKeyFrame || !m_pTargetKeyFrame ) return moveTime; // if we're not moving, we're not moving if ( !IsMoving() ) return moveTime; float destTime = moveTime + GetLocalTime(); // work out where we want to be, using destTime m_flTimeIntoFrame = destTime - m_flAnimStartTime; float newTime = (destTime - m_flAnimStartTime) / (m_flAnimEndTime - m_flAnimStartTime); Vector newPos; QAngle newAngles; IPositionInterpolator *pInterp = GetPositionInterpolator( m_iPositionInterpolator ); if( pInterp ) { // setup key frames pInterp->SetKeyPosition( -1, m_pPreKeyFrame->m_Origin ); Motion_SetKeyAngles( -1, m_pPreKeyFrame->m_qAngle ); pInterp->SetKeyPosition( 0, m_pCurrentKeyFrame->m_Origin ); Motion_SetKeyAngles( 0, m_pCurrentKeyFrame->m_qAngle ); pInterp->SetKeyPosition( 1, m_pTargetKeyFrame->m_Origin ); Motion_SetKeyAngles( 1, m_pTargetKeyFrame->m_qAngle ); pInterp->SetKeyPosition( 2, m_pPostKeyFrame->m_Origin ); Motion_SetKeyAngles( 2, m_pPostKeyFrame->m_qAngle ); // find new interpolated position & rotation pInterp->InterpolatePosition( newTime, newPos ); } else { newPos.Init(); } Quaternion qRot; Motion_InterpolateRotation( newTime, m_iRotationInterpolator, qRot ); QuaternionAngles( qRot, newAngles ); // find our velocity vector (newPos - currentPos) and scale velocity vector according to the movetime float oneOnMoveTime = 1 / moveTime; SetAbsVelocity( (newPos - GetLocalOrigin()) * oneOnMoveTime ); SetLocalAngularVelocity( (newAngles - GetLocalAngles()) * oneOnMoveTime ); return moveTime; }
void HSV2RGB(float H, float s, float v, Vector &normalizedRGB) { int Hr = floor(H / 60.0f); float f = H / 60.0f - Hr; float p = v * (1.0f - s); float q = v * (1.0f - s * f); float t = v * (1.0f - s * (1.0f - f)); switch (Hr) { default: normalizedRGB.Init(v, t, p); break; case 1: normalizedRGB.Init(q, v, p); break; case 2: normalizedRGB.Init(p, v, t); break; case 3: normalizedRGB.Init(p, q, v); break; case 4: normalizedRGB.Init(t, p, v); break; case 5: normalizedRGB.Init(v, p, q); break; } }
virtual void BuildTransformations( CStudioHdr *hdr, Vector *pos, Quaternion q[], const matrix3x4_t& cameraTransform, int boneMask, CBoneBitList &boneComputed ) { VPROF_BUDGET( "C_ServerRagdollAttached::SetupBones", VPROF_BUDGETGROUP_CLIENT_ANIMATION ); if ( !hdr ) return; float frac = RemapVal( gpGlobals->curtime, m_parentTime, m_parentTime+ATTACH_INTERP_TIME, 0, 1 ); frac = clamp( frac, 0.f, 1.f ); // interpolate offset over some time Vector offset = m_vecOffset * (1-frac); C_BaseAnimating *parent = assert_cast< C_BaseAnimating* >( GetMoveParent() ); Vector worldOrigin; worldOrigin.Init(); if ( parent ) { Assert( parent != this ); parent->SetupBones( NULL, -1, BONE_USED_BY_ANYTHING, gpGlobals->curtime ); matrix3x4_t boneToWorld; parent->GetCachedBoneMatrix( m_boneIndexAttached, boneToWorld ); VectorTransform( m_attachmentPointBoneSpace, boneToWorld, worldOrigin ); } BaseClass::BuildTransformations( hdr, pos, q, cameraTransform, boneMask, boneComputed ); if ( parent ) { int index = m_boneIndex[m_ragdollAttachedObjectIndex]; const matrix3x4_t &matrix = GetBone( index ); Vector ragOrigin; VectorTransform( m_attachmentPointRagdollSpace, matrix, ragOrigin ); offset = worldOrigin - ragOrigin; // fixes culling SetAbsOrigin( worldOrigin ); m_vecOffset = offset; } for ( int i = 0; i < hdr->numbones(); i++ ) { if ( !( hdr->boneFlags( i ) & boneMask ) ) continue; Vector pos; matrix3x4_t &matrix = GetBoneForWrite( i ); MatrixGetColumn( matrix, 3, pos ); pos += offset; MatrixSetColumn( pos, 3, matrix ); } }