示例#1
0
void PhysXPhysics::VSyncVisibleScene()
{
	for (ActorIdToPysXRigidBodyTable::const_iterator it = m_actorRigidBodyMap.begin(); it != m_actorRigidBodyMap.end(); it++)
	{
		ActorId const id = it->first;

		PxTransform pxLoc = it->second->getGlobalPose();
		Mat4x4 loc;
		PxMatrixToMat4x4(PxMat44(pxLoc), &loc);
		
		Actor* pActor = g_pApp->m_pGame->VGetActor(id);
		if (pActor)
		{
			TransformComponent* pTransformComponent = pActor->GetComponent<TransformComponent>(TransformComponent::g_Name);

			if (pTransformComponent)
			{
				if (pTransformComponent->GetTransform() != loc)
				{
					Vec3 rot = loc.GetYawPitchRoll();
					pTransformComponent->SetPosition(loc.GetPosition());
					pTransformComponent->SetRotation(Vec3(XMConvertToDegrees(rot.x), XMConvertToDegrees(rot.y), XMConvertToDegrees(rot.z)));
					EventDataPtr pEvent(BE_NEW EvtData_Move_Actor(id, loc));
					IEventManager::Get()->VQueueEvent(pEvent);
				}
			}
		}
	}
}
示例#2
0
void SNSpatialComponent::setTransform( Vec3D const& pos , Quat const& q )
{
	Mat4x4 trans;
	trans.setTransform( pos , q );
	mSceneNode->setWorldTransform( trans );
	updatePhyicalCompTransform( trans );
}
示例#3
0
	void SquareObject::OnCreate() {

		CreateBuffers(m_Scale.x, m_Scale.y);

		//行列の定義
		Mat4x4 World;
		World.affineTransformation(
			m_Scale,
			Vec3(0, 0, 0),
			m_Qt,
			m_Pos
		);

		auto TexPtr = App::GetApp()->GetResource<TextureResource>(m_TextureResName);
		auto NormTexPtr = App::GetApp()->GetResource<TextureResource>(m_NormalTextureResName);

		m_PtrObj = make_shared<BcDrawObject>();
		m_PtrObj->m_MeshRes = m_SquareMesh;
		m_PtrObj->m_TextureRes = TexPtr;
		m_PtrObj->m_NormalTextureRes = NormTexPtr;
		m_PtrObj->m_WorldMatrix = World;
		m_PtrObj->m_Camera = GetStage<Stage>()->GetCamera();
		m_PtrObj->m_OwnShadowmapActive = true;
		m_PtrObj->m_SamplerState = SamplerState::LinearWrap;
		m_PtrObj->m_ShadowmapUse = false;
		m_PtrObj->m_FogEnabled = true;
		//フォグはきつめに
		m_PtrObj->m_FogColor = Col4(0.3f, 0.3f, 0.3f, 1.0f);
		m_PtrObj->m_FogStart = -10.0f;
		m_PtrObj->m_FogEnd = -30.0f;


	}
void BulletPhysics::CreateTrigger(WeakGameObjectPtr pGameObject, const Vec3& position, const float dim)
{
	StrongGameObjectPtr pStrongObject = MakeStrongPtr(pGameObject);
	if (!pStrongObject)
	{
		CB_ERROR("Must attach a game object to the trigger");
		return;
	}

	// create the collision body
	btBoxShape* boxShape = new btBoxShape(Vec3_to_btVector3(Vec3(dim, dim, dim)));

	// 0 mass, this trigger is not moveable
	const btScalar mass = 0;

	// set the initial position of the trigger from the object
	Mat4x4 triggerTransform = Mat4x4::Identity;
	triggerTransform.SetPosition(position);
	ObjectMotionState* motionState = CB_NEW ObjectMotionState(triggerTransform);

	// create the rigid body
	btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, motionState, boxShape, btVector3(0, 0, 0));
	btRigidBody* body = new btRigidBody(rbInfo);

	// add the body to the world
	m_DynamicsWorld->addRigidBody(body);

	// mark the body as a trigger so it does not physically collide with object
	body->setCollisionFlags(body->getCollisionFlags() | btRigidBody::CF_NO_CONTACT_RESPONSE);
	
	// update the maps
	m_ObjectIdToRigidBody[pStrongObject->GetId()] = body;
	m_RigidBodyToObjectId[body] = pStrongObject->GetId();
}
示例#5
0
void SNSpatialComponent::setOrientation( Quat const& q )
{
	Mat4x4 trans;
	trans.setTransform( mSceneNode->getWorldPosition() , q );
	mSceneNode->setWorldTransform( trans );
	updatePhyicalCompTransform( trans );
}
示例#6
0
	//初期化
	void BcStaticChara::OnCreate() {

		//Rigidbodyの初期化
		auto PtrGameStage = GetStage<GameStage>();
		Rigidbody body;
		body.m_Owner = GetThis<GameObject>();
		body.m_Mass = 1.0f;
		body.m_Scale = m_Scale;
		body.m_Quat = m_Qt;
		body.m_Pos = m_Pos;
		body.m_CollType = CollType::typeCAPSULE;
		body.m_IsFixed = true;
//		body.m_IsDrawActive = true;
		body.SetToBefore();
		PtrGameStage->AddRigidbody(body);

		//メッシュとトランスフォームの差分の設定
		m_MeshToTransformMatrix.affineTransformation(
			Vec3(1.0f, 1.0f, 1.0f),
			Vec3(0.0f, 0.0f, 0.0f),
			Vec3(0.0f, 0.0f, 0.0f),
			Vec3(0.0f, -1.0f, 0.0f)
		);
		//行列の定義
		Mat4x4 World;
		World.affineTransformation(
			m_Scale,
			Vec3(0, 0, 0),
			m_Qt,
			m_Pos
		);
		//差分を計算
		World = m_MeshToTransformMatrix * World;
		auto MeshPtr = App::GetApp()->GetResource<MeshResource>(L"MODEL_MESH");
		//描画データの構築
		m_PtrObj = make_shared<BcDrawObject>();
		m_PtrObj->m_OwnShadowmapActive = m_OwnShadowActive;
		m_PtrObj->m_UsedModelColor = false;
		m_PtrObj->m_UsedModelTextre = true;
		m_PtrObj->m_ShadowmapUse = true;
		m_PtrObj->m_FogEnabled = true;
		//フォグは黄色っぽく
		m_PtrObj->m_FogColor = Col4(0.5f, 0.5f, 0.1f, 1.0f);
		m_PtrObj->m_FogStart = -10.0f;
		m_PtrObj->m_FogEnd = -30.0f;
		m_PtrObj->m_MeshRes = MeshPtr;
		m_PtrObj->m_WorldMatrix = World;
		m_PtrObj->m_Camera = GetStage<Stage>()->GetCamera();

		//シャドウマップ描画データの構築
		m_PtrShadowmapObj = make_shared<ShadowmapObject>();
		m_PtrShadowmapObj->m_MeshRes = MeshPtr;
		//描画データの行列をコピー
		m_PtrShadowmapObj->m_WorldMatrix = World;
		m_PtrShadowmapObj->m_Camera = GetStage<Stage>()->GetCamera();


	}
