void CActorControllerComponent::UpdateLookDirectionRequest(float frameTime)
{
	// The angular velocity maximum (Full rotations / second).
	const float angularVelocityMax = g_PI2 * 1.5f;

	// The catchup speed (Full rotations / second).
	const float catchupSpeed = g_PI2 * 1.2f;

	// If there's a player controlling us, we can query them for inputs and camera and apply that to our rotation.
	if (auto* pPlayer = m_pActorComponent->GetPlayer())
	{
		auto* pPlayerInput = pPlayer->GetPlayerInput();

		// Only allow the character to rotate in first person, and third person if they are moving.
		if ((pPlayer->IsViewFirstPerson()) || (!pPlayer->IsViewFirstPerson() && m_movementRequest.len() > FLT_EPSILON))
		{
			Ang3 facingDir;
			if (pPlayer->IsViewFirstPerson())
				facingDir = CCamera::CreateAnglesYPR(Matrix33(m_lookOrientation));
			else
				facingDir = CCamera::CreateAnglesYPR(m_movementRequest.GetNormalizedFast());

			// Use their last orientation as their present direction.
			// NOTE: I tried it with GetEntity()->GetWorldTM() but that caused crazy jitter issues.
			Ang3 ypr = CCamera::CreateAnglesYPR(Matrix33(m_lookOrientation));

			// We add in some extra rotation to 'catch up' to the direction they are being moved. This will perform a gradual
			// turn on the actor over several frames.
			float rotationDelta { 0.0f };
			if (std::abs(facingDir.x - ypr.x) > g_PI)
				rotationDelta = ypr.x - facingDir.x;
			else
				rotationDelta = facingDir.x - ypr.x;

			// Catchup allows us to step towards the goal direction in even steps using a set angular velocity.
			float catchUp { 0.0f };
			if (std::abs(rotationDelta) > FLT_EPSILON)
			{
				if (rotationDelta > 0.0f)
					catchUp = std::min(rotationDelta, catchupSpeed * frameTime);
				else
					catchUp = std::max(rotationDelta, -catchupSpeed * frameTime);
			}

			// Update angular velocity metrics.
			m_yawAngularVelocity = CLAMP(pPlayerInput->GetMouseYawDelta() + catchUp, -angularVelocityMax * frameTime, angularVelocityMax * frameTime);

			// Yaw.
			ypr.x += m_yawAngularVelocity;

			// Roll (zero it).
			ypr.z = 0;

			// Update the preferred direction we face.
			m_lookOrientation = Quat(CCamera::CreateOrientationYPR(ypr));
		}
	}
}
//------------------------------------------------------------------------
void CVehicleHelper::GetWorldTM(Matrix34& worldTM) const
{
  FUNCTION_PROFILER( gEnv->pSystem, PROFILE_ACTION );

	const Matrix34& partWorldTM = m_pParentPart->GetWorldTM();

	worldTM = Matrix34(Matrix33(partWorldTM) * Matrix33(m_localTM));
	worldTM.SetTranslation((partWorldTM * m_localTM).GetTranslation());
}
//------------------------------------------------------------------------
void CVehicleHelper::GetReflectedWorldTM(Matrix34 &reflectedWorldTM) const
{
	FUNCTION_PROFILER( gEnv->pSystem, PROFILE_ACTION );

	Matrix34 tempMatrix = m_localTM;
	tempMatrix.m03 = -tempMatrix.m03;	// negate x coord of translation

	const Matrix34& partWorldTM = m_pParentPart->GetWorldTM();

	reflectedWorldTM = Matrix34(Matrix33(partWorldTM) * Matrix33(tempMatrix));
	reflectedWorldTM.SetTranslation((partWorldTM * tempMatrix).GetTranslation());
}
inline Matrix33
make_matrix33_cols (const Vec3 &a, const Vec3 &b, const Vec3 &c)
{
    return Matrix33 (a[0], b[0], c[0],
                     a[1], b[1], c[1],
                     a[2], b[2], c[2]);
}
Exemple #5
0
bool Noun::read( const InStream & input )
{
	if (! NodeTransform::read( input ) )
		return false;

	// update the frame of this object..
	m_Frame = Matrix33( m_vOrientation );

	// ensure the parent pointer is set correctly on our traits
	for(size_t i=0;i<m_Traits.size();)
	{
		if (! m_Traits[i].valid() )
		{
			LOG_ERROR( "Noun", "Noun::read() - NULL Trait object." );
			m_Traits.erase( m_Traits.begin() + i );
			continue;
		}

		m_Traits[i]->setParent( this );
		++i;
	}

	// make sure traits are sorted by name
	std::sort( m_Traits.begin(), m_Traits.end(), SortTraits );

	m_bPostInit = postInitialize();
	// set the last position to the current position
	setLastPosition( position() );

	return true;
}
bool
ShadingSystemImpl::set_colorspace (ustring colorspace)
{
    for (int i = 0;  colorSystems[i].name;  ++i) {
        if (colorspace == colorSystems[i].name) {
            m_Red.setValue (colorSystems[i].xRed, colorSystems[i].yRed, 0.0f);
            m_Green.setValue (colorSystems[i].xGreen, colorSystems[i].yGreen, 0.0f);
            m_Blue.setValue (colorSystems[i].xBlue, colorSystems[i].yBlue, 0.0f);
            m_White.setValue (colorSystems[i].xWhite, colorSystems[i].yWhite, 0.0f);
            // set z values to normalize
            m_Red[2]   = 1.0f - (m_Red[0]   + m_Red[1]);
            m_Green[2] = 1.0f - (m_Green[0] + m_Green[1]);
            m_Blue[2]  = 1.0f - (m_Blue[0]  + m_Blue[1]);
            m_White[2] = 1.0f - (m_White[0] + m_White[1]);

            const Color3 &R(m_Red), &G(m_Green), &B(m_Blue), &W(m_White);
            // xyz -> rgb matrix, before scaling to white.
            Color3 r (G[1]*B[2] - B[1]*G[2], B[0]*G[2] - G[0]*B[2], G[0]*B[1] - B[0]*G[1]);
            Color3 g (B[1]*R[2] - R[1]*B[2], R[0]*B[2] - B[0]*R[2], B[0]*R[1] - R[0]*B[1]);
            Color3 b (R[1]*G[2] - G[1]*R[2], G[0]*R[2] - R[0]*G[2], R[0]*G[1] - G[0]*R[1]);
            Color3 w (r.dot(W), g.dot(W), b.dot(W));  // White scaling factor
            if (W[1] != 0.0f)  // divide by W[1] to scale luminance to 1.0
                w *= 1.0f/W[1];
            // xyz -> rgb matrix, correctly scaled to white.
            r /= w[0];
            g /= w[1];
            b /= w[2];
            m_XYZ2RGB = Matrix33 (r[0], g[0], b[0],
                                  r[1], g[1], b[1],
                                  r[2], g[2], b[2]);
            m_RGB2XYZ = m_XYZ2RGB.inverse();
            m_luminance_scale = Color3 (m_RGB2XYZ[0][1], m_RGB2XYZ[1][1], m_RGB2XYZ[2][1]);

            // Precompute a table of blackbody values
            m_blackbody_table.clear ();
            float lastT = 0;
            for (int i = 0;  lastT <= BB_MAX_TABLE_RANGE;  ++i) {
                float T = powf (float(i), BB_TABLE_XPOWER) * BB_TABLE_SPACING + BB_DRAPER;
                lastT = T;
                bb_spectrum spec (T);
                Color3 rgb = XYZ_to_RGB (spectrum_to_XYZ (spec));
                clamp_zero (rgb);
                rgb = colpow (rgb, 1.0f/BB_TABLE_YPOWER);
                m_blackbody_table.push_back (rgb);
                // std::cout << "Table[" << i << "; T=" << T << "] = " << rgb << "\n";
            }
            // std::cout << "Made " << m_blackbody_table.size() << " table entries for blackbody\n";

#if 0
            // Sanity checks
            std::cout << "m_XYZ2RGB = " << m_XYZ2RGB << "\n";
            std::cout << "m_RGB2XYZ = " << m_RGB2XYZ << "\n";
            std::cout << "m_luminance_scale = " << m_luminance_scale << "\n";
#endif
            return true;
        }
    }
    return false;
}
Exemple #7
0
static Matrix33 RotateZ(float theta)
{
    float sinTheta = sinf(theta);
    float cosTheta = cosf(theta);
    return Matrix33(cosTheta,  -sinTheta,  0.0f,
                    sinTheta,   cosTheta,  0.0f,
                    0.0f,       0.0f,      1.0f);
}
Exemple #8
0
void Matrix33::Scale(Vector3 const &aScale)
{
  float values[9] = {aScale.x, 0, 0,
                          0, aScale.y, 0,
                          0, 0, aScale.z};
  Matrix33 scaleMatrix = Matrix33(values);
  (*this) *= scaleMatrix;
}
Matrix33 CameraIntrinsics::getInvKMatrix33() const
{
    double invFocal = k / f;
    return Matrix33 (
       invFocal,  0.0,    -center.x() * invFocal,
          0.0,  invFocal, -center.y() * invFocal,
          0.0,    0.0,               1.0
    );
}
Matrix33 CameraIntrinsics::getKMatrix33() const
{
    double focal = f / k;
    return Matrix33 (
       focal,   0.0, center.x(),
       0.0,   focal, center.y(),
       0.0,     0.0,    1.0
    );
}
	void ProfilerViewer_Imp::DrawTextSprite(Vector2DF position, Color color, astring text)
	{
		m_renderer->AddText(
			Matrix33().SetIdentity(),
			Matrix33().SetTranslation(position.X, position.Y),
			Vector2DF(),
			false,
			false,
			color,
			m_font.get(),
			text.c_str(),
			WritingDirection::Horizontal,
			AlphaBlendMode::Blend,
			1,
			0,
			0,
			false);
	}
