Exemplo n.º 1
0
void BoneModel::createBone(){

	auto& bones = mBoneAssetDataPtr->GetFileData().GetBoneData().mBoneBuffer;
	auto& boneName = mBoneAssetDataPtr->GetFileData().GetBoneData().mBoneName;

	DWORD mBoneNum = bones.size();
	mBone.clear();
	mIk.clear();
	mBone.resize(mBoneNum);

	DWORD ikCount = 0;
	for (DWORD i = 0; i < mBoneNum; i++){
		auto& bone = bones[i];


		mBone[i].mStrName = boneName[i];
		mBone[i].mHierarchy.mIdxSelf = i;
		mBone[i].mHierarchy.mIdxParent = bone.parent_bidx;
		if (bone.parent_bidx >= (int)mBoneNum) mBone[i].mHierarchy.mIdxParent = UINT(-1);


		XMVECTOR head_pos = XMVectorSet(bone.bone_head_pos[0], bone.bone_head_pos[1], bone.bone_head_pos[2], 0.0f);
		XMVECTOR parent_pos = { 0, 0, 0, 1 };
		if (mBone[i].mHierarchy.mIdxParent < (int)mBoneNum){
			UINT p = mBone[i].mHierarchy.mIdxParent;
			parent_pos = XMVectorSet(bones[p].bone_head_pos[0], bones[p].bone_head_pos[1], bones[p].bone_head_pos[2], 0.0f);
		}

		XMVECTOR local_pos = XMVectorSubtract(head_pos, parent_pos);

		mBone[i].mPos = XMFLOAT3(XMVectorGetX(local_pos), XMVectorGetY(local_pos), XMVectorGetZ(local_pos));
		mBone[i].mScale = XMFLOAT3(1.0f, 1.0f, 1.0f);
		XMVECTOR q = XMQuaternionIdentity();
		mBone[i].mRot = XMFLOAT4(XMVectorGetX(q), XMVectorGetY(q), XMVectorGetZ(q), XMVectorGetW(q));

		//ワールド行列計算
		XMVECTOR scale = { 1, 1, 1, 1 };
		mBone[i].mMtxPose = SRTMatrix(scale, q, local_pos);
		if (mBone[i].mHierarchy.mIdxParent < (int)mBoneNum){
			mBone[i].mMtxPose = XMMatrixMultiply(mBone[i].mMtxPose, mBone[mBone[i].mHierarchy.mIdxParent].mMtxPose);
		}
		if (bone.bone_flag & pmx::t_bone::BIT_IK){
			mBone[i].mIkBoneIdx = (WORD)bone.t_ik_data_idx;

			createIk(ikCount, i);
			ikCount++;
		}
		else{
			mBone[i].mIkBoneIdx = 0;
		}


		mBone[i].mMtxPoseInit = mBone[i].mMtxPose;

	}
}
    void FirstPersonCamera::Update(const GameTime& gameTime)
    {
		XMFLOAT2 movementAmount = Vector2Helper::Zero;
        if (mKeyboard != nullptr)
        {
            if (mKeyboard->IsKeyDown(DIK_W))
            {
                movementAmount.y = 1.0f;
            }

            if (mKeyboard->IsKeyDown(DIK_S))
            {
                movementAmount.y = -1.0f;
            }

            if (mKeyboard->IsKeyDown(DIK_A))
            {
                movementAmount.x = -1.0f;
            }

            if (mKeyboard->IsKeyDown(DIK_D))
            {
                movementAmount.x = 1.0f;
            }
        }

        XMFLOAT2 rotationAmount = Vector2Helper::Zero;
        if ((mMouse != nullptr) && (mMouse->IsButtonHeldDown(MouseButtons::Left)))
        {
            LPDIMOUSESTATE mouseState = mMouse->CurrentState();			
            rotationAmount.x = -mouseState->lX * mMouseSensitivity;
            rotationAmount.y = -mouseState->lY * mMouseSensitivity;
        }

		float elapsedTime = (float)gameTime.ElapsedGameTime();
        XMVECTOR rotationVector = XMLoadFloat2(&rotationAmount) * mRotationRate * elapsedTime;
        XMVECTOR right = XMLoadFloat3(&mRight);

        XMMATRIX pitchMatrix = XMMatrixRotationAxis(right, XMVectorGetY(rotationVector));
        XMMATRIX yawMatrix = XMMatrixRotationY(XMVectorGetX(rotationVector));

        ApplyRotation(XMMatrixMultiply(pitchMatrix, yawMatrix));

        XMVECTOR position = XMLoadFloat3(&mPosition);
		XMVECTOR movement = XMLoadFloat2(&movementAmount) * mMovementRate * elapsedTime;

		XMVECTOR strafe = right * XMVectorGetX(movement);
        position += strafe;

        XMVECTOR forward = XMLoadFloat3(&mDirection) * XMVectorGetY(movement);
        position += forward;
        
        XMStoreFloat3(&mPosition, position);

        Camera::Update(gameTime);
    }