///////////////////////////////////////////////
//Motion Blur
///////////////////////////////////////////////
AVOID DeferredRenderer::VGenerateVelocityMap(CameraPtr pCamera, Renderer* pRenderer, const Mat4x4 & viewproj)
{
	//set screen-aligned quad
	m_pVertices->Set(0, 0);

	//set shaders
	m_pVelocityMapShaders->VBind();

	//set shader resources
	m_gbuffer.BindPositionTex(0, ST_Pixel);

	//set render target
	m_pVelocityRTV->Set();

	//set constant buffers

	//bind matrix constant buffer to the pipeline
	Mat4x4 trans;
	//trans.CreateTranslation(pCamera->GetLookAt() + 10000 * pCamera->GetDir());
	trans.CreateTranslation(pCamera->GetPosition() + 500* pCamera->GetDir());

	Mat4x4 rot;
	rot = rot.CreateRollPitchYaw(pCamera->GetRoll(), pCamera->GetPitch(), pCamera->GetYaw());

	Mat4x4 WVP = rot * trans * pCamera->GetView() * CreateOrthoProjectionLH(SCREEN_WIDTH, SCREEN_HEIGHT, 1.0f, 1000.0f);
	WVP.Transpose();
	m_pMatrixBuffer->UpdateSubresource(0, NULL, &WVP, 0, 0);
	m_pMatrixBuffer->Set(0, ST_Vertex);

	//set previous frame view-projection transform
	Mat4x4 currViewProj = viewproj;
	Mat4x4 prevViewProj = pCamera->GetPrevView() * pCamera->GetPrevProjection();
	//prevViewProj = pCamera->GetView() * pCamera->GetProjection();
	//prevViewProj = pCamera->GetProjection();
	currViewProj.Transpose();
	prevViewProj.Transpose();
	//m_pcbPrevViewProj->UpdateSubresource(0, NULL, &prevViewProj, 0, 0);
	//m_pcbPrevViewProj->Set(0, ST_Pixel);

	struct TwoMatrices
	{
		Mat4x4 prevViewProj;
		Mat4x4 currViewProj;
	};
	TwoMatrices temp;
	temp.prevViewProj =prevViewProj;
	temp.currViewProj = currViewProj;

	m_pcbWorldPlusWVP->UpdateSubresource(0, nullptr, &temp, 0, 0);
	m_pcbWorldPlusWVP->Set(0, ST_Pixel);

	//Finally render velocity map
	Draw(6, 0);

	//unbind views
	UnbindShaderResourceViews(0, 1, ST_Pixel);
	UnbindRenderTargetViews(1);
}
示例#8
0
//
// TeapotWarsGame::VOnUpdate			- Chapter 19, page 709
//
void CometConquestGame::VOnUpdate(float time, float elapsedTime)
{
	int deltaMilliseconds = int(elapsedTime * 1000.0f);
	m_Lifetime += elapsedTime;
	unsigned int currentTime = timeGetTime();
	BaseGameLogic::VOnUpdate(time, elapsedTime);

	if (m_bProxy)
		return;

	switch(m_State)
	{
	case BGS_LoadingGameEnvironment:
		break;

	case BGS_MainMenu:
		break;

	case BGS_WaitingForPlayers:
		if (m_ExpectedPlayers + m_ExpectedRemotePlayers == m_HumanPlayersAttached ) 
		{
			VChangeState(BGS_LoadingGameEnvironment);
		}
		break;

	case BGS_Running:
		if(currentTime > (m_data.m_lastCometTime + 5000))
		{
			Vec4 at = -g_Right4 * 2.0f;
			Vec4 atWorld = Mat4x4::g_Identity.Xform(at);
			int randVertical = m_random.Random(115) + 1 - 60;
			Vec3 normalDir(atWorld);
			normalDir.Normalize();
			Mat4x4 temp = Mat4x4::g_Identity;
			temp.SetPosition(Vec3(110,10,randVertical));
			CometParams cp;
			cp.m_Pos = temp.GetPosition() + Vec3(atWorld);
			cp.m_Radius = 6.0f;
			cp.m_Color = g_Cyan;
			cp.m_NormalDir = normalDir;
			cp.m_Force = 40000.0f;

			const EvtData_Request_New_Actor cannonBallEvt( &cp );
			safeTriggerEvent( cannonBallEvt );
			m_data.m_lastCometTime = currentTime;
		}
		break;
	default:
		assert(0 && _T("Unrecognized state."));
	}

	// look in Chapter 15, page 563 for more on this bit of code
	if(m_pPhysics)
	{
		m_pPhysics->VOnUpdate(elapsedTime);
		m_pPhysics->VSyncVisibleScene();
	}
}
示例#9
0
//
// SkyNode::VPreRender				- Chapter 14, page 502
//
HRESULT SkyNode::VPreRender(Scene *pScene)
{
	Vec3 cameraPos = m_camera->VGet()->ToWorld().GetPosition();
	Mat4x4 mat = m_Props.ToWorld();
	mat.SetPosition(cameraPos);
	VSetTransform(&mat);

	return SceneNode::VPreRender(pScene);
}
示例#10
0
Vec Camera::GetLookAt() const
{
	Mat4x4 rot;
	rot = rot.CreateRollPitchYaw(m_roll, m_pitch, m_yaw);

	Vec lookAt;
	lookAt = m_pos + m_dir * rot;

	return lookAt;
}
示例#11
0
AVOID Light::VPrepareToGenerateShadowMap(const Mat4x4 & world, Renderer * pRenderer)
{
	//Set depth stencil view
	if (pRenderer->m_bVarianceShadows)
	{
		m_pVarianceShadowRTV->Set(*m_pShadowMapDSV);
		//m_pVarianceShadowRTV->Set();
	}
	else
	{
		SetDepthStencilView(m_pShadowMapDSV);
	}
	//GetRenderTargetView()->Set(*m_pShadowMapDSV);

	//set constant buffer with orthographic projection
	Vec pos = m_pData->m_pos * m_worldTransform;
	Vec dir = Vector(m_pData->m_dir.x, m_pData->m_dir.y, m_pData->m_dir.z, 0.0f);
	Mat4x4 view = CreateViewMatrixLH(pos, dir, Vector(0.0f, 1.0f, 0.0f, 0.0f));
	Mat4x4 ortho = CreateOrthoProjectionLH(m_iShadowMapWidth * 1.5f, m_iShadowMapHeight * 1.5f, 0.5f, m_r32Range);
	//Mat4x4 ortho = CreateOrthoProjectionLH(m_iShadowMapWidth, m_iShadowMapHeight, 2.0f, 60.0f);
	//Mat4x4 ortho = CreatePerspectiveProjectionLH( 0.25f * 3.14f, (AREAL)SCREEN_WIDTH / (AREAL)SCREEN_HEIGHT, 0.5f, 30.0f);
	
	m_view = view;
	m_viewProjection = view * ortho;

	Mat4x4 WVP = world * m_viewProjection;
	WVP.Transpose();

	if (pRenderer->m_bVarianceShadows)
	{
		Mat4x4 WorldView = world * view;
		WorldView.Transpose();

		struct MatrixBuffer
		{
			Mat4x4 WorldView;
			Mat4x4 WVP;
		};
		MatrixBuffer buffer;
		buffer.WorldView = WorldView;
		buffer.WVP = WVP;
		pRenderer->m_pcbWorldPlusWVP->UpdateSubresource(0, NULL, &buffer, 0, 0);
		pRenderer->m_pcbWorldPlusWVP->Set(0, ST_Vertex);
	}
	else
	{
		pRenderer->m_pcbWVP->UpdateSubresource(0, NULL, &WVP, 0, 0);
		pRenderer->m_pcbWVP->Set(0, ST_Vertex);
	}

	//Actually stores length of light frustum
	Vec frustumSize = Vector(m_r32Range - 0.5, m_r32Range -0.5, m_r32Range - 0.5, m_r32Range - 0.5 );
	pRenderer->m_pcbCameraPos->UpdateSubresource(0, NULL, &frustumSize, 0, 0);
	pRenderer->m_pcbCameraPos->Set(0, ST_Pixel);
}
示例#12
0
	//初期化
	void BoneChara::OnCreate() {

		//Rigidbodyの初期化
		auto PtrGameStage = GetStage<GameStage>();
		Rigidbody body;
		body.m_Owner = GetThis<GameObject>();
		body.m_Mass = 1.0f;
		body.m_Scale = m_Scale;
		body.m_Quat = m_Qt;
		body.m_Pos = m_Pos;
		body.m_CollType = CollType::typeCAPSULE;
		body.m_IsFixed = true;
//		body.m_IsDrawActive = true;
		body.SetToBefore();
		PtrGameStage->AddRigidbody(body);

		//メッシュとトランスフォームの差分の設定
		m_MeshToTransformMatrix.affineTransformation(
			Vec3(1.0f, 1.0f, 1.0f),
			Vec3(0.0f, 0.0f, 0.0f),
			Vec3(0.0f, 0.0f, 0.0f),
			Vec3(0.0f, -1.0f, 0.0f)
		);
		//行列の定義
		Mat4x4 World;
		World.affineTransformation(
			m_Scale,
			Vec3(0, 0, 0),
			m_Qt,
			m_Pos
		);
		//差分を計算
		World = m_MeshToTransformMatrix * World;
		auto MeshPtr = App::GetApp()->GetResource<MeshResource>(L"Chara_R_MESH");
		//描画データの構築
		m_PtrObj = make_shared<SimpleDrawObject>();
		m_PtrObj->m_MeshRes = MeshPtr;
		m_PtrObj->m_WorldMatrix = World;
		m_PtrObj->m_Camera = GetStage<Stage>()->GetCamera();
		m_PtrObj->m_UsedModelColor = false;
		m_PtrObj->m_UsedModelTextre = true;
		m_PtrObj->m_OwnShadowmapActive = m_OwnShadowActive;
		m_PtrObj->m_ShadowmapUse = true;
		m_PtrObj->BoneInit();
		m_PtrObj->AddAnimation(L"Default", 0, 100, true, 20.0f);
		m_PtrObj->ChangeCurrentAnimation(L"Default");

		//シャドウマップ描画データの構築
		m_PtrShadowmapObj = make_shared<ShadowmapObject>();
		m_PtrShadowmapObj->m_MeshRes = MeshPtr;
		//描画データの行列をコピー
		m_PtrShadowmapObj->m_WorldMatrix = World;
		m_PtrShadowmapObj->m_Camera = GetStage<Stage>()->GetCamera();

	}