Exemple #12
0
//------------------------------------------------------------------------
IMPLEMENT_RMI(CC4Projectile, ClSetPosition)
{
	Matrix34 mat;
	mat.SetRotation33(Matrix33(params.rot));
	mat.SetTranslation(params.pos);
	GetEntity()->SetWorldTM(mat);

	m_stuck = true;

	return true;
}
Exemple #13
0
//------------------------------------------------------------------------
const Matrix33 &CItem::GetSlotHelperRotation(int slot, const char *helper, bool worldSpace, bool relative)
{
	static Matrix33 rotation;
	rotation.SetIdentity();

	IEntity* pEntity = GetEntity();
	if(!pEntity)
		return rotation;

	SEntitySlotInfo info;
	if (pEntity->GetSlotInfo(slot, info))
	{
    if (info.pStatObj)
    {
      IStatObj *pStatObj = info.pStatObj;
      rotation = Matrix33(pStatObj->GetHelperTM(helper));
      rotation.OrthonormalizeFast();
      rotation = Matrix33(GetEntity()->GetSlotLocalTM(slot, false))*rotation;        
    }
		else if (info.pCharacter)
		{
			ICharacterInstance *pCharacter = info.pCharacter;
			if(!pCharacter)
				return rotation;

			IAttachment* pAttachment = pCharacter->GetIAttachmentManager()->GetInterfaceByName(helper);
			if(pAttachment)
			{
				rotation = Matrix33(worldSpace ? pAttachment->GetAttWorldAbsolute().q : pAttachment->GetAttModelRelative().q);
				return rotation;
			}
			else
			{
				ICharacterModelSkeleton* pICharacterModelSkeleton = pCharacter->GetICharacterModel()->GetICharacterModelSkeleton();
				ISkeletonPose* pSkeletonPose = pCharacter->GetISkeletonPose();
				int16 id = pICharacterModelSkeleton->GetJointIDByName(helper);
				if (id > -1)
				{
					rotation = relative ? Matrix33(pSkeletonPose->GetRelJointByID(id).q) : Matrix33(pSkeletonPose->GetAbsJointByID(id).q);
				}
			}

			if (!relative)
			{
				rotation = Matrix33(pEntity->GetSlotLocalTM(slot, false)) * rotation;
			}
		}    
	}

	if (worldSpace)
	{
		rotation = Matrix33(pEntity->GetWorldTM()) * rotation;
	}

	return rotation;
}
Exemple #14
0
//-------------------------------------------------------------------------
IMPLEMENT_RMI(CC4Projectile, ClStickToEntity)
{
	if(IEntity *pEntity = gEnv->pEntitySystem->GetEntity(params.targetId))
	{
		Matrix34 localMatrix;
		localMatrix.SetRotation33(Matrix33(params.localRotation));
		localMatrix.SetTranslation(params.localCollisonPos);
		StickToEntity(pEntity,localMatrix);
	}

	return true;
}
Exemple #15
0
void CPlayerView::ViewThirdPersonDirected(SViewParams &viewParams)
{
	if (m_in.thirdPersonYaw>0.001f)
	{
		viewParams.rotation *= Quat::CreateRotationXYZ(Ang3(0,0,m_in.thirdPersonYaw * gf_PI/180.0f));
		m_io.viewQuatFinal = Matrix33(viewParams.rotation);
	}

	if (m_io.bUsePivot)			
		viewParams.position += m_io.viewQuatFinal.GetColumn1() * m_in.params_viewDistance + m_io.viewQuatFinal.GetColumn2() * (0.25f + m_in.params_viewHeightOffset);
	else
		viewParams.position += m_io.viewQuatFinal.GetColumn1() * -m_in.thirdPersonDistance + m_io.viewQuatFinal.GetColumn2() * (0.25f + m_in.params_viewHeightOffset);
}
Exemple #16
0
bool NounShip::read( const InStream & input )
{
	if (! NounBody::read( input ) )
		return false;

	// make sure we have all our traits after serialization
	if (! findTrait( TraitReplication::classKey() ) )
		attachTrait( new TraitReplication() );
	if (! findTrait( TraitMovement::classKey() ) )
		attachTrait( new TraitMovement() );
	if (! findTrait( TraitOrbit::classKey() ) )
		attachTrait( new TraitOrbit() );

	m_fHeading = m_fSetHeading = m_vOrientation.m_fYaw;
	m_fLastSetHeading = m_fSetHeading;
	m_fLastSetVelocity = m_fSetVelocity;
	m_fLastYaw = m_fYaw;

	// a bug caused these values to go NAN when all the drives were removed from the ship
#if defined(_WIN32)
	if ( _isnan( m_fHeading ) )
		m_fHeading = 0.0f;
	if ( _isnan( m_fVelocity ) )
		m_fVelocity = 0.0f;
#else
	if ( isnan( m_fHeading ) )
		m_fHeading = 0.0f;
	if ( isnan( m_fVelocity ) )
		m_fVelocity = 0.0f;
#endif

	// update the ship frame
	m_Frame = Matrix33( m_fPitch, m_fHeading, m_fRoll );

	initializeGadgets();
	initializeEnhancements();
	updateCharacter();
	updateDamageBits();

	// reset and reapply all modifiers
	resetModifiers();
	for(int i=0;i<m_Enhancements.size();++i)
		m_Enhancements[i]->applyModifiers( true );

	// until we add slots for enhancements, just set max to 8
	// TODO: Add 
	m_MaxEnhancements = 8;
	m_nIgnoreCollisionTick = 0;

	return true;
}
Exemple #17
0
//FIXME:use the animated character view filter for this
void CPlayerView::ViewFollowCharacterFirstPerson(SViewParams &viewParams)
{
	viewParams.viewID = 3;

	//to avoid clipping
	viewParams.nearplane = 0.1f;
	viewParams.position = m_in.entityWorldMatrix *m_in.localEyePos;

	if (m_in.stats_isRagDoll)
		viewParams.position.z += 0.05f;

	if (m_in.stats_followCharacterHead)
		viewParams.rotation = Quat(Matrix33(m_in.entityWorldMatrix)*m_in.headMtxLocal*Matrix33::CreateRotationY(gf_PI*0.5f));
}
Exemple #18
0
	void Run
	(
	)
	{
		Vector2 test = Vector2::One();

		Vector3 z = Cross(Vector3::Integer<1, 0, 0>(), Vector3::Integer<0, 1, 0>());

		Vector1 length = Length(Vector3::Integer<1>());
		Assert(length < Vector1::Integer<2>());

		Matrix33 testMat = Matrix33(Vector3::Integer<1, 2, 3>(), Vector3::Integer<4, 5, 6>(), Vector3::Integer<7, 8, 9>());
		Matrix33 testTran = Transpose(testMat);
	}