Exemplo n.º 3
0
VOID DebugDraw::DrawObb( const OrientedBox& obb, D3DCOLOR Color )
{
    XMMATRIX matWorld = XMMatrixRotationQuaternion( XMLoadFloat4( &obb.Orientation ) );
    XMMATRIX matScale = XMMatrixScaling( obb.Extents.x, obb.Extents.y, obb.Extents.z );
    matWorld = XMMatrixMultiply( matScale, matWorld );
    XMVECTOR position = XMLoadFloat3( &obb.Center );
    matWorld.r[3] = XMVectorSelect( matWorld.r[3], position, XMVectorSelectControl( 1, 1, 1, 0 ) );

    DrawCubeWireframe( matWorld, Color );
}
Exemplo n.º 4
0
void BatchRenderer::DrawOBB( const rxOOBB& box, const FColor& color )
{
	XMMATRIX matWorld = XMMatrixRotationQuaternion( XMLoadFloat4( &box.Orientation ) );
	XMMATRIX matScale = XMMatrixScaling( box.Extents.x, box.Extents.y, box.Extents.z );
	matWorld = XMMatrixMultiply( matScale, matWorld );
	XMVECTOR position = XMLoadFloat3( &box.Center );
	matWorld.r[3] = XMVectorSelect( matWorld.r[3], position, XMVectorSelectControl( 1, 1, 1, 0 ) );

	DrawCube( matWorld, color );
}
Exemplo n.º 5
0
void Terrain::DrawShadowMap(const Camera& cam)
{
	ID3D11DeviceContext* dc = pDeviceContext;

	dc->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
	dc->IASetInputLayout(InputLayouts::Terrain);

	UINT stride = sizeof(Vertex::Terrain);
    UINT offset = 0;

    dc->IASetVertexBuffers(0, 1, &mQuadPatchVB, &stride, &offset);
	dc->IASetIndexBuffer(mQuadPatchIB, DXGI_FORMAT_R16_UINT, 0);

	XMMATRIX view = XMLoadFloat4x4(&d3d->m_LightView);
	XMMATRIX proj = XMLoadFloat4x4(&d3d->m_LightProj);
	XMMATRIX viewProj = XMMatrixMultiply(view, proj);
	XMMATRIX world  = XMLoadFloat4x4(&mWorld);
	XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world);
	XMMATRIX worldViewProj = world*viewProj;
	XMMATRIX ShadowTransform = world * XMLoadFloat4x4(&d3d->m_ShadowTransform);
	XMFLOAT4 worldPlanes[6];
	ExtractFrustumPlanes(worldPlanes, cam.ViewProj());

	// Set per frame constants.
	
	Effects::TerrainFX->SetViewProj(viewProj);
	Effects::TerrainFX->SetEyePosW(cam.GetPosition());
	Effects::TerrainFX->SetMinDist(20.0f);
	Effects::TerrainFX->SetMaxDist(400.0f);
	Effects::TerrainFX->SetMinTess(0.0f);
	Effects::TerrainFX->SetMaxTess(3.0f);
	Effects::TerrainFX->SetTexelCellSpaceU(1.0f / mInfo.HeightmapWidth);
	Effects::TerrainFX->SetTexelCellSpaceV(1.0f / mInfo.HeightmapHeight);
	Effects::TerrainFX->SetWorldCellSpace(mInfo.CellSpacing);
	Effects::TerrainFX->SetWorldFrustumPlanes(worldPlanes);

	Effects::TerrainFX->SetHeightMap(mHeightMapSRV);
	Effects::TerrainFX->SetShadowMap(d3d->GetShadowMap());
	Effects::TerrainFX->SetShadowTransform(ShadowTransform);

	ID3DX11EffectTechnique* tech = Effects::TerrainFX->TessBuildShadowMapTech;
    D3DX11_TECHNIQUE_DESC techDesc;
    tech->GetDesc( &techDesc );

    for(UINT i = 0; i < techDesc.Passes; ++i)
    {
        ID3DX11EffectPass* pass = tech->GetPassByIndex(i);
		pass->Apply(0, dc);

		dc->DrawIndexed(mNumPatchQuadFaces*4, 0, 0);
	}	
	
	//dc->HSSetShader(0, 0, 0);
	//dc->DSSetShader(0, 0, 0);
}
Exemplo n.º 6
0
void CGLImpl::InitializeMatrices() {
	projection_matrix.dirty = 1;
	projection_matrix.stackdepth = 0;
	projection_matrix.usage = MATPROJECTION;

	modelview_matrix.dirty = 1;
	modelview_matrix.stackdepth = 0;
	modelview_matrix.usage = MATMODELVIEW;

	depth_fix = XMMatrixMultiply(XMMatrixTranslation(0, 0, 1), XMMatrixScaling(1, 1, 0.5));
}
Exemplo n.º 7
0
XMVECTOR LimitAngle(const XMVECTOR& quat, const XMVECTOR& rotmin, const XMVECTOR& rotmax)
{
	XMVECTOR rot_xyz = GetAngle(quat);
	/*	XMMATRIX mtx = XMMatrixRotationQuaternion(quat);

	//ZYX Y=-90〜90°Y軸=ねじり方向
	float rx = -atan2f(XMVectorGetY(mtx.r[2]),XMVectorGetZ(mtx.r[2]));
	float ry = asinf(XMVectorGetX(mtx.r[2]));
	float rz = -atan2f(XMVectorGetX(mtx.r[1]),XMVectorGetX(mtx.r[0]));
	XMVECTOR rot_xyz = {rx,ry,rz,0};
	*rotang_before = rot_xyz;
	*/
	rot_xyz = XMVectorMax(rot_xyz, rotmin);
	rot_xyz = XMVectorMin(rot_xyz, rotmax);
	XMMATRIX mtx = XMMatrixRotationZ(XMVectorGetZ(rot_xyz));
	mtx = XMMatrixMultiply(mtx, XMMatrixRotationY(XMVectorGetY(rot_xyz)));
	mtx = XMMatrixMultiply(mtx, XMMatrixRotationX(XMVectorGetX(rot_xyz)));

	return XMQuaternionRotationMatrix(mtx);
}
Exemplo n.º 8
0
/**
 *	Multiplies this matrix by another matrix.
 *
 *	@param mOther The matrix to multiply by.
 *  @return self
 */