示例#13
0
	//初期化
	void BcBoxObject::OnCreate() {

		//Rigidbodyの初期化
		auto PtrGameStage = GetStage<GameStage>();
		Rigidbody body;
		body.m_Owner = GetThis<GameObject>();
		body.m_Mass = 1.0f;
		body.m_Scale = m_Scale;
		body.m_Quat = m_Qt;
		body.m_Pos = m_Pos;
		body.m_CollType = CollType::typeOBB;
		body.m_IsFixed = true;
//		body.m_IsDrawActive = true;
		body.SetToBefore();
		PtrGameStage->AddRigidbody(body);


		//行列の定義
		Mat4x4 World;
		World.affineTransformation(
			body.m_Scale,
			Vec3(0, 0, 0),
			body.m_Quat,
			body.m_Pos
		);
		auto TexPtr = App::GetApp()->GetResource<TextureResource>(m_TextureResName);
		auto NormTexPtr = App::GetApp()->GetResource<TextureResource>(m_NormalTextureResName);
		//メッシュの取得
		auto MeshPtr = App::GetApp()->GetResource<MeshResource>(L"NORMAL_BOX");

		//描画データの構築
		m_PtrObj = make_shared<BcDrawObject>();
		m_PtrObj->m_MeshRes = MeshPtr;
		m_PtrObj->m_TextureRes = TexPtr;
		m_PtrObj->m_NormalTextureRes = NormTexPtr;
		m_PtrObj->m_WorldMatrix = World;
		m_PtrObj->m_Camera = GetStage<Stage>()->GetCamera();
		m_PtrObj->m_OwnShadowmapActive = true;
		m_PtrObj->m_ShadowmapUse = true;
		m_PtrObj->m_FogEnabled = true;
		//フォグは黄色っぽく
		m_PtrObj->m_FogColor = Col4(0.5f, 0.5f, 0.1f, 1.0f);
		m_PtrObj->m_FogStart = -10.0f;
		m_PtrObj->m_FogEnd = -30.0f;

		//シャドウマップ描画データの構築
		m_PtrShadowmapObj = make_shared<ShadowmapObject>();
		m_PtrShadowmapObj->m_MeshRes = MeshPtr;
		//描画データの行列をコピー
		m_PtrShadowmapObj->m_WorldMatrix = World;
		m_PtrShadowmapObj->m_Camera = GetStage<Stage>()->GetCamera();


	}
