void VolumeBrush::UndoViscosityCalculation(ContainerPhysics* pCPStruct) { if (!pCPStruct) return; // Undo dampening... if (m_fViscosity > 0.0f) { VEC_DIVSCALAR(pCPStruct->m_Velocity, pCPStruct->m_Velocity, m_fViscosity); VEC_DIVSCALAR(pCPStruct->m_Acceleration, pCPStruct->m_Acceleration, m_fViscosity); } }
void Trigger::CreateBoundingBox() { CServerDE* pServerDE = GetServerDE(); if (!pServerDE) return; ObjectCreateStruct theStruct; INIT_OBJECTCREATESTRUCT(theStruct); DVector vPos; pServerDE->GetObjectPos(m_hObject, &vPos); VEC_COPY(theStruct.m_Pos, vPos); SAFE_STRCPY(theStruct.m_Filename, "Models\\Props\\1x1_square.abc"); // strcpy(theStruct.m_SkinName, "SpecialFX\\smoke.dtx"); theStruct.m_Flags = FLAG_VISIBLE; HCLASS hClass = pServerDE->GetClass("Model"); LPBASECLASS pModel = pServerDE->CreateObject(hClass, &theStruct); if (pModel) { m_hBoundingBox = pModel->m_hObject; DVector vDims; pServerDE->GetObjectDims(m_hObject, &vDims); DVector vScale; VEC_DIVSCALAR(vScale, vDims, 0.5f); pServerDE->ScaleObject(m_hBoundingBox, &vScale); } pServerDE->SetObjectColor(m_hBoundingBox, GetRandom(0.5f, 1.0f), GetRandom(0.5f, 1.0f), GetRandom(0.5f, 1.0f), 1.0f); }
void GameBase::CreateBoundingBox() { if (m_hDimsBox) return; if (!g_vtDimsAlpha.IsInitted()) { g_vtDimsAlpha.Init(g_pLTServer, "DimsAlpha", LTNULL, 1.0f); } ObjectCreateStruct theStruct; INIT_OBJECTCREATESTRUCT(theStruct); LTVector vPos; g_pLTServer->GetObjectPos(m_hObject, &vPos); theStruct.m_Pos = vPos; SAFE_STRCPY(theStruct.m_Filename, "Models\\1x1_square.abc"); SAFE_STRCPY(theStruct.m_SkinName, "Models\\1x1_square.dtx"); theStruct.m_Flags = FLAG_VISIBLE | FLAG_NOLIGHT | FLAG_GOTHRUWORLD; theStruct.m_ObjectType = OT_MODEL; HCLASS hClass = g_pLTServer->GetClass("BaseClass"); LPBASECLASS pModel = g_pLTServer->CreateObject(hClass, &theStruct); if (pModel) { m_hDimsBox = pModel->m_hObject; LTVector vDims; g_pLTServer->GetObjectDims(m_hObject, &vDims); LTVector vScale; VEC_DIVSCALAR(vScale, vDims, 0.5f); g_pLTServer->ScaleObject(m_hDimsBox, &vScale); } LTVector vOffset; LTRotation rOffset; vOffset.Init(); rOffset.Init(); HATTACHMENT hAttachment; LTRESULT dRes = g_pLTServer->CreateAttachment(m_hObject, m_hDimsBox, LTNULL, &vOffset, &rOffset, &hAttachment); if (dRes != LT_OK) { g_pLTServer->RemoveObject(m_hDimsBox); m_hDimsBox = LTNULL; } LTVector vColor = GetBoundingBoxColor(); g_pLTServer->SetObjectColor(m_hDimsBox, vColor.x, vColor.y, vColor.z, g_vtDimsAlpha.GetFloat()); }
void Explosion::ReadProp(ObjectCreateStruct *pStruct) { CServerDE* pServerDE = GetServerDE(); if (!pServerDE || !pStruct) return; char buf[MAX_CS_FILENAME_LEN]; buf[0] = '\0'; pServerDE->GetPropString("Skin", buf, MAX_CS_FILENAME_LEN); if (buf[0]) m_hstrSkinName = pServerDE->CreateString(buf); buf[0] = '\0'; pServerDE->GetPropString("Model", buf, MAX_CS_FILENAME_LEN); if (buf[0]) m_hstrModelName = pServerDE->CreateString(buf); buf[0] = '\0'; pServerDE->GetPropString("Sound", buf, MAX_CS_FILENAME_LEN); if (buf[0]) m_hstrSound = pServerDE->CreateString(buf); pServerDE->GetPropReal("SoundRadius", &m_fSoundRadius); pServerDE->GetPropReal("DamageRadius", &m_fDamageRadius); pServerDE->GetPropReal("MaxDamage", &m_fMaxDamage); pServerDE->GetPropReal("MinScale", &m_fMinScale); pServerDE->GetPropReal("MaxScale", &m_fMaxScale); pServerDE->GetPropReal("Duration", &m_fMinScale); pServerDE->GetPropBool("CreateLight", &m_bCreateLight); pServerDE->GetPropVector("LightColor", &m_vLightColor); VEC_DIVSCALAR(m_vLightColor, m_vLightColor, 255.0f); pServerDE->GetPropBool("CreateSmoke", &m_bCreateSmoke); pServerDE->GetPropBool("CreateShockwave", &m_bCreateShockwave); buf[0] = '\0'; pServerDE->GetPropString("ShockwaveFile", buf, MAX_CS_FILENAME_LEN); if (buf[0]) m_hstrShockwaveSprite = pServerDE->CreateString(buf); pServerDE->GetPropVector("ShockwaveScaleMin", &m_vShockwaveScaleMin); pServerDE->GetPropVector("ShockwaveScaleMax", &m_vShockwaveScaleMax); pServerDE->GetPropReal("ShockwaveDuration", &m_fShockwaveDuration); pServerDE->GetPropReal("Delay", &m_fDelay); pServerDE->GetPropVector("RotateSpeed", &m_vRotation); return; }
DBOOL ClientLightFX::Init() { CServerDE* pServerDE = GetServerDE(); if (!pServerDE) return DFALSE; VEC_DIVSCALAR(m_vColor, m_vColor, 511.0f); m_fStartTime = pServerDE->GetTime(); m_fIntensityPhase = DEG2RAD(m_fIntensityPhase); m_fRadiusPhase = DEG2RAD(m_fRadiusPhase); if (m_bOn) { DDWORD dwUsrFlags = pServerDE->GetObjectUserFlags(m_hObject); dwUsrFlags |= USRFLG_VISIBLE | USRFLG_SAVEABLE; pServerDE->SetObjectUserFlags(m_hObject, dwUsrFlags); } return DTRUE; }
LTBOOL ClientLightFX::Init() { VEC_DIVSCALAR(m_vColor, m_vColor, 511.0f); m_fStartTime = g_pLTServer->GetTime(); m_fIntensityPhase = DEG2RAD(m_fIntensityPhase); m_fRadiusPhase = DEG2RAD(m_fRadiusPhase); if (m_bStartOn) { uint32 dwUsrFlags = g_pLTServer->GetObjectUserFlags(m_hObject); dwUsrFlags |= USRFLG_VISIBLE; g_pLTServer->SetObjectUserFlags(m_hObject, dwUsrFlags); } // Set the dims to something to avoid situations where the object is considered // invisible even though it's visible. float fDims = LTMAX(m_fRadiusMin, 5.0f); LTVector vDims(fDims, fDims, fDims); g_pLTServer->SetObjectDims(m_hObject, &vDims); return LTTRUE; }
void SoccerBall::Update( ) { DVector vVel, vAccel, vAccelAdd, vPos, vForward, vCross, vTemp, vTemp2; CollisionInfo collInfo; float fVelMag, fDistTraveled, fTime, fRotAmount, fExp; DRotation rRot; g_pServerDE->GetObjectPos( m_hObject, &vPos ); g_pServerDE->GetVelocity( m_hObject, &vVel ); fVelMag = VEC_MAG( vVel ); fTime = g_pServerDE->GetTime( ); // Remove the ball if it's been sitting around for a while. if( fTime > m_fRespawnTime ) { g_pServerDE->RemoveObject( m_hObject ); return; } // Update the on ground info g_pServerDE->GetStandingOn( m_hObject, &collInfo ); m_bOnGround = ( collInfo.m_hObject ) ? DTRUE : DFALSE; if( m_bOnGround ) { m_fLastTimeOnGround = fTime; } // Get how far we've traveled. VEC_SUB( vForward, vPos, m_vLastPos ); fDistTraveled = VEC_MAG( vForward ); VEC_COPY( m_vLastPos, vPos ); // Rotate the ball if( fDistTraveled > 0.0f ) { VEC_MULSCALAR( vForward, vForward, 1.0f / fDistTraveled ); if( m_bOnGround ) { VEC_COPY( m_vLastNormal, collInfo.m_Plane.m_Normal ); VEC_CROSS( vCross, vForward, m_vLastNormal ); fRotAmount = VEC_MAG( vCross ) * fDistTraveled / m_fRadius; } else { VEC_CROSS( vCross, vForward, m_vLastNormal ); fRotAmount = VEC_MAG( vCross ) * fDistTraveled / m_fRadius; } if( fRotAmount > 0.0f ) { VEC_NORM( vCross ); g_pServerDE->GetObjectRotation( m_hObject, &rRot ); g_pServerDE->RotateAroundAxis( &rRot, &vCross, fRotAmount ); g_pServerDE->SetObjectRotation( m_hObject, &rRot ); } } // Adjust the velocity and accel if( fVelMag < MINBALLVEL ) { VEC_INIT( vVel ); g_pServerDE->SetVelocity( m_hObject, &vVel ); } else if( fVelMag > MAXBALLVEL ) { VEC_MULSCALAR( vVel, vVel, MAXBALLVEL / fVelMag ); g_pServerDE->SetVelocity( m_hObject, &vVel ); } else { // new velocity is given by: v = ( a / k ) + ( v_0 - a / k ) * exp( -k * t ) g_pServerDE->GetAcceleration( m_hObject, &vAccel ); fExp = ( float )exp( -BALLDRAG * g_pServerDE->GetFrameTime( )); VEC_DIVSCALAR( vTemp, vAccel, BALLDRAG ); VEC_SUB( vTemp2, vVel, vTemp ); VEC_MULSCALAR( vTemp2, vTemp2, fExp ); VEC_ADD( vVel, vTemp2, vTemp ); g_pServerDE->SetVelocity( m_hObject, &vVel ); } // Make sure we're rolling if we're on a slope. This counteracts the way the // engine stops objects on slopes. if( m_bOnGround ) { if( collInfo.m_Plane.m_Normal.y < 0.9f && fabs( vVel.y ) < 50.0f ) { g_pServerDE->GetGlobalForce( &vAccelAdd ); vAccel.y += vAccelAdd.y * 0.5f; g_pServerDE->SetAcceleration( m_hObject, &vAccel ); } } // Play a bounce sound if enough time has elapsed if( m_bBounced ) { if( fTime > m_fLastBounceTime + TIMEBETWEENBOUNCESOUNDS ) { // Play a bounce sound... PlaySoundFromPos( &vPos, "Sounds_ao\\events\\soccerball.wav", 750, SOUNDPRIORITY_MISC_MEDIUM ); } m_bBounced = DFALSE; } g_pServerDE->SetNextUpdate( m_hObject, 0.001f ); }
bool Prop::Setup( ) { // Set Initial flags...(NOTE: The m_dwXXX variables are used so subclasses // can adjust the intial state of the prop) g_pCommonLT->SetObjectFlags(m_hObject, OFT_User, m_dwUsrFlgs, m_dwUsrFlgs); g_pCommonLT->SetObjectFlags(m_hObject, OFT_Flags, m_dwFlags, m_dwFlags); g_pCommonLT->SetObjectFlags(m_hObject, OFT_Flags2, m_dwFlags2, m_dwFlags2); // Set object translucency... VEC_DIVSCALAR(m_vObjectColor, m_vObjectColor, 255.0f); g_pLTServer->SetObjectColor(m_hObject, m_vObjectColor.x, m_vObjectColor.y, m_vObjectColor.z, m_fAlpha); // Default us to our "world" animation... // Pick a random world animation from the list. uint32 iWorldAnim = 1; char szWorldAnim[32]; sprintf( szWorldAnim, "%s%d", ANIM_WORLD, iWorldAnim++ ); HMODELANIM hWorldAnim = g_pLTServer->GetAnimIndex( m_hObject, szWorldAnim ); while( hWorldAnim != INVALID_ANI ) { m_lstWorldAnims.push_back( hWorldAnim ); sprintf( szWorldAnim, "%s%d", ANIM_WORLD, iWorldAnim++ ); hWorldAnim = g_pLTServer->GetAnimIndex( m_hObject, szWorldAnim ); } PlayRandomWorldAnim(); // Look for touch animation. HMODELANIM hAnim = g_pLTServer->GetAnimIndex(m_hObject, ANIM_TOUCH); if( hAnim != INVALID_ANI ) { if(m_pDisturb == LTNULL) { m_pDisturb = debug_new(PropDisturbStruct); } m_pDisturb->hTouchAnim = hAnim; m_pDisturb->eTouchAnimType = kPA_Touch; AIASSERT( g_pLTServer->GetAnimIndex(m_hObject, ANIM_KNOCK) == INVALID_ANI, m_hObject, "Prop::InitialUpdate: Prop cannot have both TOUCH and KNOCK animations." ); } else // Look for knock animation. { hAnim = g_pLTServer->GetAnimIndex(m_hObject, ANIM_KNOCK); if( hAnim != INVALID_ANI ) { if(m_pDisturb == LTNULL) { m_pDisturb = debug_new(PropDisturbStruct); } m_pDisturb->hTouchAnim = hAnim; m_pDisturb->eTouchAnimType = kPA_Knock; } } // Look for hit animation... hAnim = g_pLTServer->GetAnimIndex( m_hObject, ANIM_HIT ); if( hAnim != INVALID_ANI ) { if( m_pDisturb == LTNULL ) { m_pDisturb = debug_new( PropDisturbStruct ); } m_pDisturb->hHitAnim = hAnim; } // Set the dims based on the current animation... LTVector vDims; g_pCommonLT->GetModelAnimUserDims(m_hObject, &vDims, g_pLTServer->GetModelAnimation(m_hObject)); // Set object dims based on scale value... LTVector vNewDims; vNewDims.x = m_vScale.x * vDims.x; vNewDims.y = m_vScale.y * vDims.y; vNewDims.z = m_vScale.z * vDims.z; g_pLTServer->ScaleObject(m_hObject, &m_vScale); g_pPhysicsLT->SetObjectDims(m_hObject, &vNewDims, 0); // Only need to update if we're moving the object to the floor...Else, disable // updates so the object isn't eating ticks... SetNextUpdate((m_bMoveToFloor || !m_bCanDeactivate) ? UPDATE_NEXT_FRAME : UPDATE_NEVER); // See if we should force our debris aggregate to use a specific // debris type... if (m_pDebrisOverride && *m_pDebrisOverride) { DEBRIS* pDebris = g_pDebrisMgr->GetDebris(m_pDebrisOverride); if (pDebris) { m_damage.m_nDebrisId = pDebris->nId; } } // Send the Activate SpecialFX message. If we never set the Activate Type no message will get sent... m_ActivateTypeHandler.SetState( ACTIVATETYPE::eOn, false ); m_ActivateTypeHandler.SetDisabled( false, false ); m_ActivateTypeHandler.CreateActivateTypeMsg(); return true; }
void Prop::InitialUpdate() { // Set flags... uint32 dwFlags = g_pLTServer->GetObjectUserFlags(m_hObject); g_pLTServer->SetObjectUserFlags(m_hObject, dwFlags | m_dwUsrFlgs); dwFlags = g_pLTServer->GetObjectFlags(m_hObject); g_pLTServer->SetObjectFlags(m_hObject, dwFlags | m_dwFlags); g_pLTServer->Common()->GetObjectFlags(m_hObject, OFT_Flags2, dwFlags); g_pLTServer->Common()->SetObjectFlags(m_hObject, OFT_Flags2, dwFlags | m_dwFlags2); // Set object translucency... VEC_DIVSCALAR(m_vObjectColor, m_vObjectColor, 255.0f); g_pLTServer->SetObjectColor(m_hObject, m_vObjectColor.x, m_vObjectColor.y, m_vObjectColor.z, m_fAlpha); // Default us to our "world" animation... uint32 dwAni = g_pLTServer->GetAnimIndex(m_hObject, "World"); if (dwAni != INVALID_ANI) { g_pLTServer->SetModelAnimation(m_hObject, dwAni); } // Set the dims based on the current animation... LTVector vDims; g_pLTServer->GetModelAnimUserDims(m_hObject, &vDims, g_pLTServer->GetModelAnimation(m_hObject)); // Set object dims based on scale value... LTVector vNewDims; vNewDims.x = m_vScale.x * vDims.x; vNewDims.y = m_vScale.y * vDims.y; vNewDims.z = m_vScale.z * vDims.z; g_pLTServer->ScaleObject(m_hObject, &m_vScale); g_pLTServer->SetObjectDims(m_hObject, &vNewDims); // Only need to update if we're moving the object to the floor... if (m_bMoveToFloor) { SetNextUpdate(0.001f); } // See if we should force our debris aggregate to use a specific // debris type... if (m_pDebrisOverride && *m_pDebrisOverride) { DEBRIS* pDebris = g_pDebrisMgr->GetDebris(m_pDebrisOverride); if (pDebris) { m_damage.m_nDebrisId = pDebris->nId; } } }