CFMat4x4&	CFMat4x4::operator *=	( CFMat4x4Arg mOther )
{
	//Get referances of type XMMATRIX to our CFMat4x4 classes.
	XMMATRIX& matA = *reinterpret_cast<XMMATRIX*>( this );
	const XMMATRIX& matB = *reinterpret_cast<const XMMATRIX*>( &mOther );

	//Do the multiplication
	matA = XMMatrixMultiply( matA, matB ) ;

	return *this;
}
Exemplo n.º 9
0
XMMATRIX MathHelper::WorldToBillboard(const XMMATRIX &source, XMFLOAT3 eyePos)
{
	XMMATRIX billboardMatrix;
	float angle;
	XMFLOAT3 pos;
	XMStoreFloat3(&pos, source.r[3]);

	angle = atan2(pos.x - eyePos.x, pos.z - eyePos.z);
	billboardMatrix = source;
	billboardMatrix = XMMatrixMultiply(billboardMatrix, XMMatrixRotationY(XMConvertToRadians( angle)));
	return billboardMatrix;
}
Exemplo n.º 10
0
//--------------------------------------------------------------------------------------------------------------------
void RDX11RenderHelper::RenderPlane(XMMATRIX& tm, CVector2 size)
{
	XMMATRIX mtWorld = XMMatrixMultiply( tm, XMMatrixScaling(size.x, size.y, 1) );

	SetWorldTM(mtWorld);

	GLOBAL::ShaderMgr()->Begin(SHADER_QUAD_VS, SHADER_TEXURE_PS);
	
	GLOBAL::RenderStateMgr()->SetTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
	GLOBAL::RenderStateMgr()->SetVertexInput(FVF_QUAD);
	GLOBAL::D3DContext()->Draw(4, 0);
}
Exemplo n.º 11
0
//--------------------------------------
//姿勢行列更新
void BoneModel::UpdatePose()
{

	DWORD mBoneNum = mBone.size();
	for (DWORD mid = 0; mid < mBoneNum; mid++){
		//ワールド行列計算
		mBone[mid].mMtxPose = SQTMatrix(FloatToVector(mBone[mid].mScale), FloatToVector(mBone[mid].mRot), FloatToVector(mBone[mid].mPos));
		if (mBone[mid].mHierarchy.mIdxParent < mBoneNum){
			mBone[mid].mMtxPose = XMMatrixMultiply(mBone[mid].mMtxPose, mBone[mBone[mid].mHierarchy.mIdxParent].mMtxPose);
		}
	}
}
Exemplo n.º 12
0
Shape::Shape(HINSTANCE hInstance)
:	D3DApplication(hInstance),
	mShapeVB(nullptr),
	mShapeIB(nullptr),
	mFX(nullptr),
	mTech(nullptr),
	mfxWorldViewProj(nullptr),
	mInputLayout(nullptr),
	mWireframeRS(nullptr),
	mTheta(1.5f*MathHelper::Pi),
	mPhi(0.1f*MathHelper::Pi),
	mRadius(15.0f)
{
	mMainWndCaption = L"Shape Demo";

	mLastMousePos.x = 0;
	mLastMousePos.y = 0;

	XMMATRIX I = XMMatrixIdentity();
	XMStoreFloat4x4(&mGridWorld, I);
	XMStoreFloat4x4(&mView, I);
	XMStoreFloat4x4(&mProj, I);

	XMMATRIX boxScale = XMMatrixScaling(2.0f, 1.0f, 2.0f);
	XMMATRIX boxOffset = XMMatrixTranslation(0.0f, 0.5f, 0.0f);
	XMStoreFloat4x4(&mBoxWorld, XMMatrixMultiply(boxScale, boxOffset));

	XMMATRIX centerSphereScale = XMMatrixScaling(2.0f, 2.0f, 2.0f);
	XMMATRIX centerSphereOffset = XMMatrixTranslation(0.0f, 2.0f, 0.0f);
	XMStoreFloat4x4(&mCenterSphereWorld, XMMatrixMultiply(centerSphereScale, centerSphereOffset));

	for ( int i = 0; i < 5; i++ )
	{
		XMStoreFloat4x4(&mCylinderWorld[i * 2 + 0], XMMatrixTranslation(-5.0f, 1.5f, -10.0f + i*5.0f));
		XMStoreFloat4x4(&mCylinderWorld[i * 2 + 1], XMMatrixTranslation(+5.0f, 1.5f, -10.0f + i*5.0f));

		XMStoreFloat4x4(&mSphereWorld[i * 2 + 0], XMMatrixTranslation(-5.0f, 3.5f, -10.0f + i*5.0f));
		XMStoreFloat4x4(&mSphereWorld[i * 2 + 1], XMMatrixTranslation(+5.0f, 3.5f, -10.0f + i*5.0f));
	}
}
Exemplo n.º 13
0
int DuckHuntMain::pick(float x, float y, std::vector<BasicModelInstance> models)
{

	XMMATRIX P = mCam.Proj();

	// Compute picking ray in view space.
	int newWidth, newHeight;
	float fs;

	 newWidth = mScreenViewport.Width; 
	 newHeight = mScreenViewport.Height; 
	 fs = 1.0f; 


	float vx = (+2.0f*x / newWidth - fs) / P(0, 0);
	float vy = (-2.0f*y / newHeight + fs) / P(1, 1);


	// Ray definition in view space.
	XMVECTOR rayOrigin = XMVectorSet(0.0f, 0.0f, 0.0f, 1.0f);
	XMVECTOR rayDir = XMVectorSet(vx, vy, 1.0f, 0.0f);

	// Tranform ray to local space of Mesh.
	XMMATRIX V = mCam.View();
	XMMATRIX invView = XMMatrixInverse(&XMMatrixDeterminant(V), V);


	for (unsigned i = 0; i < models.size(); ++i)
	{
		XMMATRIX W = XMLoadFloat4x4(&models[i].World);
		XMMATRIX invWorld = XMMatrixInverse(&XMMatrixDeterminant(W), W);

		XMMATRIX toLocal = XMMatrixMultiply(invView, invWorld);

		rayOrigin = XMVector3TransformCoord(rayOrigin, toLocal);
		rayDir = XMVector3TransformNormal(rayDir, toLocal);

		// Make the ray direction unit length for the intersection tests.
		rayDir = XMVector3Normalize(rayDir);

		float tmin = 0.0f; // The Returned Distance
		if (XNA::IntersectRayAxisAlignedBox(rayOrigin, rayDir, &models[i].Model->collisionBox, &tmin))
		{

			//WE ARE IN THE MESH .. DO WHATEVER YOU WANT
			return i;
		}

	}
	return -1;

}
Exemplo n.º 14
0
void CGLImpl::CheckDirtyMatrix(xe_matrix_t *m) {
	if (m->dirty)
	{
		/** Hack **/
		if(m->usage == MATPROJECTION) {
			XMMATRIX mat = XMMatrixMultiply(m->stack[m->stackdepth], depth_fix);
			device->SetVertexShaderConstantF(m->usage, (float*)&mat, 4);
		} else {
			device->SetVertexShaderConstantF(m->usage, (float*)&m->stack[m->stackdepth], 4);
		}
		m->dirty = 0;
	}
}
Exemplo n.º 15
0
/**
 *	@param mOther The matrix to transform by.
 *	@return A matrix that performs the transforms in this matrix then the 
 *			transforms in mOther.
 */