示例#14
0
Mat4x4 Anubis::CreateOrthoProjectionLH(	const AREAL width, const AREAL height,
										const AREAL nearZ,	const AREAL farZ)
{
	Mat4x4 mat;

	mat.Init(	Vector( 2.0f / width,			0,					0,					 0),
				Vector( 0,				 2.0f / height,				0,					 0),
				Vector( 0,						0,			1.0f / (farZ - nearZ),		 0),
				Vector( 0,						0,			nearZ / (nearZ - farZ),		 1) );

	return mat;
}
示例#15
0
	void Player::OnDrawShadowmap() {
		auto PtrGameStage = GetStage<GameStage>();
		//ワールド行列の決定
		Mat4x4 World;
		World.affineTransformation(m_Scale, Vec3(0, 0, 0),
			m_Qt, m_Pos);
		auto shptr = PtrGameStage->FindTagGameObject<ShadowmapDrawObject>(L"ShadowmapDrawObject");
		shptr->AddDrawMesh(
			m_SphereMesh,
			World
		);
	}
示例#16
0
void PhysXPhysics::AddShape(Actor* pActor, PxGeometry* geometry, float density, const std::string& physicsMaterial, bool gravityEnabled, float linearDamping, float angularDamping, const std::string& bodyType)
{
	BE_ASSERT(pActor);
	ActorId actorId = pActor->GetId();
	BE_ASSERTf(m_actorRigidBodyMap.find(actorId) == m_actorRigidBodyMap.end(), "Actor with more than one rigidbody");

	Mat4x4 transform = Mat4x4::g_Identity;
	
	TransformComponent* pTransformComponent = pActor->GetComponent<TransformComponent>(TransformComponent::g_Name);

	if (pTransformComponent)
	{
		transform = pTransformComponent->GetTransform();
	}
	else 
	{
		//Doesnt work without transform
		BE_ERROR("Actor %s PhysicsComponent requires Shape to have Transform Component: %d", actorId);
		return;
	}

	PhysicsMaterialData material(LookupMaterialData(physicsMaterial));
	PxMaterial* mat = m_pPhysicsSdk->createMaterial(material.m_friction, material.m_friction, material.m_restitution);

	Vec3 translation, scale;
	Quaternion rotation;
	
	bool ok = transform.Decompose(translation, rotation, scale);
	PxQuat pxRot;
	PxVec3 pxLoc;
	Vec3ToPxVec(translation, &pxLoc);
	QuaternionToPxQuat(rotation, &pxRot);
	PxTransform t(pxLoc, pxRot);

	if (bodyType == "Dynamic")
	{
		PxRigidDynamic* body = PxCreateDynamic(*m_pPhysicsSdk, t, *geometry, *mat, density);
		body->setActorFlag(PxActorFlag::eDISABLE_GRAVITY, !gravityEnabled);
		PxRigidBodyExt::updateMassAndInertia(*body, density);
		body->setLinearDamping(linearDamping);
		body->setAngularDamping(angularDamping);
		m_pScene->addActor(*body);

		m_actorRigidBodyMap[actorId] = body;
		m_rigidBodyActorMap[body] = actorId;
	}
	else
	{
		BE_ERROR("[Physics] BodyType not supported: %s", bodyType.c_str());
		return;
	}
}
示例#17
0
HRESULT SkyNode::PreRender(Scene* pScene)
{
	// get the camera position in world space
	Vec3 cameraPos = m_Camera->Get()->ToWorld().GetPosition();
	// get the sky node's world matrix
	Mat4x4 mat = m_Properties.ToWorld();

	// set the matrix's position to the camera position
	mat.SetPosition(cameraPos);
	SetTransform(&mat);

	return SceneNode::PreRender(pScene);
}
示例#18
0
void PhysicsComponent::VUpdate(int deltaMs)
{
    // get the transform component
    shared_ptr<TransformComponent> pTransformComponent = MakeStrongPtr(m_pOwner->GetComponent<TransformComponent>(TransformComponent::g_Name));
    if (!pTransformComponent)
    {
        GCC_ERROR("No transform component!");
        return;
    }

    // get the direction the object is facing
    Mat4x4 transform = pTransformComponent->GetTransform();

	if (m_acceleration != 0)
    {
        // calculate the acceleration this frame

        float accelerationToApplyThisFrame = m_acceleration / 1000.f * (float)deltaMs;

        // Get the current velocity vector and convert to a scalar.  The velocity vector is a combination of 
        // the direction this actor is going in and the speed of the actor.  The scalar is just the speed 
        // component.
        Vec3 velocity(m_pGamePhysics->VGetVelocity(m_pOwner->GetId()));
        float velocityScalar = velocity.Length();

		Vec3 direction(transform.GetDirection());
		m_pGamePhysics->VApplyForce(direction, accelerationToApplyThisFrame, m_pOwner->GetId());

        // logging
        // [rez] Comment this back in if you want to debug the physics thrust & rotation stuff.  It spams quite 
        // a bit of info the output window so I'm commenting it out for now.
/*
        GCC_LOG("Actor", "Acceleration: " + ToStr(accelerationToApplyThisFrame) + "; velocityScalar: " + ToStr(velocityScalar) + \
                "; direction: " + ToStr(direction) + "; direction.Length(): " + ToStr(direction.Length()) + \
                "; velocity: " + ToStr(velocity) + "; velocity.Length(): " + ToStr(velocity.Length()));
*/
    }

    if (m_angularAcceleration != 0)
    {
        // calculate the acceleration this frame
        float angularAccelerationToApplyThisFrame = m_angularAcceleration / 1000.f * (float)deltaMs;
		m_pGamePhysics->VApplyTorque(transform.GetUp(), angularAccelerationToApplyThisFrame, m_pOwner->GetId());

        // logging
        // [rez] Comment this back in if you want to debug the physics thrust & rotation stuff.  It spams quite 
        // a bit of info the output window so I'm commenting it out for now.
        //GCC_LOG("Actor", "Angular Acceleration: " + ToStr(angularAccelerationToApplyThisFrame) );
    }
}
示例#19
0
void PhysicsComponent::SetPosition(float x, float y, float z)
{
    shared_ptr<TransformComponent> pTransformComponent = MakeStrongPtr(m_pOwner->GetComponent<TransformComponent>(TransformComponent::g_Name));
    if (pTransformComponent)
    {
        Mat4x4 transform = pTransformComponent->GetTransform();
        Vec3 position = Vec3(x, y, z);
        transform.SetPosition(position);

        KinematicMove(transform);
    }
    else
        GCC_ERROR("Attempting to call RotateY() on actor with no trnasform component");
}
示例#20
0
/* ======================================
					Matrices
	========================================= */
