//------------------------------------------------------------------------ void CItem::SetCharacterAttachmentWorldTM(int slot, const char *name, const Matrix34 &tm) { ICharacterInstance *pCharacter = GetEntity()->GetCharacter(slot); if(IAttachment * pAttachment = GetCharacterAttachment(pCharacter, name)) { Matrix34 boneWorldMatrix = GetEntity()->GetSlotWorldTM(slot) * Matrix34(pCharacter->GetISkeletonPose()->GetAbsJointByID(pAttachment->GetBoneID()) ); Matrix34 localAttachmentMatrix = (boneWorldMatrix.GetInverted()*tm); pAttachment->SetAttRelativeDefault(QuatT(localAttachmentMatrix)); } }
//------------------------------------------------------------------------ void CItem::SetEffectWorldTM(uint32 id, const Matrix34 &tm) { TEffectInfoMap::const_iterator it = m_effects.find(id); if (it == m_effects.end()) return; const SEffectInfo &info = it->second; SEntitySlotInfo slotInfo; if (GetEntity()->GetSlotInfo(info.slot, slotInfo) && (slotInfo.pParticleEmitter||slotInfo.pLight)) { Matrix34 worldMatrix = GetEntity()->GetWorldTM(); Matrix34 localMatrix = worldMatrix.GetInverted()*tm; GetEntity()->SetSlotLocalTM(info.slot, localMatrix); } else if (GetEntity()->GetSlotInfo(info.characterSlot, slotInfo) && slotInfo.pCharacter) SetCharacterAttachmentWorldTM(info.characterSlot, info.helper.c_str(), tm); }
//------------------------------------------------------------------------ void CItem::SetCharacterAttachmentWorldTM(int slot, const char *name, const Matrix34 &tm) { ICharacterInstance *pCharacter = GetEntity()->GetCharacter(slot); if (!pCharacter) return; IAttachmentManager *pAttachmentManager = pCharacter->GetIAttachmentManager(); IAttachment *pAttachment = pAttachmentManager->GetInterfaceByName(name); if (!pAttachment) { GameWarning("Item '%s' trying to set world TM on attachment '%s' which does not exist!", GetEntity()->GetName(), name); return; } // Matrix34 boneWorldMatrix = GetEntity()->GetSlotWorldTM(slot) * pCharacter->GetISkeleton()->GetAbsJMatrixByID(pAttachment->GetBoneID()); Matrix34 boneWorldMatrix = GetEntity()->GetSlotWorldTM(slot) * Matrix34(pCharacter->GetISkeletonPose()->GetAbsJointByID(pAttachment->GetBoneID()) ); Matrix34 localAttachmentMatrix = (boneWorldMatrix.GetInverted()*tm); pAttachment->SetAttRelativeDefault(QuatT(localAttachmentMatrix)); }
//------------------------------------------------------------------------ bool CVehicleViewFirstPerson::Init(IVehicleSeat* pISeat, const CVehicleParams& table) { CVehicleSeat* pSeat = static_cast<CVehicleSeat*>(pISeat); if (!CVehicleViewBase::Init(pSeat, table)) return false; if (CVehicleParams paramsTable = table.findChild(m_name)) { paramsTable.getAttr("offset", m_offset); paramsTable.getAttr("hidePlayer", m_hidePlayer); paramsTable.getAttr("hideVehicle", m_hideVehicle); paramsTable.getAttr("relativeToHorizon", m_relToHorizon); paramsTable.getAttr("followSpeed", m_speedRot); float viewFov; if(paramsTable.getAttr("fov", viewFov)) { m_fov = DEG2RAD(viewFov); } m_sCharacterBoneName = paramsTable.getAttr("characterBone"); string helperName = paramsTable.getAttr("helper"); if (!helperName.empty()) { if (helperName != "auto") { m_pHelper = m_pVehicle->GetHelper(helperName); } else { // create a helper with default viewpos above sithelper const string& seatName = pSeat->GetName(); helperName = seatName + string("_ghostview_pos"); if (IVehicleHelper* pSitHelper = pSeat->GetSitHelper()) { Matrix34 tm; pSitHelper->GetVehicleTM(tm); Vec3 pos = tm.GetTranslation() + Vec3(0,0,0.625); // player eye height m_pVehicle->AddHelper(helperName.c_str(), pos, tm.GetColumn1(), pSitHelper->GetParentPart()); m_pHelper = m_pVehicle->GetHelper(helperName.c_str()); } } if (!m_pHelper) GameWarning("[%s, seat %s]: view helper %s not found, using character head", m_pVehicle->GetEntity()->GetName(), m_pSeat->GetName().c_str(), helperName.c_str()); } string frame = paramsTable.getAttr("frameObject"); if (!frame.empty()) { // todo: aspect ratio? if (strstr(frame, ".cgf")) m_frameSlot = m_pVehicle->GetEntity()->LoadGeometry(-1, frame); else m_frameSlot = m_pVehicle->GetEntity()->LoadCharacter(-1, frame); if (m_frameSlot != -1) { m_pVehicle->GetEntity()->SetSlotFlags(m_frameSlot, m_pVehicle->GetEntity()->GetSlotFlags(m_frameSlot) &~ (ENTITY_SLOT_RENDER|ENTITY_SLOT_RENDER_NEAREST)); if (m_pHelper) { Matrix34 tm; m_pHelper->GetVehicleTM(tm); m_invFrame = tm.GetInverted(); m_pVehicle->GetEntity()->SetSlotLocalTM(m_frameSlot, tm); } } } paramsTable.getAttr("frameObjectOffset", m_frameObjectOffset); } if (m_hideVehicle) m_hidePlayer = true; if (m_speedRot==0.f) { m_speedRot = 4.0f; if (IVehicleMovement* pMovement = m_pVehicle->GetMovement()) { if (pMovement->GetMovementType() == IVehicleMovement::eVMT_Air) { m_speedRot *= 2.0f; } } } Reset(); return true; }
//========================================= void CRocketLauncher::UpdateDotEffect(float frameTime) { Vec3 laserPos, dir; CCamera& camera = gEnv->pSystem->GetViewCamera(); laserPos = camera.GetPosition(); dir = camera.GetMatrix().GetColumn1(); dir.Normalize(); const float nearClipPlaneLimit = 10.0f; Vec3 hitPos(0,0,0); float laserLength = 0.0f; float dotScale=1.0f; { IPhysicalEntity* pSkipEntity = NULL; if(GetOwner()) pSkipEntity = GetOwner()->GetPhysics(); const int objects = ent_all; const int flags = (geom_colltype_ray << rwi_colltype_bit) | rwi_colltype_any | (10 & rwi_pierceability_mask) | (geom_colltype14 << rwi_colltype_bit); ray_hit hit; if (gEnv->pPhysicalWorld->RayWorldIntersection(laserPos, dir*m_LaserRange, objects, flags, &hit, 1, &pSkipEntity, pSkipEntity?1:0)) { //Clamp distance below near clip plane limits, if not dot will be overdrawn during rasterization if(hit.dist>nearClipPlaneLimit) { laserLength = nearClipPlaneLimit; hitPos = laserPos + (nearClipPlaneLimit*dir); } else { laserLength = hit.dist; hitPos = hit.pt; } if(GetOwnerActor() && GetOwnerActor()->GetActorParams()) dotScale *= GetOwnerActor()->GetActorParams()->viewFoVScale; } else { hitPos = laserPos - (3.0f*dir); laserLength = 3.0f; } } if (m_dotEffectSlot>=0) { Matrix34 worldMatrix = GetEntity()->GetWorldTM(); if(laserLength<=0.7f) hitPos = laserPos+(0.7f*dir); if(IsWeaponLowered()) { hitPos = laserPos+(2.0f*dir); laserLength = 2.0f; } if(laserLength<=2.0f) dotScale *= min(1.0f,(0.35f + ((laserLength-0.7f)*0.5f))); Matrix34 localMatrix = worldMatrix.GetInverted()*Matrix34::CreateTranslationMat(hitPos-(0.2f*dir)); localMatrix.Scale(Vec3(dotScale,dotScale,dotScale)); GetEntity()->SetSlotLocalTM(m_dotEffectSlot, localMatrix); } }