CFMat4x4	CFMat4x4::GetPostTransformedBy( CFMat4x4Arg mOther ) const
{
	//Create the CFMat4x4 to return.
	CFMat4x4 matReturn;

	const XMMATRIX& matA = *reinterpret_cast<const XMMATRIX*>( this );
	const XMMATRIX& matB = *reinterpret_cast<const XMMATRIX*>( &mOther );
	XMMATRIX& matResult = *reinterpret_cast<XMMATRIX*>( &matReturn );

	matResult = XMMatrixMultiply( matA, matB );

	return matReturn; 
}
Exemplo n.º 16
0
void render()
{
	UINT stride = sizeof(Vertex);
	UINT offset = 0;

	//XMVECTOR Eye = XMVectorSet(cos(t)*5.0f, 2.0f, sin(t)*5.0f, 0.0f);
	XMVECTOR Eye = XMVectorSet(g_R * sin(g_Theta) * cos(g_Phi), g_R * sin(g_Phi), g_R * cos(g_Theta) * cos(g_Phi), 1.0f);
	XMVECTOR At = XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f);
	XMVECTOR Up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
	g_View = XMMatrixLookAtLH(Eye, At, Up);

	cBufferShader1 cb1;
	cb1.mWorld = XMMatrixTranspose(XMMatrixIdentity());
	cb1.mView = XMMatrixTranspose(g_View);
	cb1.mProjection = XMMatrixTranspose(g_Projection);
	cb1.color = XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f);
	cb1.LightDir = XMFLOAT3(0.0f, -1.0f, -1.0f);
	XMStoreFloat3(&cb1.EyePos, Eye);
	XMStoreFloat3(&cb1.EyeDir, At - Eye);

	XMMATRIX A = cb1.mWorld;
	//A.r[3] = XMVectorSet(0.0f, 0.0f, 0.0f, 1.0f);

	XMVECTOR det = XMMatrixDeterminant(A);
	cb1.mWorldInvTrans = XMMatrixInverse(&det, A);

	g_pImmediateContext->UpdateSubresource(g_pcBufferShader1, 0, NULL, &cb1, 0, 0);

	float ClearColor[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
	g_pImmediateContext->ClearRenderTargetView(g_pRenderTargetView, ClearColor);
	g_pImmediateContext->ClearDepthStencilView(g_pDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0);

	g_pImmediateContext->IASetVertexBuffers(0, 1, &g_pVertexBuffer, &stride, &offset);
	g_pImmediateContext->IASetIndexBuffer(g_pIndexBuffer, DXGI_FORMAT_R16_UINT, 0);

	g_pImmediateContext->VSSetShader(g_pVertexShader, NULL, 0);
	g_pImmediateContext->VSSetConstantBuffers(0, 1, &g_pcBufferShader1);
	g_pImmediateContext->PSSetConstantBuffers(0, 1, &g_pcBufferShader1);
	g_pImmediateContext->PSSetShader(g_pPixelShader, NULL, 0);

	for (int i = 0; i < Spheres.size(); i++)
	{
		cb1.mWorld = XMMatrixTranspose(XMMatrixMultiply(XMMatrixScaling(Spheres[i].Radius, Spheres[i].Radius, Spheres[i].Radius), XMMatrixTranslation(Spheres[i].Position.x, Spheres[i].Position.y, Spheres[i].Position.z)));
		cb1.color = Spheres[i].Color;
		g_pImmediateContext->UpdateSubresource(g_pcBufferShader1, 0, NULL, &cb1, 0, 0);
		g_pImmediateContext->DrawIndexed(num_sphere_indices, 0, 0);
	}

	g_pSwapChain->Present(0, 0);
}
Exemplo n.º 17
0
void GuardianSystemDemo::Render()
{
    // Get current eye pose for rendering
    double eyePoseTime = 0;
    ovrPosef eyePose[ovrEye_Count] = {};
    ovr_GetEyePoses(mSession, mFrameIndex, ovrTrue, mHmdToEyeOffset, eyePose, &eyePoseTime);

    // Render each eye
    for (int i = 0; i < ovrEye_Count; ++i) {
        int renderTargetIndex = 0;
        ovr_GetTextureSwapChainCurrentIndex(mSession, mTextureChain[i], &renderTargetIndex);
        ID3D11RenderTargetView* renderTargetView = mEyeRenderTargets[i][renderTargetIndex];
        ID3D11DepthStencilView* depthTargetView = mEyeDepthTarget[i];

        // Clear and set render/depth target and viewport
        DIRECTX.SetAndClearRenderTarget(renderTargetView, depthTargetView, 0.2f, 0.2f, 0.2f, 1.0f);
        DIRECTX.SetViewport((float)mEyeRenderViewport[i].Pos.x, (float)mEyeRenderViewport[i].Pos.y, 
            (float)mEyeRenderViewport[i].Size.w, (float)mEyeRenderViewport[i].Size.h);

        // Eye
        XMVECTOR eyeRot = XMVectorSet(eyePose[i].Orientation.x, eyePose[i].Orientation.y, 
            eyePose[i].Orientation.z, eyePose[i].Orientation.w);
        XMVECTOR eyePos = XMVectorSet(eyePose[i].Position.x, eyePose[i].Position.y, eyePose[i].Position.z, 0);
        XMVECTOR eyeForward = XMVector3Rotate(XMVectorSet(0, 0, -1, 0), eyeRot);

        // Matrices
        XMMATRIX viewMat = XMMatrixLookAtRH(eyePos, XMVectorAdd(eyePos, eyeForward), 
            XMVector3Rotate(XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f), eyeRot));
        ovrMatrix4f proj = ovrMatrix4f_Projection(mEyeRenderLayer.Fov[i], 0.001f, 1000.0f, ovrProjection_None);
        XMMATRIX projMat = XMMatrixTranspose(XMMATRIX(&proj.M[0][0]));
        XMMATRIX viewProjMat = XMMatrixMultiply(viewMat, projMat);

        // Render and commit to swap chain
        mDynamicScene.Render(&viewProjMat, 1.0f, 1.0f, 1.0f, 1.0f, true);
        ovr_CommitTextureSwapChain(mSession, mTextureChain[i]);

        // Update eye layer
        mEyeRenderLayer.ColorTexture[i] = mTextureChain[i];
        mEyeRenderLayer.RenderPose[i] = eyePose[i];
        mEyeRenderLayer.SensorSampleTime = eyePoseTime;
    }

    // Submit frames
    ovrLayerHeader* layers = &mEyeRenderLayer.Header;
    ovrResult result = ovr_SubmitFrame(mSession, mFrameIndex++, nullptr, &layers, 1);
    if (!OVR_SUCCESS(result)) {
        printf("ovr_SubmitFrame failed"); exit(-1);
    }
}
Exemplo n.º 18
0
/**
 *	Divides this matrix by another matrix.
 *
 *	@param mOther The matrix to multiply by.
 *  @return self.
 */