Mat4x4 Anubis::CreateViewMatrixLH(const Vec & pos, const Vec & lookDir, const Vec & up)
{
	Mat4x4 mat;

	Vec & zaxis = Normalize(lookDir);
	Vec & xaxis = Normalize(cross(up, zaxis));
	Vec & yaxis = cross(zaxis, xaxis);

	mat.Init(	Vector( getx(xaxis), getx(yaxis), getx(zaxis), 0),
				Vector( gety(xaxis), gety(yaxis), gety(zaxis), 0),
				Vector( getz(xaxis), getz(yaxis), getz(zaxis), 0),
				Vector( -Dot(xaxis, pos), -Dot(yaxis, pos), -Dot(zaxis, pos), 1) );

	return mat;
}
示例#21
0
	void Player::OnDraw() {
		auto TexPtr = App::GetApp()->GetResource<TextureResource>(m_TextureResName);
		auto PtrGameStage = GetStage<GameStage>();
		//ワールド行列の決定
		Mat4x4 World;
		World.affineTransformation(m_Scale, Vec3(0, 0, 0),
			m_Qt, m_Pos);
		auto shptr = PtrGameStage->FindTagGameObject<PNTDrawObject>(L"PNTDrawObject");
		shptr->AddDrawMesh(
			m_SphereMesh,
			TexPtr,
			World,
			true
		);
	}