bool CCannonBall::RayTraceGeometry( const EventPhysCollision* pCollision, const Vec3& pos, const Vec3& hitDirection, SBackHitInfo* pBackHitInfo )
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	bool exitPointFound = false;

	IPhysicalEntity* pCollider = pCollision->pEntity[1];
	assert(pCollider);

	pe_params_part partParams;
	partParams.partid = pCollision->partid[1];
	pe_status_pos posStatus;

	if (pCollider->GetParams(&partParams) && pCollider->GetStatus(&posStatus))
	{
		if (partParams.pPhysGeom && partParams.pPhysGeom->pGeom)
		{
			geom_world_data geomWorldData;
			geomWorldData.R = Matrix33(posStatus.q*partParams.q);
			geomWorldData.offset = posStatus.pos + (posStatus.q * partParams.pos);
			geomWorldData.scale = posStatus.scale * partParams.scale;

			geom_contact *pContacts;
			intersection_params intersectionParams;
			IGeometry* pRayGeometry = s_pRayWrapper->GetRay(pos, hitDirection);
			const Vec3 hitDirectionNormalized = hitDirection.GetNormalized();

			{ WriteLockCond lock; 
			const int contactCount = partParams.pPhysGeom->pGeom->IntersectLocked(pRayGeometry,&geomWorldData,0,&intersectionParams,pContacts,lock);
			if (contactCount > 0)
			{
				float bestDistance = 10.0f;
				
				for (int i = (contactCount-1); (i >= 0) && (pContacts[i].t < bestDistance) && ((pContacts[i].n*hitDirectionNormalized) < 0); i--)
				{
					bestDistance = (float)pContacts[i].t;
					pBackHitInfo->pt = pContacts[i].pt;
					exitPointFound = true;
				}
			}
			} // lock
		}
	}

	s_pRayWrapper->ResetRay();

	return exitPointFound;
}
Exemple #20
0
void NodeScale::preRender( RenderContext & context, const Matrix33 & frame, const Vector3 & position )
{
	float t = context.time();
	float t2 = t * t;

	float x = (m_XV * t) + (( 0.5f * m_XA ) * t2) + 1.0f;
	float y = (m_YV * t) + (( 0.5f * m_YA ) * t2) + 1.0f;
	float z = (m_ZV * t) + (( 0.5f * m_ZA ) * t2) + 1.0f;

	m_Frame = Matrix33( Vector3(1,0,0) * x,
		Vector3(0,1,0) * y,
		Vector3(0,0,1) * z );

	// call the base class
	NodeTransform::preRender( context, frame, position );
}
int CScriptBind_Physics::SamplePhysEnvironment(IFunctionHandler *pH)
{
	int nEnts,i,nHits=0,objtypes = ent_static|ent_rigid|ent_sleeping_rigid|ent_sort_by_mass;
	pe_status_nparts snp; 
	pe_status_pos sp;
	IPhysicalEntity **pEnts;
	geom_world_data gwd;
	IGeometry *pSphere;
	primitives::sphere sph;
	intersection_params ip;
	geom_contact *pcontacts;
	IPhysicalWorld *pWorld = m_pSystem->GetIPhysicalWorld();
	IEntity *pEntity;
	SmartScriptTable pObj(m_pSS);
	ip.bStopAtFirstTri=ip.bNoBorder=ip.bNoAreaContacts = true;
	ip.bThreadSafe = true;

	if (!pH->GetParams(sph.center,sph.r))
		return pH->EndFunction();
	if (pH->GetParamCount()>2)
		pH->GetParam(3,objtypes);
	pSphere = pWorld->GetGeomManager()->CreatePrimitive(primitives::sphere::type,&sph);

	nEnts = pWorld->GetEntitiesInBox(sph.center-Vec3(sph.r),sph.center+Vec3(sph.r),pEnts,objtypes);
	for(i=0;i<nEnts;i++) for(sp.ipart=pEnts[i]->GetStatus(&snp)-1;sp.ipart>=0;sp.ipart--)
	{
		sp.partid=-1; pEnts[i]->GetStatus(&sp);
		gwd.offset=sp.pos; gwd.R=Matrix33(sp.q); gwd.scale=sp.scale;
		WriteLockCond lock;
		if ((sp.flagsOR & (geom_colltype0|geom_no_coll_response))==geom_colltype0 && sp.pGeomProxy->IntersectLocked(pSphere,&gwd,0,&ip,pcontacts,lock))
		{
			++nHits;
			if (pEntity = (IEntity*)pEnts[i]->GetForeignData(PHYS_FOREIGN_ID_ENTITY))
				pObj->SetAt(nHits*3-2, pEntity->GetScriptTable());
			else
				pObj->SetNullAt(nHits*3-2);
			pObj->SetAt(nHits*3-1, sp.partid);
			pObj->SetAt(nHits*3, pWorld->GetPhysicalEntityId(pEnts[i]));
			if (pEnts[i]->GetType()!=PE_ARTICULATED)
				break;
		}
	}
	pSphere->Release();

	return pH->EndFunction(*pObj);	
}
//------------------------------------------------------------------------
void CVehicleActionDeployRope::AttachOnRope(IEntity *pEntity)
{
	assert(pEntity);

	if(!pEntity)
		return;

	IRopeRenderNode *pRopeUpper = GetRopeRenderNode(m_ropeUpperId);

	if(!pRopeUpper)
		return;

	assert(pRopeUpper->GetPointsCount() >= 2);

	IPhysicalEntity *pRopePhys = pRopeUpper->GetPhysics();
	assert(pRopePhys);

	typedef std::vector <Vec3> TVec3Vector;
	TVec3Vector points;

	int pointCount;

	pe_status_rope ropeStatus;

	if(pRopePhys->GetStatus(&ropeStatus))
		pointCount = ropeStatus.nSegments + 1;
	else
		pointCount = 0;

	if(pointCount < 2)
		return;

	points.resize(pointCount);
	ropeStatus.pPoints = &points[0];

	if(pRopePhys->GetStatus(&ropeStatus))
	{
		Matrix34 worldTM;
		worldTM.SetIdentity();
		worldTM = Matrix33(m_pVehicle->GetEntity()->GetWorldTM());
		worldTM.SetTranslation(ropeStatus.pPoints[1]);
		pEntity->SetWorldTM(worldTM);
	}

	pRopeUpper->LinkEndEntities(m_pVehicle->GetEntity()->GetPhysics(), pEntity->GetPhysics());
}
//------------------------------------------------------------------------
const Matrix33 &CItem::GetSlotHelperRotation(int slot, const char *helper, bool worldSpace, bool relative)
{
	// if mounted force the slot to be 1st person
	if(m_stats.mounted)
		slot=eIGS_FirstPerson;

	static Matrix33 rotation;
	rotation.SetIdentity();

	IEntity *pEntity = GetEntity();

	if(!pEntity)
		return rotation;

	SEntitySlotInfo info;

	if(pEntity->GetSlotInfo(slot, info))
	{
		if(info.pStatObj)
		{
			IStatObj *pStatObj = info.pStatObj;
			rotation = Matrix33(pStatObj->GetHelperTM(helper));
			rotation.OrthonormalizeFast();
			rotation = Matrix33(GetEntity()->GetSlotLocalTM(slot, false))*rotation;
		}
		else if(info.pCharacter)
		{
			ICharacterInstance *pCharacter = info.pCharacter;

			if(!pCharacter)
				return rotation;

			int16 id = pCharacter->GetISkeletonPose()->GetJointIDByName(helper);

			//	if (id > -1) rotation = Matrix33(pCharacter->GetISkeleton()->GetAbsJMatrixByID(id));
			if(id > -1)
			{
				if(relative)
					rotation = Matrix33(pCharacter->GetISkeletonPose()->GetRelJointByID(id).q);
				else
					rotation = Matrix33(pCharacter->GetISkeletonPose()->GetAbsJointByID(id).q);
			}

			if(!relative)
				rotation = Matrix33(pEntity->GetSlotLocalTM(slot, false))*rotation;
		}
	}

	if(worldSpace)
		rotation=Matrix33(pEntity->GetWorldTM())*rotation;

	return rotation;
}
void CubeMapManager::UpdateCameraOrientation( int face )
{
	Vector3 vDir, vUp, vRight;

	switch(face)
	{
	case 0: vRight = Vector3( 0, 0,-1); vUp = Vector3( 0, 1, 0); vDir = Vector3( 1, 0, 0); break; // pos-x
	case 1: vRight = Vector3( 0, 0, 1); vUp = Vector3( 0, 1, 0); vDir = Vector3(-1, 0, 0); break; // neg-x
	case 2: vRight = Vector3( 1, 0, 0); vUp = Vector3( 0, 0,-1); vDir = Vector3( 0, 1, 0); break; // pos-y
	case 3: vRight = Vector3( 1, 0, 0); vUp = Vector3( 0, 0, 1); vDir = Vector3( 0,-1, 0); break; // neg-y
	case 4: vRight = Vector3( 1, 0, 0); vUp = Vector3( 0, 1, 0); vDir = Vector3( 0, 0, 1); break; // pos-z
	case 5: vRight = Vector3(-1, 0, 0); vUp = Vector3( 0, 1, 0); vDir = Vector3( 0, 0,-1); break; // neg-z
	default:
		break;
	}

	m_Camera.SetOrientation( Matrix33( vRight, vUp, vDir ) );
}
//------------------------------------------------------------------------
void CVehicleActionEntityAttachment::Update(const float deltaTime)
{
	if(m_isAttached)
		return;

	IEntitySystem *pEntitySystem = gEnv->pEntitySystem;
	assert(pEntitySystem);

	IEntity *pEntity = pEntitySystem->GetEntity(m_entityId);

	if(!pEntity)
		return;

	IPhysicalEntity *pPhysEntity = pEntity->GetPhysics();

	if(!pPhysEntity)
		return;

	pe_simulation_params paramsSim;
	float gravity;

	if(pPhysEntity->GetParams(&paramsSim))
		gravity = abs(paramsSim.gravity.z);
	else
		gravity = 9.82f;

	pe_status_dynamics dyn;

	if(pPhysEntity->GetStatus(&dyn))
	{
		pe_action_impulse impulse;
		impulse.impulse  = Matrix33(pEntity->GetWorldTM()) * Vec3(0.0f, 0.0f, 1.0f) * g_parachuteForce * gravity;
		impulse.impulse = impulse.impulse - dyn.v;
		impulse.impulse *= dyn.mass * deltaTime;
		impulse.iSource = 3;

		pPhysEntity->Action(&impulse);
	}

	m_timer -= deltaTime;

	if(m_timer <= 0.0f || dyn.v.z >= 0.0f)
		m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_NoUpdate);
}
void CStickyProjectile::NetSetStuck(CProjectile* pProjectile, bool stuck)
{
	if(stuck && ((m_flags&eSF_IsStuck)==0))
	{
		IEntity* pTargetEntity = gEnv->pEntitySystem->GetEntity(m_parentId);
		if(pTargetEntity)
		{
			if(ICharacterInstance* pTargetCharacter = pTargetEntity->GetCharacter(0))
			{
				const char* boneName = pTargetCharacter->GetICharacterModel()->GetICharacterModelSkeleton()->GetJointNameByID(m_stuckJoint);
				if(AttachToCharacter(pProjectile, *pTargetEntity, *pTargetCharacter, boneName))
				{
					IActor* pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pTargetEntity->GetId());
					m_flags |= eSF_IsStuck;
					m_flags |= pActor ? pActor->IsPlayer() ? eSF_StuckToPlayer : eSF_StuckToAI : 0;
					m_childId = pProjectile->GetEntityId();
				}
			}
		}
		if((m_flags&eSF_IsStuck)==0)
		{
			IEntity* pProjectileEntity = pProjectile->GetEntity();
			AttachTo(pProjectile, pTargetEntity);
			m_childId = pProjectileEntity->GetId();
			if(pTargetEntity) //If we have a parent then the stuck position/rotation are local to the parent
			{
				pProjectileEntity->SetPos(m_stuckPos);
				pProjectileEntity->SetRotation(m_stuckRot);
			}
			else if(m_flags&eSF_OrientateToCollNormal)
			{
				Matrix34 mat;
				mat.SetTranslation(m_stuckPos);
				mat.SetRotation33(Matrix33(m_stuckRot));
				pProjectileEntity->SetWorldTM(mat);
			}
			else
			{
				pProjectileEntity->SetPos(m_stuckPos);
			}
			m_flags |= eSF_IsStuck;
		}
	}
}
CRRCMath::Matrix33 CRRCMath::Quaternion_002::initFromEuler(CRRCMath::Vector3 eul)
{
    Matrix33 mat2;

    double s0 = sin(eul.r[0]);
    double c0 = cos(eul.r[0]);
    double s1 = sin(eul.r[1]);
    double c1 = cos(eul.r[1]);
    double s2 = sin(eul.r[2]);
    double c2 = cos(eul.r[2]);

    // Berechnung der Matrix A aus [1], S.12, Formel (2.1)
    // Damit gilt mat2 * v_local = v_body
    mat2 = Matrix33(c1*c2,          s2*c1,          -s1,
                    c2*s1*s0-s2*c0, s2*s1*s0+c2*c0, c1*s0,
                    c2*s1*c0+s2*s0, s2*s1*c0-c2*s0, c1*c0);

    return(mat2);
}
Exemple #28
0
//-----------------------------------------------------------------------
void CVehiclePartLight::UpdateLight(const float frameTime)
{ 
  if (m_slot == -1)
    return;

	// move to vehicle event change view?
  if (m_diffuseMult[0] != m_diffuseMult[1])
  {
    SEntitySlotInfo info;
    if (m_pVehicle->GetEntity()->GetSlotInfo(m_slot, info) && info.pLight)
    {
      CDLight& light = info.pLight->GetLightProperties();    

      IActor* pActor = CCryAction::GetCryAction()->GetClientActor();
      bool localPlayer = (pActor != NULL) && (pActor->GetLinkedVehicle() == m_pVehicle);

			IVehicleSeat* pSeat = pActor ? m_pVehicle->GetSeatForPassenger(pActor->GetEntityId()) : NULL;
			IVehicleView* pView = pSeat? pSeat->GetView(pSeat->GetCurrentView()) : NULL;
			bool isThirdPersonView = pView? pView->IsThirdPerson() : true;
      if (localPlayer && !isThirdPersonView)
				light.SetLightColor(ColorF(m_diffuseCol * m_diffuseMult[0], 1.f));
      else
				light.SetLightColor(ColorF(m_diffuseCol * m_diffuseMult[1], 1.f));    
    }
  }  

  if (m_pHelper)
  { 
    const static Matrix33 rot(Matrix33::CreateRotationXYZ(Ang3(0.f, 0.f, DEG2RAD(90.f))));
    
    Matrix34 helperTM;
		m_pHelper->GetVehicleTM(helperTM);
    Matrix34 localTM = Matrix33(helperTM) * rot;
    localTM.SetTranslation(helperTM.GetTranslation());

    GetEntity()->SetSlotLocalTM(m_slot, localTM);  
  }

}
void CActorControllerComponent::UpdateAnimation(float frameTime)
{
	if (auto* pPlayer = m_pActorComponent->GetPlayer())
	{
		// Radians / sec
		const float angularVelocityMin = 0.174f;

		// Update tags and motion parameters used for turning
		const bool isTurning = std::abs(m_yawAngularVelocity) > angularVelocityMin;

		// Resolve the animation tags.
		// HACK: This should be done once on init or on entity changed events or similar. It fails hard if the init order is switched with CAdvancedAnimationComponent.
		if ((m_rotateTagId == TAG_ID_INVALID) && (strlen(m_pAdvancedAnimationComponent->GetControllerDefinitionFile()) > 0))
			m_rotateTagId = m_pAdvancedAnimationComponent->GetTagId("Rotate");

		// Set the tag, if it exists.
		if (m_rotateTagId != TAG_ID_INVALID)
			m_pAdvancedAnimationComponent->SetTagWithId(m_rotateTagId, isTurning);

		if (isTurning)
		{
			// Expect the turning motion to take approximately one second.
			// TODO: Get to work on making this happen more like Blade and Soul.
			const float turnDuration = 1.0f;
			m_pAdvancedAnimationComponent->SetMotionParameter(eMotionParamID_TurnAngle, m_yawAngularVelocity * turnDuration);
		}

		// Update entity rotation as the player turns. We only want to affect Z-axis rotation, zero pitch and roll.
		// TODO: is there a case where we want to avoid zeroing out pitch and roll?
		Ang3 ypr = CCamera::CreateAnglesYPR(Matrix33(m_lookOrientation));
		ypr.y = 0;
		ypr.z = 0;
		const Quat correctedOrientation = Quat(CCamera::CreateOrientationYPR(ypr));

		// Send updated transform to the entity, only orientation changes.
		GetEntity()->SetPosRotScale(GetEntity()->GetWorldPos(), correctedOrientation, Vec3(1, 1, 1));
	}
}
void CBoundingContainer::HideContainedItems()
{
	IEntity* pEntity = GetEntity();
	if (pEntity)
	{
		// Proximity query all entities in area
		AABB aabbBounds(m_vBoundingMin, m_vBoundingMax);

		OBB	obbBounds;
		Matrix34	worldTM = pEntity->GetWorldTM();
		obbBounds.SetOBBfromAABB(Matrix33(worldTM), aabbBounds);
		aabbBounds.Reset();
		aabbBounds.SetAABBfromOBB(pEntity->GetWorldPos(), obbBounds);

		SEntityProximityQuery query;
		query.box = aabbBounds;
		gEnv->pEntitySystem->QueryProximity(query);
		const int iQueryCount = query.nCount;
		for (int i = 0; i < iQueryCount; ++i)
		{
			IEntity* pQueryEntity = query.pEntities[i];
			if (pQueryEntity)
			{
				const EntityId queryEntityId = pQueryEntity->GetId();
				
				if (!stl::find(m_hiddenEntities, queryEntityId)) // Only if not already hidden
				{
					// Make sure entity type should be hidden and entity pos is also inside, not just an intersection
					if (ShouldHide(queryEntityId, pQueryEntity) && aabbBounds.IsContainPoint(pQueryEntity->GetWorldPos()))
					{
						pQueryEntity->Hide(true);
						m_hiddenEntities.push_back(pQueryEntity->GetId());
					}
				}
			}
		}
	}
}