CFMat4x4&	CFMat4x4::operator /=	( CFMat4x4Arg mOther )
{
	XMVECTOR vDeterminant;

	XMMATRIX& matA = *reinterpret_cast<XMMATRIX*>( this );
	const XMMATRIX& matB = *reinterpret_cast<const XMMATRIX*>( &mOther );
		
	//Get the inverse of the matrix:
	matA = XMMatrixInverse( &vDeterminant, matA );
	
	//Multiply by the other matrix:
	matA = XMMatrixMultiply( matA, matB );

	return *this;
}
void SpriteSheet::RenderSprite( GameSprite* sprite, ID3D11DeviceContext* d3dContext, ID3D11Buffer* vertexBuffer, ID3D11Buffer* mvpCB, XMMATRIX* vpMatrix )
{
	XMMATRIX world = sprite->GetWorldMatrix( );
	XMMATRIX mvp = XMMatrixMultiply( world, *vpMatrix );
	mvp = XMMatrixTranspose( mvp );

	d3dContext->UpdateSubresource( mvpCB, 0, 0, &mvp, 0, 0 );
	d3dContext->VSSetConstantBuffers( 0, 1, &mvpCB );

	// draw the current sprite
	map<string, vector<XMFLOAT2>>::iterator a = animationMap_.find( sprite->GetCurrentAnimation( ) );
	map<string, float>::iterator f = durationMap_.find( sprite->GetCurrentAnimation( ) );

	// don't draw if the animation is not in the map
	if( a != animationMap_.end( ) )
	{
		unsigned int currentSprite = sprite->GetCurrentSprite( );

		if ( f != durationMap_.end( ) && f->second != -1)
		{
			float frameTime = sprite->GetFrameTime( );

			frameTime += game_->GetDeltaTime( );
			if( frameTime >= f->second )
			{
				currentSprite++;

				if( currentSprite >= a->second.size( ) )
				{
					currentSprite = 0;
				}

				// set the current sprite to the next one in the animation
				sprite->SetCurrentSprite( currentSprite );

				frameTime = 0.0f;
			}

			sprite->SetFrameTime( frameTime );

			// add delta time to the time since this sprite has been on this animation
			sprite->SetChangeAnimationTime( sprite->GetChangeAnimationTime( ) + game_->GetDeltaTime( ) );
		}

		// draw the first sprite in the animtation (background animations only have one sprite per animation)
		activate_ = DrawSprite( a->second.at( currentSprite ).x, a->second.at( currentSprite ).y, sprite->GetWidth( ), sprite->GetHeight( ), sheetWidth_, sheetHeight_, d3dContext, vertexBuffer );
	}
}
Exemplo n.º 20
0
//--------------------------------------------------------------------------------------------------------------------
void RDX11RenderHelper::RenderSphere(CVector3* pos, float radius)
{	
	XMMATRIX mtWorld = XMMatrixIdentity();

	mtWorld	= XMMatrixMultiply( mtWorld, XMMatrixScaling(radius, radius, radius) );
	mtWorld.r[3].x = pos->x;
	mtWorld.r[3].y = pos->y;
	mtWorld.r[3].z = pos->z;


	SetWorldTM(mtWorld);

	GLOBAL::ShaderMgr()->Begin(SHADER_POS_VS, SHADER_COLOR_PS);
	GLOBAL::RenderStateMgr()->SetRasterizer(RASTERIZER_WIRE);
	GLOBAL::RDevice()->GetRenderStrategy()->RenderGeometry(&m_Sphere);
}
Exemplo n.º 21
0
/**
 *	Multiplies a matrix by another matrix, and returns the resulting matrix.
 *
 *	@param mOther The matrix to multiply by.
 *  @return Returns the result of the multiplication as a matrix.
 */