示例#22
0
	void BcSphereObject::OnCreate() {
		CreateBuffers();

		//Rigidbodyの初期化
		auto PtrGameStage = GetStage<GameStage>();
		Rigidbody body;
		body.m_Owner = GetThis<GameObject>();
		body.m_Mass = 1.0f;
		body.m_Scale = m_Scale;
		body.m_Quat = m_Qt;
		body.m_Pos = m_Pos;
		body.m_CollType = CollType::typeSPHERE;
		body.m_IsFixed = true;
//		body.m_IsDrawActive = true;
		body.SetToBefore();
		PtrGameStage->AddRigidbody(body);


		//行列の定義
		Mat4x4 World;
		World.affineTransformation(
			m_Scale,
			Vec3(0, 0, 0),
			m_Qt,
			m_Pos
		);
		auto TexPtr = App::GetApp()->GetResource<TextureResource>(m_TextureResName);
		//描画データの構築
		m_PtrObj = make_shared<BcDrawObject>();
		m_PtrObj->m_MeshRes = m_SphereMesh;
		m_PtrObj->m_TextureRes = TexPtr;
		m_PtrObj->m_WorldMatrix = World;
		m_PtrObj->m_Camera = GetStage<Stage>()->GetCamera();
		m_PtrObj->m_OwnShadowmapActive = false;
		m_PtrObj->m_ShadowmapUse = true;
		m_PtrObj->m_FogEnabled = true;
		//フォグは青色っぽく
		m_PtrObj->m_FogColor = Col4(0.4f, 0.4f, 0.8f, 1.0f);
		m_PtrObj->m_FogStart = -10.0f;
		m_PtrObj->m_FogEnd = -30.0f;

		//シャドウマップ描画データの構築
		m_PtrShadowmapObj = make_shared<ShadowmapObject>();
		m_PtrShadowmapObj->m_MeshRes = m_SphereMesh;
		//描画データの行列をコピー
		m_PtrShadowmapObj->m_WorldMatrix = World;
		m_PtrShadowmapObj->m_Camera = GetStage<Stage>()->GetCamera();
	}
