void GameObject::ChangeParent( GameObject* nextParent ) { D3DXMATRIX matParent; D3DXMatrixIdentity( &matParent ); GameObject* parent = GetParent(); if( parent ) { matParent = parent->m_matWorld; } UpdateTransform( matParent ); m_matLocal = m_matWorld; D3DXMatrixIdentity( &matParent ); if( nextParent ) { matParent = nextParent->m_matWorld; } D3DXMATRIX matInv; D3DXMatrixInverse( &matInv,NULL,&matParent ); D3DXMatrixMultiply( &m_matLocal,&matInv,&m_matLocal ); D3DXMatrixDecompose( &m_localScale,&m_localRotation,&m_localPosition,&m_matLocal ); m_changedLocal = true; UpdateTransform( matParent ); }
void wxSVGAnimateTransformElement::ApplyAnimation() { wxSVGElement* targetElement = GetTargetElement(); if (targetElement == NULL || GetDur() <= 0 || (GetTo().GetPropertyType() != wxSVG_ANIMATED_LENGTH && GetTo().GetPropertyType() != wxSVG_ANIMATED_LENGTH_LIST)) return; wxSVGLengthList values; if (GetCurrentTime() >= GetStartTime() + GetDur()) { if (GetTo().GetPropertyType() == wxSVG_ANIMATED_LENGTH) { values.push_back(GetTo().GetLength()); } else { values = GetTo().GetLengthList(); } } else if (GetCurrentTime() >= GetStartTime() && GetFrom().GetPropertyType() == GetTo().GetPropertyType() && GetFrom().GetLengthList().size() == GetTo().GetLengthList().size()) { if (GetTo().GetPropertyType() == wxSVG_ANIMATED_LENGTH) { values.Add(wxSVGLength(GetTo().GetLength().GetUnitType(), GetFrom().GetLength().GetValue() + (GetTo().GetLength().GetValue() - GetFrom().GetLength().GetValue())* (GetCurrentTime() - GetStartTime())/GetDur())); } else { for (unsigned int i = 0; i < GetFrom().GetLengthList().size(); i++) { const wxSVGLength& from = GetFrom().GetLengthList()[i]; const wxSVGLength& to = GetTo().GetLengthList()[i]; values.Add(wxSVGLength(to.GetUnitType(), from.GetValue() + (to.GetValue() - from.GetValue())*(GetCurrentTime() - GetStartTime())/GetDur())); } } } else { return; } wxSVGTransformable* transformable = wxSVGTransformable::GetSVGTransformable(*targetElement); if (transformable != NULL) { if (m_transformIdx == -1 || m_transformIdx >= (int) transformable->GetTransformList().GetAnimVal().size()) { wxSVGTransformList& transforms = transformable->GetTransformList().GetAnimVal(); if (GetAdditive() != wxSVG_ANIMATION_ADDITIVE_SUM) { transforms.Clear(); } wxSVGTransform* transform = new wxSVGTransform(); UpdateTransform(*transform, GetType(), values); transforms.Add(transform); m_transformIdx = transforms.size() - 1; } else { UpdateTransform(transformable->GetTransformList().GetAnimVal()[m_transformIdx], GetType(), values); } } else { wxSVGTransformList transforms; wxSVGTransform* transform = new wxSVGTransform(); UpdateTransform(*transform, GetType(), values); transforms.Add(transform); targetElement->SetAnimatedValue(GetAttributeName(), wxSVGAnimatedType(transforms)); } }
///////////////////////////////////////////////////////////////////////////// // Set observer position ///////////////////////////////////////////////////////////////////////////// void CPlot::SetObserver(double x, double y, double z) { tObserver[0] = x; tObserver[1] = y; tObserver[2] = z; UpdateTransform(); }
// NOTE: it is important that rigid bodies are added // (happens in CJoint::Attach()) before joint transforms are set!!! void CHinge2Joint::Attach(dWorldID WorldID, dJointGroupID GroupID, const matrix44& ParentTfm) { ODEJointID = dJointCreateHinge2(WorldID, GroupID); for (int i = 0; i < 2; i++) { const CJointAxis& CurrAxis = AxisParams[i]; if (CurrAxis.IsLoStopEnabled) dJointSetHinge2Param(ODEJointID, dParamLoStop + dParamGroup * i, CurrAxis.LoStop); if (CurrAxis.IsHiStopEnabled) dJointSetHinge2Param(ODEJointID, dParamHiStop + dParamGroup * i, CurrAxis.HiStop); dJointSetHinge2Param(ODEJointID, dParamVel + dParamGroup * i, CurrAxis.Velocity); dJointSetHinge2Param(ODEJointID, dParamFMax + dParamGroup * i, CurrAxis.FMax); dJointSetHinge2Param(ODEJointID, dParamFudgeFactor + dParamGroup * i, CurrAxis.FudgeFactor); dJointSetHinge2Param(ODEJointID, dParamBounce + dParamGroup * i, CurrAxis.Bounce); dJointSetHinge2Param(ODEJointID, dParamCFM + dParamGroup * i, CurrAxis.CFM); dJointSetHinge2Param(ODEJointID, dParamStopERP + dParamGroup * i, CurrAxis.StopERP); dJointSetHinge2Param(ODEJointID, dParamStopCFM + dParamGroup * i, CurrAxis.StopCFM); } dJointSetHinge2Param(ODEJointID, dParamSuspensionERP, SuspensionERP); dJointSetHinge2Param(ODEJointID, dParamSuspensionCFM, SuspensionCFM); CJoint::Attach(WorldID, GroupID, ParentTfm); UpdateTransform(ParentTfm); }
BOOL obj_Grenade::OnCreate() { const GameObject* owner = GameWorld().GetObject(ownerID); if(!owner) return FALSE; m_isSerializable = false; ReadPhysicsConfig(); PhysicsConfig.group = PHYSCOLL_PROJECTILES; PhysicsConfig.isFastMoving = true; r3d_assert(m_Ammo); r3d_assert(m_Weapon); parent::OnCreate(); m_CreationTime = r3dGetTime() - m_AddedDelay; m_CreationPos = GetPosition(); if(m_Ammo->getParticleTracer()) m_ParticleTracer = (obj_ParticleSystem*)srv_CreateGameObject("obj_ParticleSystem", m_Ammo->getParticleTracer(), GetPosition() ); SetBBoxLocal( GetObjectMesh()->localBBox ) ; UpdateTransform(); m_FireDirection.y += 0.1f; // to make grenade fly where you point m_AppliedVelocity = m_FireDirection*m_Weapon->m_AmmoSpeed; SetVelocity(m_AppliedVelocity); return TRUE; }
CEditableObject* CSceneObject::UpdateReference() { Lib.RemoveEditObject(m_pReference); m_pReference = (m_ReferenceName.size())?Lib.CreateEditObject(*m_ReferenceName):0; UpdateTransform (); return m_pReference; }
BOOL obj_ParticleSystem::OnCreate() { parent::OnCreate(); setSkipOcclusionCheck(true); // until proper aabb will be generated for particles!! ObjFlags |= OBJFLAG_DisableShadows | OBJFLAG_ForceSleep; UpdateTime = r3dGetTime(); Torch->GlobalScale = GlobalScale; Torch->Position = GetPosition(); Torch->Restart(UpdateTime); float size = SRV_WORLD_SCALE(1.0f); r3dBoundBox bboxLocal ; bboxLocal.Size.Assign(size, size, size); bboxLocal.Org = - bboxLocal.Size * 0.5f; SetBBoxLocal( bboxLocal ) ; UpdateTransform(); return TRUE; }
bool CGlow::Load(IReader& F) { u32 version = 0; R_ASSERT(F.r_chunk(GLOW_CHUNK_VERSION,&version)); if((version!=0x0011)&&(version!=GLOW_VERSION)){ ELog.DlgMsg( mtError, "CGlow: Unsupported version."); return false; } CCustomObject::Load(F); if (F.find_chunk(GLOW_CHUNK_SHADER)){ F.r_stringZ (m_ShaderName); } R_ASSERT(F.find_chunk(GLOW_CHUNK_TEXTURE)); F.r_stringZ (m_TexName); R_ASSERT(F.find_chunk(GLOW_CHUNK_PARAMS)); m_fRadius = F.r_float(); if (version==0x0011){ F.r_fvector3 (FPosition); UpdateTransform(); } if (F.find_chunk(GLOW_CHUNK_FLAGS)) m_Flags.assign (F.r_u16()); return true; }
BOOL obj_DebugTexture::OnCreate() { parent::OnCreate(); ObjFlags |= OBJFLAG_DisableShadows ; setSkipOcclusionCheck(true); ObjFlags |= OBJFLAG_SkipCastRay ; ObjFlags |= OBJFLAG_AlwaysDraw ; ObjFlags |= OBJFLAG_ForceSleep; m_isSerializable = false ; DrawOrder = OBJ_DRAWORDER_LAST; r3dBoundBox bboxLocal ; bboxLocal.Size = r3dPoint3D(10,10,10); bboxLocal.Org = -bboxLocal.Size * 0.5f; SetBBoxLocal( bboxLocal ) ; UpdateTransform(); return 1; }
///////////////////////////////////////////////////////////////////////////// // Set target point ///////////////////////////////////////////////////////////////////////////// void CPlot::SetTarget(double x, double y, double z) { tTarget[0] = x; tTarget[1] = y; tTarget[2] = z; UpdateTransform(); }
BOOL obj_ItemSpawnPoint::OnCreate() { parent::OnCreate(); #ifndef FINAL_BUILD if(!g_bEditMode) #endif ObjFlags |= OBJFLAG_SkipCastRay; #ifndef FINAL_BUILD if(g_bEditMode) // to make it easier in editor to edit spawn points { setSkipOcclusionCheck(true); ObjFlags |= OBJFLAG_AlwaysDraw | OBJFLAG_ForceSleep ; } #endif r3dBoundBox bboxLocal ; bboxLocal.Size = r3dPoint3D(2, 2, 2); bboxLocal.Org = -bboxLocal.Size * 0.5f; SetBBoxLocal(bboxLocal) ; UpdateTransform(); return 1; }
void CFeature::UpdateTransformAndPhysState() { UpdateDirVectors(!def->upright); UpdateTransform(pos, true); UpdatePhysicalStateBit(CSolidObject::PSTATE_BIT_MOVING, (SetSpeed(speed) != 0.0f)); UpdatePhysicalState(0.1f); }
void CGroupObject::Scale(Fvector& amount ) { inherited::Scale(amount); Fmatrix m_old; m_old.invert(FTransform); UpdateTransform(true); for (ObjectIt it=m_Objects.begin(); it!=m_Objects.end(); it++) (*it)->ScalePivot(m_old,FTransform,amount); }
void CGroupObject::UpdatePivot(LPCSTR nm, bool center) { // first init VERIFY(m_Objects.size()); if (false==center){ CCustomObject* object = 0; if (nm&&nm[0]){ for (ObjectIt it=m_Objects.begin(); it!=m_Objects.end(); it++){ if (0==strcmp(nm,(*it)->Name)){ object = *it; break; } } }else{ bool bValidPivot = false; for (ObjectIt it=m_Objects.begin(); it!=m_Objects.end(); it++){ if ((*it)->ClassID==OBJCLASS_SCENEOBJECT){ object = (*it); bValidPivot = true; break; } } if (!bValidPivot) object = m_Objects.front(); } if (object){ PPosition = object->PPosition; PRotation = object->PRotation; //. PScale = object->PScale; UpdateTransform(true); //.. if (object->GetUTBox(box)) m_BBox.merge(box); } }else{ // center alignment ObjectIt it=m_Objects.begin(); Fvector C; C.set((*it)->PPosition); it++; for (; it!=m_Objects.end(); it++) C.add((*it)->PPosition); FPosition.div(C,m_Objects.size()); FRotation.set(0,0,0); //. FScale.set(1.f,1.f,1.f); UpdateTransform(true); } }
void GameObject::SetScale(const r3dPoint3D &v) { vScl = v; ShadowExDirty = true; UpdateTransform(); if (PhysicsObject) { PhysicsObject->SetScale(v); } }
///////////////////////////////////////////////////////////////////////////// // Constructor ///////////////////////////////////////////////////////////////////////////// CPlot::CPlot(const CSurface &surfInit): surf(surfInit) { tObserver[0] = tObserver[1] = tObserver[2] = 10.0; tTarget[0] = tTarget[1] = tTarget[2] = 0.0; xMin = yMin = zMin = -1.0; xMax = yMax = zMax = 1.0; Dist = 1.0; UpdateTransform(); }
void Model::Update(float deltaTime) { if(IsUpToDate()) { return; } UpdateTransform(); IObject::Update(deltaTime); }
BOOL obj_DBFMasterControl::Update() { float f = 2.f; r3dBoundBox bboxLocal ; bboxLocal.Size = r3dPoint3D( f, f, f ); bboxLocal.Org = -bboxLocal.Size / 2; SetBBoxLocal( bboxLocal ) ; UpdateTransform(); return TRUE; }
void CGroupObject::NumSetPosition(const Fvector& pos) { inherited::NumSetPosition(pos); Fmatrix prev; prev.invert(FTransform); UpdateTransform(true); for (ObjectIt it=m_Objects.begin(); it!=m_Objects.end(); it++){ Fvector v=(*it)->PPosition; prev.transform_tiny(v); FTransform.transform_tiny(v); (*it)->PPosition=v; } }
void GameObject::SetRotationVector(const r3dVector& Angles) { if(vRot.AlmostEqual(Angles)) return; if(PhysicsObject) PhysicsObject->SetRotation(Angles); vRot = Angles; vLoadTimeRot = Angles; ShadowExDirty = true ; UpdateTransform(); }
void GameObject::SetPosition(const r3dPoint3D& pos) { if(r3d_float_isFinite(pos.x) && r3d_float_isFinite(pos.y) && r3d_float_isFinite(pos.z)) // sanity check { if(PhysicsObject) PhysicsObject->SetPosition(pos); vPos = pos; vLoadTimePos = pos; ShadowExDirty = true ; UpdateTransform(); } }
bool EParticlesObject::Compile(LPCSTR ref_name) { ::Render->model_Delete (m_Particles); if (ref_name){ m_Particles = (IParticleCustom*)::Render->model_CreateParticles(ref_name); if (m_Particles){ UpdateTransform (); m_RefName = ref_name; return true; } } m_RefName = ""; return false; }
bool CGroupObject::UpdateReference() { if (!m_ReferenceName.size()){ ELog.Msg (mtError,"ERROR: '%s' - has empty reference.",Name); return false; } xr_string fn = m_ReferenceName.c_str(); fn = EFS.ChangeFileExt(fn,".group"); IReader* R = FS.r_open(_groups_,fn.c_str()); bool bres = false; if (R){ CloseGroup (); Clear (); xr_string nm = Name; shared_str old_refs = m_ReferenceName; UpdateTransform (true); Fvector old_pos = PPosition; Fvector old_rot = PRotation; Fvector old_sc = PScale; if (Load(*R)){ Name = nm.c_str(); bres = true; UpdateTransform (true); } m_ReferenceName = old_refs; NumSetPosition (old_pos); NumSetRotation (old_rot); NumSetScale (old_sc); UpdateTransform (true); FS.r_close (R); }else{ ELog.Msg (mtError,"ERROR: Can't open group file: '%s'.",fn.c_str()); } return bres; }
void CEditShape::SetScale(const Fvector& val) { if (shapes.size()==1){ switch (shapes[0].type){ case cfSphere:{ FScale.set(val.x,val.x,val.x); }break; case cfBox: FScale.set(val.x,val.y,val.z); break; default: THROW; } }else{ FScale.set(val.x,val.x,val.x); } ComputeBounds (); UpdateTransform (); }
GameObject::GameObject() : m_pModelRenderer(NULL) , m_pPMDModelRenderer(NULL) , m_name(_T("GameObject")) , m_pAnimation(NULL) { m_localPosition = D3DXVECTOR3(0.0f,0.0f,0.0f); D3DXQuaternionIdentity( &m_localRotation ); m_localScale = D3DXVECTOR3(1.0f,1.0f,1.0f); D3DXMATRIX matParent; D3DXMatrixIdentity( &matParent ); m_changedLocal = true; UpdateTransform( matParent ); }
void CGroupObject::NumSetScale(const Fvector& scale) { Fvector old_s = PScale; inherited::NumSetScale(scale); Fmatrix prev; prev.invert(FTransform); UpdateTransform(true); Fvector ds; ds.sub(FScale,old_s); for (ObjectIt it=m_Objects.begin(); it!=m_Objects.end(); it++){ Fvector s=(*it)->PScale; s.add(ds); (*it)->PScale=s; Fvector v=(*it)->PPosition; prev.transform_tiny(v); FTransform.transform_tiny(v); (*it)->PPosition=v; } }
void GameObject::SetLocalScale( const D3DXVECTOR3& scale ) { m_localScale = scale; D3DXMATRIX matParent; D3DXMatrixIdentity( &matParent ); GameObject* parent = GetParent(); if( parent ) { matParent = parent->m_matWorld; } m_changedLocal = true; UpdateTransform( matParent ); }
void GameObject::SetLocalRotation( const D3DXQUATERNION& rotation ) { m_localRotation = rotation; D3DXMATRIX matParent; D3DXMatrixIdentity( &matParent ); GameObject* parent = GetParent(); if( parent ) { matParent = parent->m_matWorld; } m_changedLocal = true; UpdateTransform( matParent ); }
void CGroupObject::Move(Fvector& amount) { Fvector old_r=FRotation; inherited::Move(amount); Fmatrix prev; prev.invert(FTransform); UpdateTransform(true); Fvector dr; dr.sub(FRotation,old_r); for (ObjectIt it=m_Objects.begin(); it!=m_Objects.end(); it++){ Fvector r=(*it)->PRotation; r.add(dr); (*it)->PRotation=r; Fvector v=(*it)->PPosition; prev.transform_tiny(v); FTransform.transform_tiny(v); (*it)->PPosition=v; } }
void GameObject::CreatePhysicsData() { UpdateTransform(); if(PhysicsConfig.ready && PhysicsObject == 0 && m_bEnablePhysics) { if(PhysicsConfig.isDynamic || PhysicsConfig.isKinematic) { PhysicsObject = BasePhysicsObject::CreateDynamicObject(PhysicsConfig, this); ObjFlags &= ~OBJFLAG_ForceSleep ; } else { PhysicsObject = BasePhysicsObject::CreateStaticObject(PhysicsConfig, this); ObjFlags |= OBJFLAG_ForceSleep ; } } }