CFMat4x4	CFMat4x4::operator *	( CFMat4x4Arg mOther ) const
{
	//Create the CFMat4x4 to return.
	CFMat4x4 matReturn;

	//Get referances of type XMMATRIX to our CFMat4x4 classes.
	const XMMATRIX& matA = *reinterpret_cast<const XMMATRIX*>( this );
	const XMMATRIX& matB = *reinterpret_cast<const XMMATRIX*>( &mOther );
	XMMATRIX& matResult = *reinterpret_cast<XMMATRIX*>( &matReturn );

	//Do the multiplication
	matResult = XMMatrixMultiply( matA, matB ) ;

	//Return the temp matrix.
	return matReturn;
}
Exemplo n.º 22
0
    void Skeleton::RecursiveProcess(float time, Bone& bone, Animation& anim, MatrixBuffer& buffer, TrackBuffer& trackData, XMFLOAT4X4 parentTransform)
    {
        VQS vqs;

        anim.CalculateTransform(time, bone.BoneIndex, vqs, trackData[bone.BoneIndex]);

        XMFLOAT4X4 localTransform = vqs.GetMatrix();
        XMFLOAT4X4 modelTransform; // = localTransform  * parentTransform;
        XMStoreFloat4x4(&modelTransform, XMMatrixMultiply(XMLoadFloat4x4(&localTransform), XMLoadFloat4x4(&parentTransform)));
        buffer[bone.BoneIndex] = modelTransform;

        for (UINT i = 0; i < bone.Children.size(); ++i)
        {
            RecursiveProcess(time, *bone.Children[i], anim, buffer, trackData, modelTransform);
        }
    }