示例#23
0
Quat	Util_L::GetOrientationQuat(const Vec3f &_front, const Vec3f &_baseUp, S32 _order[3])
{
	// orientation / sol
	Mat4x4	rot;
	Quat	qRot;
	Vec3f	vRight = _front ^  _baseUp;
	vRight.CNormalize();
	Vec3f	vUp = vRight ^ _front;
	vUp.CNormalize();	
	Vec3f	v[3] = { _front, vUp, vRight };	
	for (S32 i = 0;i < 3;i++)
		rot.GetRow(i) = Sign(_order[i]) * v[Abs(_order[i]) - 1];
	qRot = Quat(rot);
	qRot.Normalize();
	return qRot;
}
示例#24
0
/**
Gets a 3x3 matrix consisting of all cells besides those along the given row or column.
*/
Mat3x3 GetSubmatrix(const Mat4x4& m, int row, int col)
{
	int nextRow = 0;
	int nextColumn = 0;
	Mat3x3 result = Mat3x3::Zero();

	//we will loop through each element of our 4x4;
	//if the current element is valid (neither on the same row as [row] or column as [col])
	//then set Mat3x3(nextRow, nextColumn) and increment nextColumn
	//then increment nextRow
	//the last step might not be necessary
	for (int i = 0; i < MAT4X4_NUM_CELLS; i++)
	{
		//if this row is valid...
		if (i != row)
		{
			//reset nextColumn
			nextColumn = 0;
			for (int j = 0; j < MAT4X4_NUM_CELLS; j++)
			{
				if (j != col)
				{
					result(nextRow, nextColumn) = m.AtCoordinate(i, j);
					nextColumn++;
				}
			}
			//move nextRow down a row
			nextRow++;
		}
	}
	return result;
}
示例#25
0
/**
Gets the adjoint matrix: The transpose of the matrix's cofactor.
*/
Mat4x4 Adjoint(const Mat4x4& m)
{
	//Another huge pain!
	//Build a new 4x4 matrix from cofactors.
	//C(i, j) = (-1)^(i+j)*det(submatrix(i,j))
	Mat4x4 result = Mat4x4::Zero();
	for (int i = 0; i < MAT4X4_NUM_CELLS; i++)
	{
		for (int j = 0; j < MAT4X4_NUM_CELLS; j++)
		{
			result(i, j) = pow(-1.0f, i + j) * GetSubmatrix(m, i, j).Determinant();
		}
	}
	result.Transpose();
	return result;
}
///////////////////////////////////////////////
//Ambient occlusion
///////////////////////////////////////////////
AVOID DeferredRenderer::CalculateAmbientOcclusion(CameraPtr pCamera)
{
	m_pSSAOShaders->VBind();

	m_pVertices->Set(0, 0);

	//bind matrix constant buffer to the pipeline
	Mat4x4 trans;
	trans.CreateTranslation(pCamera->GetLookAt());

	Mat4x4 rot;
	rot = rot.CreateRollPitchYaw(pCamera->GetRoll(), pCamera->GetPitch(), pCamera->GetYaw());

	Mat4x4 WVP = rot * trans * pCamera->GetView() * CreateOrthoProjectionLH(SCREEN_WIDTH, SCREEN_HEIGHT, 0.1f, 1000.0f);
	WVP.Transpose();
	m_pMatrixBuffer->UpdateSubresource(0, NULL, &WVP, 0, 0);
	m_pMatrixBuffer->Set(0, ST_Vertex);

	//camera params
	Vec cameraParams = Vector(pCamera->GetFrustum().GetNearWidth(), pCamera->GetFrustum().GetNearHeight(), 0.0f, 0.0f);
	m_pcbFrustumSize->UpdateSubresource(0, NULL, &cameraParams, 0, 0);
	m_pcbFrustumSize->Set(0, ST_Pixel);

	//depth buffer params
	Vec depthBufferParams = Vector(1.0f / SCREEN_WIDTH, 1.0f / SCREEN_HEIGHT, 0.0f, 0.0f);
	m_pcbDepthBuffer->UpdateSubresource(0, NULL, &depthBufferParams, 0, 0);
	m_pcbDepthBuffer->Set(1, ST_Pixel); 

	//camera view matrix
	Mat4x4 View = pCamera->GetView();
	View.Transpose();
	m_pcbView->UpdateSubresource(0, NULL, &View, 0, 0);
	m_pcbView->Set(2, ST_Pixel);

	//send SSAO params
	//Vec ssaoParams = Vector(20.0f, 2.0f, 5.0f, 2.0f);
	//m_pcbSSAOParams->UpdateSubresource(0, NULL, &ssaoParams, 0, 0);
	//m_pcbSSAOParams->Set(2, ST_Pixel);
	
	m_pDepthDisableStencilDisable->Set(0);
	//m_pDepthSRV->Set(0, ST_Pixel);
	m_gbuffer.m_SRVList.SetView(2, 0, ST_Pixel);
	m_gbuffer.m_SRVList.SetView(5, 1, ST_Pixel);
	m_pSSAORTV->Set();
	
	//set sampler states
	//AnisotropySampler16()->Set(0, ST_Pixel);
	PointClampSampler()->Set(0, ST_Pixel);
	D3D11DeviceContext()->Draw(6, 0);

	//Unbind render target view
	UnbindRenderTargetViews(1);

	//m_pSSAOSRV->Set(5, ST_Pixel); 
	UnbindShaderResourceViews(0, 2, ST_Pixel);
	GetRenderTargetView()->Set(); 
}
示例#27
0
void PhysicsComponent::RotateY(float angleRadians)
{
    shared_ptr<TransformComponent> pTransformComponent = MakeStrongPtr(m_pOwner->GetComponent<TransformComponent>(TransformComponent::g_Name));
    if (pTransformComponent)
    {
        Mat4x4 transform = pTransformComponent->GetTransform();
        Vec3 position = transform.GetPosition();

        Mat4x4 rotateY;
        rotateY.BuildRotationY(angleRadians);
        rotateY.SetPosition(position);

        KinematicMove(rotateY);
    }
    else
        GCC_ERROR("Attempting to call RotateY() on actor with no transform component");
}
bool TransformComponent::Init(TiXmlElement* pData)
{
	CB_ASSERT(pData);

	Vec3 yawPitchRoll = m_Transform.GetYawPitchRoll();
	yawPitchRoll.x = RADIANS_TO_DEGREES(yawPitchRoll.x);
	yawPitchRoll.y = RADIANS_TO_DEGREES(yawPitchRoll.y);
	yawPitchRoll.z = RADIANS_TO_DEGREES(yawPitchRoll.z);

	Vec3 position = m_Transform.GetPosition();

	TiXmlElement* pPositionElement = pData->FirstChildElement("Position");
	if (pPositionElement)
	{
		double x = 0;
		double y = 0;
		double z = 0;
		pPositionElement->Attribute("x", &x);
		pPositionElement->Attribute("y", &y);
		pPositionElement->Attribute("z", &z);
		position = Vec3(x, y, z);
	}

	TiXmlElement* pOrientationElement = pData->FirstChildElement("YawPitchRoll");
	if (pOrientationElement)
	{
		double yaw = 0;
		double pitch = 0;
		double roll = 0;
		pOrientationElement->Attribute("x", &yaw);
		pOrientationElement->Attribute("y", &pitch);
		pOrientationElement->Attribute("z", &roll);
		yawPitchRoll = Vec3(yaw, pitch, roll);
	}

	Mat4x4 translation;
	translation.BuildTranslation(position);

	Mat4x4 rotation;
	rotation.BuildYawPitchRoll((float)DEGREES_TO_RADIANS(yawPitchRoll.x), (float)DEGREES_TO_RADIANS(yawPitchRoll.y), (float)DEGREES_TO_RADIANS(yawPitchRoll.z));

	m_Transform = rotation * translation;

	return true;
}
//Update the state
AVOID ShadowTestState::VUpdate( Game * pGame, AREAL64 r64Time, AREAL64 r64ElapsedTime )
{
	m_pScene->VUpdate(r64Time, r64ElapsedTime);

	//update light
	AREAL diffX = r64ElapsedTime * 5.0f;
	Vec trans = Vector(40.0f*Cos(r64Time), 8, 40.0f*Sin(r64Time), 1);
	//Vec trans = Vector(-15, -2.0f, -8.0f, 1);
	Mat4x4 tr;
	tr.CreateTranslation(trans);

	SpotLightEntity* pLight = static_cast<SpotLightEntity*>(&*m_pLight);
	pLight->SetCurrentTransform(tr, r64Time);

	Vec dir = Normalize(Vector(0.0f, 0.0f, 0.0f, 1.0f) - trans);
	pLight->SetDirection(dir);
	//pLight->SetDirection( Vector(0.4f, -0.5f, 0.8f, 2.0f) );
}
示例#30
-4
int InternalScriptExports::CreateActor(const char* actorArchetype, LuaPlus::LuaObject luaPosition, LuaPlus::LuaObject luaYawPitchRoll)
{

    if (!luaPosition.IsTable())
    {
	    GCC_ERROR("Invalid object passed to CreateActor(); type = " + std::string(luaPosition.TypeName()));
		return INVALID_ACTOR_ID;
	}

    if (!luaYawPitchRoll.IsTable())
    {
	    GCC_ERROR("Invalid object passed to CreateActor(); type = " + std::string(luaYawPitchRoll.TypeName()));
		return INVALID_ACTOR_ID;
	}

	Vec3 pos(luaPosition["x"].GetFloat(), luaPosition["y"].GetFloat(), luaPosition["z"].GetFloat());
	Vec3 ypr(luaYawPitchRoll["x"].GetFloat(), luaYawPitchRoll["y"].GetFloat(), luaYawPitchRoll["z"].GetFloat());

	Mat4x4 initialTransform;
	initialTransform.BuildYawPitchRoll(ypr.x, ypr.y, ypr.z);
	initialTransform.SetPosition(pos);

	TiXmlElement *overloads = NULL;
	StrongActorPtr pActor = g_pApp->m_pGame->VCreateActor(actorArchetype, overloads, &initialTransform);

	if (pActor)
	{
		shared_ptr<EvtData_New_Actor> pNewActorEvent(GCC_NEW EvtData_New_Actor(pActor->GetId()));
		IEventManager::Get()->VQueueEvent(pNewActorEvent);
		return pActor->GetId();
	}

	return INVALID_ACTOR_ID;
}