Exemplo n.º 23
0
/*****************************************************************
* GetWorldVelocty():	Returns World Velocity
*
* Ins:					N/A
*
* Outs:					XMFLOAT3 - World Velocity
*
* Returns:				N/A
*
* Mod. Date:			8/20/2015
* Mod. Initials:		MZ
*****************************************************************/
XMFLOAT3 IObject::GetWorldVelocity()
{
	XMFLOAT4X4 oldWorldMAtrix = m_mWorld;

	XMMATRIX d3dTranslateZ = XMMatrixTranslation(m_f3Velocity.x, m_f3Velocity.y, m_f3Velocity.z);

	XMFLOAT4X4 newWorld;
	XMStoreFloat4x4(&newWorld, XMMatrixMultiply(d3dTranslateZ, XMLoadFloat4x4(&m_mWorld)));

	XMFLOAT3 f3VelocityUpdate;
	f3VelocityUpdate.x = newWorld._41 - oldWorldMAtrix._41;
	f3VelocityUpdate.y = newWorld._42 - oldWorldMAtrix._42;
	f3VelocityUpdate.z = newWorld._43 - oldWorldMAtrix._43;

	return f3VelocityUpdate;
}
Exemplo n.º 24
0
//Needs to be called befor all other drawcalls, and ended with "EndDraw()"
void DirectXGraphicEngine::BeginDraw()
{
	if (m_IsDrawing)
	{
		Logger::Log( "Rendering call Begin was called before end was called", "DirectXRenderSystem", LoggerType::MSG_ERROR );
		return;
	}

	//clear the backbuffer, and depthstencil buffer
	float t_Black[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
	m_DeviceContext->ClearRenderTargetView(m_RenderTargetView, t_Black);
	m_DeviceContext->ClearDepthStencilView(m_DepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0);

	//clear gbuffers
	for (int i = 0; i < 3; i++)
	{
		m_DeviceContext->ClearRenderTargetView(m_GBufferRTV[i], t_Black);
	}

	m_IsDrawing = true;

	UINT t_Strides = sizeof(XMFLOAT4X4);
	UINT t_Offsets = 0;

	m_DeviceContext->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	m_DeviceContext->IASetVertexBuffers(1, 1, &m_InstanceBuffer, &t_Strides, &t_Offsets);



	//update viewmatrix
	DirectXMatrixLibrary* t_MatrixLib = (DirectXMatrixLibrary*)t_MatrixLib->GetInstance();

	UINT t_Size = m_View.size();
	for (size_t i = 0; i < t_Size; i++)
	{
		PerFrameCBuffer t_PFB;
		t_PFB.View = *t_MatrixLib->GetMatrix(m_View.at(i).camera.transformMatrixHandle);
		t_PFB.Proj = *t_MatrixLib->GetMatrix(m_View.at(i).camera.projectionMatrixHandle);
		XMMATRIX t_View = XMLoadFloat4x4(&t_PFB.View);
		XMMATRIX t_Proj = XMLoadFloat4x4(&t_PFB.Proj);
		XMMATRIX t_ViewProj = XMMatrixMultiply(t_View, t_Proj);
		XMStoreFloat4x4(&t_PFB.ViewProj, t_ViewProj);
		
		m_DeviceContext->UpdateSubresource(m_PerFrameCBuffer, 0, nullptr, &t_PFB, 0, 0);
	}
	
}
Exemplo n.º 25
0
void SpriteRenderer::RenderText(const SpriteFont& font,
                                const WCHAR* text,
            				    const XMMATRIX& transform,
                                const XMFLOAT4& color)
{
    D3DPERF_BeginEvent(0xFFFFFFFF, L"SpriteRenderer RenderText");

    size_t length = wcslen(text);

    XMMATRIX textTransform = XMMatrixIdentity();

    UINT64 numCharsToDraw = min(length, MaxBatchSize);
    UINT64 currentDraw = 0;
    for (UINT64 i = 0; i < numCharsToDraw; ++i)
    {
        WCHAR character = text[i];
        if(character == ' ')
            textTransform._41 += font.SpaceWidth();
        else if(character == '\n')
        {
            textTransform._42 += font.CharHeight();
            textTransform._41 = 0;
        }
        else
        {
            SpriteFont::CharDesc desc = font.GetCharDescriptor(character);

            textDrawData[currentDraw].Transform = XMMatrixMultiply(textTransform, transform);
            textDrawData[currentDraw].Color = color;
            textDrawData[currentDraw].DrawRect.x = desc.X;
            textDrawData[currentDraw].DrawRect.y = desc.Y;
            textDrawData[currentDraw].DrawRect.z = desc.Width;
            textDrawData[currentDraw].DrawRect.w = desc.Height;
            currentDraw++;

            textTransform._41 += desc.Width + 1;
        }
    }

    // Submit a batch
    RenderBatch(font.SRView(), textDrawData, currentDraw);

    D3DPERF_EndEvent();

    if(length > numCharsToDraw)
        RenderText(font, text + numCharsToDraw, textTransform, color);
}
Exemplo n.º 26
0
void JF::Component::SkyBox::Render()
{
	// Declear)
	float blendFactors[] = { 0.0f, 0.0f, 0.0f, 0.0f };

	// 컴포넌트에 카메라가 없거나 메인카메라가 아니라면 패스.
	Camera* pCamera = GetOwner()->GetComponent<Camera>();
	if (pCamera == nullptr || Camera::g_pMainCamera != pCamera)
		return;

	// 
	Transform* pTransform = GetOwner()->GetComponent<Transform>();
	if (pTransform == nullptr)
		return;

	// Set Layout And Topology
	gRENDERER->DeviceContext()->IASetInputLayout(m_pInputLayout);
	gRENDERER->DeviceContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	// Set VertexBuffer And IndexBuffer
	UINT stride = m_Stride;
	UINT offset = 0;
	gRENDERER->DeviceContext()->IASetVertexBuffers(0, 1, &m_pVB, &stride, &offset);
	gRENDERER->DeviceContext()->IASetIndexBuffer(m_pIB, DXGI_FORMAT_R32_UINT, 0);

	// center Sky about eye in world space
	XMFLOAT3 eyePos = pTransform->GetPosition();
	XMMATRIX T = XMMatrixTranslation(eyePos.x, eyePos.y, eyePos.z);

	XMMATRIX WVP = XMMatrixMultiply(T, pCamera->GetViewProj());
	Effects::CubeMapFX->SetWorldViewProj(WVP);
	Effects::CubeMapFX->SetCubeMap(m_pMainTexture->GetTexture());

	ID3DX11EffectTechnique* tech = Effects::CubeMapFX->SkyTech;
	D3DX11_TECHNIQUE_DESC techDesc;
	tech->GetDesc(&techDesc);
	for (UINT p = 0; p < techDesc.Passes; ++p)
	{
		tech->GetPassByIndex(p)->Apply(0, gRENDERER->DeviceContext());

		gRENDERER->DeviceContext()->DrawIndexed(m_IndexCount, 0, 0);
	}

	// 기본 랜더상태로 복원한다.
	gRENDERER->DeviceContext()->RSSetState(0);
	gRENDERER->DeviceContext()->OMSetBlendState(0, blendFactors, 0xffffffff);
}
Exemplo n.º 27
0
//-----------------------------------------------------------------------------
// Name: Frame::UpdateCachedWorldTransformIfNeeded()
//-----------------------------------------------------------------------------
VOID Frame::UpdateCachedWorldTransformIfNeeded()
{
    if( IsCachedWorldTransformDirty() )
    {
        if( m_pParent )
        {
            m_pParent->UpdateCachedWorldTransformIfNeeded();
            m_CachedWorldTransform = XMMatrixMultiply( m_LocalTransform, m_pParent->m_CachedWorldTransform );
            m_CachedWorldBound = m_LocalBound * m_CachedWorldTransform;
        }
        else
        {
            m_CachedWorldTransform = m_LocalTransform;
            m_CachedWorldBound = m_LocalBound * m_CachedWorldTransform;
        }
    }
}
AmbientOcclusionApp::AmbientOcclusionApp(HINSTANCE hInstance)
: D3DApp(hInstance), mSkullVB(0), mSkullIB(0), mSkullIndexCount(0)
{
	mMainWndCaption = L"Ambient Occlusion";
	
	mLastMousePos.x = 0;
	mLastMousePos.y = 0;

	mCam.SetPosition(0.0f, 5.0f, -5.0f);
	mCam.LookAt(
		XMFLOAT3(-4.0f, 4.0f, -4.0f),
		XMFLOAT3(0.0f, 2.2f, 0.0f),
		XMFLOAT3(0.0f, 1.0f, 0.0f));

	XMMATRIX skullScale = XMMatrixScaling(0.5f, 0.5f, 0.5f);
	XMMATRIX skullOffset = XMMatrixTranslation(0.0f, 1.0f, 0.0f);
	XMStoreFloat4x4(&mSkullWorld, XMMatrixMultiply(skullScale, skullOffset));
}
Exemplo n.º 29
0
AnimationPlayer::AnimationPlayer()
{
	this->Animation.second = NULL;
	this->AnimTime         = 0.0f;
	this->AnimRate         = 1.0f;
	this->CurrentFrame     = 0;
	this->PreviousFrame    = 0;
	this->mRootTranslation = XMFLOAT3(0.0f, 0.0f, 0.0);
	this->mRootRotation = XMFLOAT4(0.0f, 0.0f, 0.0f, 1.0f);

	XMMATRIX matTranslate = XMMatrixIdentity();
	XMMATRIX matFinal = XMMatrixIdentity();

	matTranslate = XMMatrixTranslation( 0.0f, 1.0f, 0.0f);
		
	matFinal = XMMatrixMultiply(matFinal, matTranslate);
	XMStoreFloat4x4(&mPrevRoot, matFinal);
}
Exemplo n.º 30
0
 void Skeleton::ProcessAnimationGraph(float time, MatrixBuffer& buffer, Animation& anim, TrackBuffer& trackData)
 {
     //Linear Form This only works because the bone parent is always guaranteed to be in front
     //of its children (breath first order)
     XMFLOAT4X4 identity;
     XMStoreFloat4x4(&identity, XMMatrixIdentity());
     for (UINT boneIndex = 0; boneIndex < m_Bones.size(); ++boneIndex)
     {
         Bone& bone = m_Bones[boneIndex];
         VQS vqs;
         anim.CalculateTransform(time, boneIndex, vqs, trackData[boneIndex]);
         XMFLOAT4X4 parentTransform = bone.ParentBoneIndex != -1 ? buffer[bone.ParentBoneIndex] : identity;
         XMFLOAT4X4 localTransform = vqs.GetMatrix();
         XMFLOAT4X4 modelTransform; // = localTransform  * parentTransform;
         XMStoreFloat4x4(&modelTransform, XMMatrixMultiply(XMLoadFloat4x4(&localTransform), XMLoadFloat4x4(&parentTransform)));
         buffer[boneIndex] = modelTransform;
     }
 }