Beispiel #1
0
Mat CD3D11Skeleton::Lerp( D3DXMATRIX a, D3DXMATRIX b, float s )
{
	//Decompose a
	D3DXVECTOR3 t1, s1;
	D3DXQUATERNION q1;
	D3DXMatrixDecompose(&s1, &q1, &t1, &a);

	//Decompose b
	D3DXVECTOR3 t2, s2;
	D3DXQUATERNION q2;
	D3DXMatrixDecompose(&s2, &q2, &t2, &b);

	//Lerp each component
	D3DXVECTOR3 ti;
	D3DXVec3Lerp(&ti, &t1, &t2, s);

	D3DXVECTOR3 si;
	D3DXVec3Lerp(&si, &s1, &s2, s);

	D3DXQUATERNION qi;
	D3DXQuaternionSlerp(&qi, &q1, &q2, s);

	//Recompose each component
	D3DXMATRIX Tr, Sc, Rt;

	D3DXMatrixTranslation(&Tr, ti.x, ti.y, ti.z);
	D3DXMatrixScaling(&Sc, si.x, si.y, si.z);
	D3DXMatrixRotationQuaternion(&Rt, &qi);

	//Product
	D3DXMATRIX p = Sc * Rt * Tr;

	//Return
	return Mat((float*)p.m);
}
void GameObject::ChangeParent( GameObject* nextParent )
{
	D3DXMATRIX matParent;
	D3DXMatrixIdentity( &matParent );

	GameObject* parent = GetParent();
	if( parent )
	{
		matParent = parent->m_matWorld;
	}

	UpdateTransform( matParent );

	m_matLocal = m_matWorld;

	D3DXMatrixIdentity( &matParent );
	if( nextParent )
	{
		matParent = nextParent->m_matWorld;
	}

	D3DXMATRIX matInv;
	D3DXMatrixInverse( &matInv,NULL,&matParent );
	D3DXMatrixMultiply( &m_matLocal,&matInv,&m_matLocal );

	D3DXMatrixDecompose( &m_localScale,&m_localRotation,&m_localPosition,&m_matLocal );

	m_changedLocal = true;
	UpdateTransform( matParent );
}
Beispiel #3
0
OBB* RagDoll::CreateBoneBox(Bone* parent, Bone *bone, D3DXVECTOR3 size, D3DXQUATERNION rot) {
    if (bone == NULL || parent == NULL)
        return NULL;

    D3DXMATRIX &parentMat = parent->CombinedTransformationMatrix;
    D3DXMATRIX &boneMat = bone->CombinedTransformationMatrix;
    D3DXVECTOR3 parentPos(parentMat(3, 0), parentMat(3, 1), parentMat(3, 2));
    D3DXVECTOR3 bonePos(boneMat(3, 0), boneMat(3, 1), boneMat(3, 2));

    D3DXQUATERNION q;
    D3DXVECTOR3 p, s;
    D3DXMatrixDecompose(&s, &q, &p, &parentMat);
    q *= rot;
    D3DXQuaternionNormalize(&q, &q);

    p = (parentPos + bonePos) * 0.5f;

    OBB *obb = new OBB(p, size, q, true);

    physicsEngine.GetWorld()->addRigidBody(obb->m_pBody);
    m_boxes.push_back(obb);

    parent->m_pObb = obb;
    parent->m_pivot = obb->SetPivot(parentPos);

    return obb;
}
Beispiel #4
0
void DemoModeBase::Update(const GameContext& context)
{
	m_pDescriptionDock->Update(context);
	if(m_pDemoObject != nullptr)
	{
		D3DXVECTOR3 rotation = D3DXVECTOR3(0,0,0);
		rotation.y = context.Input->IsKeyboardKeyDown('W')?ROTATION_SPEED:0.0f;
		if(rotation.y == 0) rotation.y = -(context.Input->IsKeyboardKeyDown('S')?ROTATION_SPEED:0.0f);
		rotation.x = context.Input->IsKeyboardKeyDown('A')?ROTATION_SPEED:0.0f;
		if(rotation.x == 0) rotation.x = -(context.Input->IsKeyboardKeyDown('D')?ROTATION_SPEED:0.0f);
		rotation.z = context.Input->IsKeyboardKeyDown('Q')?ROTATION_SPEED:0.0f;
		if(rotation.z == 0) rotation.z = -(context.Input->IsKeyboardKeyDown('E')?ROTATION_SPEED:0.0f);

		rotation *= context.GameTime.ElapsedSeconds();

		D3DXMATRIX rotMatrix, newRotMatrix;
		D3DXMatrixRotationQuaternion(&rotMatrix, &m_pDemoObject->GetRotation());
		D3DXMatrixRotationYawPitchRoll(&newRotMatrix, rotation.x, rotation.y, rotation.z);
		rotMatrix *= newRotMatrix;
		D3DXQUATERNION rot;
		D3DXVECTOR3 dum;
		D3DXMatrixDecompose(&dum, &rot, &dum, &rotMatrix);
		m_pDemoObject->Rotate(rot);
	}
}
Beispiel #5
0
bool ElCamera::isViewOutOfDate()
{
	// Overridden from Frustum to use local orientation / position offsets
	// Attached to node?
	if (mParentNode != 0)
	{
		if (mRecalcView ||
			mParentNode->getDerivedOrientation() != mLastParentOrientation ||
			mParentNode->getDerivedPosition() != mLastParentPosition)
		{
			// Ok, we're out of date with SceneNode we're attached to
			mLastParentOrientation = mParentNode->getDerivedOrientation();
			mLastParentPosition = mParentNode->getDerivedPosition();

			mRealOrientation = mLastParentOrientation * mOrientation;
			D3DXMATRIX m;
			D3DXMatrixRotationQuaternion(&m, &mLastParentOrientation);
			D3DXVec3TransformCoord(&mRealPosition, &mPosition, &m);
			mRealPosition += mLastParentPosition;
			
			mRecalcView = true;
		}
	}
	else
	{
		// Rely on own updates
		mRealOrientation = mOrientation;
		mRealPosition = mPosition;
	}

	// Deriving reflected orientation / position
	if (mRecalcView)
	{
		if (mReflect)
		{
			// Calculate reflected orientation, position
			D3DXMATRIX rot;
			D3DXMatrixRotationQuaternion(&rot, &mRealOrientation);
			D3DXMATRIX trans;
			D3DXMatrixTranslation(&trans, mRealPosition.x, mRealPosition.y, mRealPosition.z);
			
			D3DXMATRIX m = rot * trans * mReflectMatrix;

			D3DXVECTOR3 scale;
			D3DXMatrixDecompose(&scale, &mDerivedOrientation, &mDerivedPosition, &m);
		}
		else
		{
			mDerivedOrientation = mRealOrientation;
			mDerivedPosition = mRealPosition;
		}
	}

	return mRecalcView;
}
int WorldInstancedObject::AddInstance(const D3DXMATRIX & world, int instance_id)
{
	InstanceInformation instance;
	D3DXVECTOR3 translation, scale;
	D3DXQUATERNION rotation;
	D3DXMatrixDecompose(&scale, &rotation, &translation, &world);
	instance.Position = translation;
	instance.ID = instance_id;
	m_InstanceVector.push_back(instance);
	return instance_id;
}
Beispiel #7
0
void RagDoll::InitBones(Bone *bone) {
    if (bone == NULL)
        return;

    D3DXVECTOR3 sca, pos;
    D3DXQUATERNION rot;
    D3DXMatrixDecompose(&sca, &rot, &pos, &bone->CombinedTransformationMatrix);
    D3DXQuaternionNormalize(&rot, &rot);
    bone->m_originalRot = rot;

    InitBones((Bone*)bone->pFrameSibling);
    InitBones((Bone*)bone->pFrameFirstChild);
}
Beispiel #8
0
void DXFrame::rotateCam(cam& camr, float dist, float rot, float angle) {
	D3DXMATRIX total;
	D3DXMATRIX temp;
	D3DXVECTOR3 out;
	D3DXVECTOR3 scal;
	D3DXQUATERNION r;
	D3DXMatrixIdentity(&total);
	temp = total;
	D3DXMatrixTranslation(&total,0,0,-dist);
	D3DXMatrixRotationYawPitchRoll(&temp,D3DXToRadian(rot),D3DXToRadian(angle),0);
	total *= temp;
	D3DXMatrixIdentity(&temp);
	D3DXMatrixTranslation(&temp,camr.cam_look_pos.x,camr.cam_look_pos.y,camr.cam_look_pos.z);
	total *= temp;
	D3DXMatrixDecompose(&scal,&r,&out,&total);
	camr.cam_pos = out;
}
void Racer::update()
{
	if (drawable && body)
	{
		D3DXMATRIX transMat;
		(body->getTransform()).get4x4ColumnMajor(transMat);
		drawable->setTransform(&transMat);
		
		// Now update wheels
		(wheelRL->body->getTransform()).get4x4ColumnMajor(transMat);
		wheelRL->drawable->setTransform(&transMat);
		
		(wheelRR->body->getTransform()).get4x4ColumnMajor(transMat);
		wheelRR->drawable->setTransform(&transMat);



		(wheelFL->body->getTransform()).get4x4ColumnMajor(transMat);

		D3DXMATRIX rot1, rot2, trans1;
		D3DXVECTOR3 scale, trans;
		D3DXQUATERNION rot;
		
		D3DXMatrixDecompose(&scale, &rot, &trans, &transMat);
		
		D3DXMatrixRotationQuaternion(&rot1, &rot);
		D3DXMatrixRotationAxis(&rot2, &(drawable->getYVector()), currentSteering * 1.11f);
		D3DXMatrixTranslation(&trans1, trans.x, trans.y, trans.z);
		
		D3DXMatrixMultiply(&transMat, &rot1, &rot2);
		D3DXMatrixMultiply(&transMat, &transMat, &trans1);
		wheelFL->drawable->setTransform(&transMat);

		(wheelFR->body->getTransform()).get4x4ColumnMajor(transMat);

		D3DXMatrixTranslation(&trans1, transMat._41, transMat._42, transMat._43);

		D3DXMatrixMultiply(&transMat, &rot1, &rot2);
		D3DXMatrixMultiply(&transMat, &transMat, &trans1);
		wheelFR->drawable->setTransform(&transMat);
	}
}
Beispiel #10
0
void bgParserASE::OperationTM()
{
	D3DXMATRIX* matParentWorld;
	D3DXMATRIX matChildWorld;
	D3DXMATRIX matInvParentWorld;
	D3DXMATRIX matPos, matRot, matScl;
	D3DXVECTOR3 vPos, vScl;
	D3DXQUATERNION qRot;
	// 터렛 애니메이션 됨! (0프레임 행렬 디버그 필요)
	for (int iNode = 0; iNode < m_pModel->m_ObjectList.size(); iNode++)
	{
		if (m_pModel->m_ObjectList[iNode].pNodeParent)
		{
			matParentWorld = &m_pModel->m_ObjectList[iNode].pNodeParent->nodeTM.matWorld;

			D3DXMatrixInverse(&matInvParentWorld, NULL, matParentWorld);
			matChildWorld = m_pModel->m_ObjectList[iNode].nodeTM.matWorld * matInvParentWorld;
			D3DXMatrixDecompose(&vScl, &qRot, &vPos, &matChildWorld);
			D3DXMatrixScaling(&m_pModel->m_ObjectList[iNode].matWorldScl, vScl.x, vScl.y, vScl.z);
			D3DXMatrixTranslation(&m_pModel->m_ObjectList[iNode].matWorldPos, vPos.x, vPos.y, vPos.z);
			D3DXMatrixRotationQuaternion(&m_pModel->m_ObjectList[iNode].matWorldRot, &qRot);
		}
	}
}
void Racer::update()
{
	if (drawable && body)
	{
		D3DXMATRIX transMat;
		(body->getTransform()).get4x4ColumnMajor(transMat);
		drawable->setTransform(&transMat);

		// Draw gunmount
		gunMountDraw->setTransform(&transMat);

		// Draw gun, centered on attachGun
		hkRotation carRot;
		carRot = body->getTransform().getRotation();


		hkVector4 finalTranslation;
		finalTranslation.setTransformedPos(body->getTransform(), attachGun);
		
		hkVector4 crossProd, normLook, unitX, unitY, unitZ;
		normLook.setXYZ(lookDir);
		normLook(1) += 0.2f;
		normLook.normalize3();
		
		unitZ.set(0,0,1);
		

		crossProd.setCross(unitZ, normLook);
		hkReal length = crossProd.length3();

		hkRotation gunRot;

		if (length == 0.0f)
		{
			crossProd.setXYZ(unitZ);
			gunRot.setIdentity();
		}
		else
		{
			crossProd.normalize3();
			hkReal gunAngle = hkMath::acos(unitZ.dot3(normLook));
			gunRot.setAxisAngle(crossProd, gunAngle);
		}

		hkTransform finalRot, finalTrans, tempTrans;

		finalTrans.setIdentity();
		finalTrans.setTranslation(finalTranslation);

		finalRot.setIdentity();
		finalRot.setRotation(gunRot);
		
		tempTrans.setMul(finalTrans, finalRot);

		tempTrans.get4x4ColumnMajor(transMat);

		gunDraw->setTransform(&transMat);



		// Now update wheels
		// rot1 = car rotation, trans1 = car translation
		D3DXMATRIX rot1, trans1;
		D3DXVECTOR3 scale, trans;
		D3DXQUATERNION rot;
		
		hkVector4 currentPos;
		double dist = 0;
		hkVector4 zDir;
		hkTransform wheelTransform;
		

		wheelTransform = wheelRL->body->getTransform();
		wheelTransform.setRotation(carRot);

		if (!braking && wheelRL->touchingGround)
		{
			currentPos.setXYZ(wheelRL->body->getPosition());
			currentPos.sub(wheelRL->lastPos);

			zDir.setXYZ(drawable->getZhkVector());

			dist = currentPos.dot3(zDir);
			dist /= (0.4);
			dist *= D3DX_PI;
			
			dist += wheelRL->rotation;

			if (hkMath::abs(dist) > D3DX_PI)
			{
				if (dist < 0.0)
					dist += 2.0 * D3DX_PI;
				else
					dist -= 2.0 * D3DX_PI;
			}

			wheelRL->lastPos.setXYZ(wheelRL->body->getPosition());
			wheelRL->rotation = dist;
		}
		

		wheelTransform.get4x4ColumnMajor(transMat);

		D3DXMatrixDecompose(&scale, &rot, &trans, &transMat);
		
		D3DXMatrixRotationQuaternion(&rot1, &rot);
		D3DXMatrixRotationX(&transMat, (float) wheelRL->rotation);
		D3DXMatrixTranslation(&trans1, trans.x, trans.y, trans.z);
		
		D3DXMatrixMultiply(&transMat, &transMat, &rot1);
		D3DXMatrixMultiply(&transMat, &transMat, &trans1);
		wheelRL->drawable->setTransform(&transMat);




		wheelTransform = wheelRR->body->getTransform();
		wheelTransform.setRotation(carRot);

		if (!braking && wheelRR->touchingGround)
		{
			currentPos.setXYZ(wheelRR->body->getPosition());
			currentPos.sub(wheelRR->lastPos);

			zDir.setXYZ(drawable->getZhkVector());

			dist = currentPos.dot3(zDir);
			dist /= (0.4);
			dist *= D3DX_PI;
			
			dist += wheelRR->rotation;

			if (hkMath::abs(dist) > D3DX_PI)
			{
				if (dist < 0.0)
					dist += 2.0 * D3DX_PI;
				else
					dist -= 2.0 * D3DX_PI;
			}

			wheelRR->lastPos.setXYZ(wheelRR->body->getPosition());
			wheelRR->rotation = dist;
		}

		wheelTransform.get4x4ColumnMajor(transMat);

		D3DXMatrixDecompose(&scale, &rot, &trans, &transMat);
		
		D3DXMatrixRotationQuaternion(&rot1, &rot);
		D3DXMatrixRotationX(&transMat, (float) wheelRR->rotation);
		D3DXMatrixTranslation(&trans1, trans.x, trans.y, trans.z);
		
		D3DXMatrixMultiply(&transMat, &transMat, &rot1);
		D3DXMatrixMultiply(&transMat, &transMat, &trans1);
		wheelRR->drawable->setTransform(&transMat);




		wheelTransform = wheelFL->body->getTransform();
		wheelTransform.setRotation(carRot);
		wheelTransform.get4x4ColumnMajor(transMat);

		D3DXMatrixDecompose(&scale, &rot, &trans, &transMat);
		
		D3DXMatrixRotationQuaternion(&rot1, &rot);
		D3DXMatrixRotationY(&transMat, currentSteering * 1.11f);
		
		D3DXMatrixMultiply(&transMat, &transMat, &rot1);
		wheelFL->drawable->setTransform(&transMat);

		wheelTransform.setRotation(carRot);

		if (!braking && wheelFL->touchingGround)
		{
			currentPos.setXYZ(wheelFL->body->getPosition());
			currentPos.sub(wheelFL->lastPos);

			zDir.setXYZ(wheelFL->drawable->getZhkVector());

			dist = currentPos.dot3(zDir);
			dist /= (0.35);
			dist *= D3DX_PI;
			
			dist += wheelFL->rotation;

			if (hkMath::abs(dist) > D3DX_PI)
			{
				if (dist < 0.0)
					dist += 2.0 * D3DX_PI;
				else
					dist -= 2.0 * D3DX_PI;
			}

			wheelFL->lastPos.setXYZ(wheelFL->body->getPosition());
			wheelFL->rotation = dist;
		}

		wheelTransform.get4x4ColumnMajor(transMat);

		D3DXMatrixDecompose(&scale, &rot, &trans, &transMat);
		
		D3DXMatrixRotationQuaternion(&rot1, &rot);
		D3DXMatrixRotationYawPitchRoll(&transMat, currentSteering * 1.11f, (float) wheelFL->rotation, 0);
		D3DXMatrixTranslation(&trans1, trans.x, trans.y, trans.z);
		
		D3DXMatrixMultiply(&transMat, &transMat, &rot1);
		D3DXMatrixMultiply(&transMat, &transMat, &trans1);
		wheelFL->drawable->setTransform(&transMat);

		

		wheelTransform = wheelFR->body->getTransform();
		wheelTransform.setRotation(carRot);
		wheelTransform.get4x4ColumnMajor(transMat);

		D3DXMatrixDecompose(&scale, &rot, &trans, &transMat);
		
		D3DXMatrixRotationQuaternion(&rot1, &rot);
		D3DXMatrixRotationY(&transMat, currentSteering * 1.11f);
		
		D3DXMatrixMultiply(&transMat, &transMat, &rot1);
		wheelFR->drawable->setTransform(&transMat);

		wheelTransform.setRotation(carRot);

		if (!braking && wheelFR->touchingGround)
		{
			currentPos.setXYZ(wheelFR->body->getPosition());
			currentPos.sub(wheelFR->lastPos);

			zDir.setXYZ(wheelFR->drawable->getZhkVector());

			dist = currentPos.dot3(zDir);
			dist /= (0.35);
			dist *= D3DX_PI;
			
			dist += wheelFR->rotation;

			if (hkMath::abs(dist) > D3DX_PI)
			{
				if (dist < 0.0)
					dist += 2.0 * D3DX_PI;
				else
					dist -= 2.0 * D3DX_PI;
			}

			wheelFR->lastPos.setXYZ(wheelFR->body->getPosition());
			wheelFR->rotation = dist;
		}

		wheelTransform.get4x4ColumnMajor(transMat);

		D3DXMatrixDecompose(&scale, &rot, &trans, &transMat);
		
		D3DXMatrixRotationQuaternion(&rot1, &rot);
		D3DXMatrixRotationYawPitchRoll(&transMat, currentSteering * 1.11f, (float) wheelFR->rotation, 0);
		D3DXMatrixTranslation(&trans1, trans.x, trans.y, trans.z);
		
		D3DXMatrixMultiply(&transMat, &transMat, &rot1);
		D3DXMatrixMultiply(&transMat, &transMat, &trans1);
		wheelFR->drawable->setTransform(&transMat);

		currentAcceleration = 0.0f;



		// Update 3D sound position
		hkVector4 vec;
		vec.setXYZ(lookDir);
		vec.normalize3();
		
		emitter->OrientFront.x = vec(0);
		emitter->OrientFront.y = vec(1);
		emitter->OrientFront.z = vec(2);

		vec.setXYZ(body->getPosition());

		emitter->Position.x = vec(0);
		emitter->Position.y = vec(1);
		emitter->Position.z = vec(2);

		vec.setXYZ(body->getLinearVelocity());

		emitter->Velocity.x = vec(0);
		emitter->Velocity.y = vec(1);
		emitter->Velocity.z = vec(2);
	}
}
void Matrix::decompose(Vector3* scale, Quaternion* rotation, Vector3* translation) const
{
	D3DXMatrixDecompose(scale, rotation, translation, this);
}
void Drawable::buildShadowVolume(D3DXVECTOR3 light)
{
	// Use connectivity table to determine silhouette edges
	unsigned long** connectivityTable;

	switch (meshType)
	{
	case (RACER):
		{
			connectivityTable = racerConnectivityTable;
			break;
		}
	case (FRONTWHEEL):
		{
			connectivityTable = frontWheelConnectivityTable;
			break;
		}
	case (REARWHEEL):
		{
			connectivityTable = rearWheelConnectivityTable;
			break;
		}
	case (GUNMOUNTMESH):
		{
			connectivityTable = gunMountConnectivityTable;
			break;
		}
	default:
		connectivityTable = racerConnectivityTable;
	}

	D3DXMATRIX invTrans;
	D3DXQUATERNION rot;
	D3DXVECTOR3 scale, translate;
	D3DXMatrixDecompose(&scale, &rot, &scale, &transform);
	D3DXQuaternionInverse(&rot, &rot);
	D3DXVECTOR4 temp;
	D3DXMatrixRotationQuaternion(&invTrans, &rot);
	D3DXVec3Transform(&temp, &light, &invTrans);
	light.x = -temp.x;
	light.y = -temp.y;
	light.z = -temp.z;

	Vertex* vertices = mesh->vertices;
	unsigned long* indices = mesh->indices;
	int vertexCount = mesh->vertexCount;
	int indexCount = mesh->indexCount;

	int numFaces = indexCount / 3;

	unsigned long index0, index1, index2, neighbourTri;


	D3DXVECTOR3* points;
	int numVertices = 0;
	D3DXVECTOR3 newV0, newV1;
	D3DXVECTOR3 v0, v1, v2;
	D3DXVECTOR3 norm;


	shadowVertexBuffer->Lock(0, sizeof(D3DXVECTOR3) * mesh->indexCount * 6, (void**) &points, NULL);
	
	for (int i = 0; i < numFaces; i++)
	{
		index0 = indices[3*i];
		index1 = indices[3*i+1];
		index2 = indices[3*i+2];

		norm = vertices[index0].normal + vertices[index1].normal + vertices[index2].normal;
		norm /= 3.0f;

		// The current face is lit. Must check neighbours now
		if (D3DXVec3Dot(&norm, &light) > 0.0f)
		{
			v0 = vertices[index0].position;
			v1 = vertices[index1].position;
			v2 = vertices[index2].position;
			
			// For each edge, check if neighbour tri is lit. If it's not, add this edge

			// EDGE 0
			neighbourTri = connectivityTable[i][0];
			index0 = indices[3*neighbourTri];
			index1 = indices[3*neighbourTri+1];
			index2 = indices[3*neighbourTri+2];

			norm = vertices[index0].normal + vertices[index1].normal + vertices[index2].normal;
			norm /= 3.0f;
			
			if (D3DXVec3Dot(&norm, &light) < 0.0f)
			{
				// Neighbour is not lit! Add this edge!
				newV0 = v0 - light*200;
				newV1 = v1 - light*200;

				points[numVertices++] = v1;
				points[numVertices++] = v0;
				points[numVertices++] = newV0;
				
				points[numVertices++] = newV0;
				points[numVertices++] = newV1;
				points[numVertices++] = v1;

			}
			
			// EDGE 1
			neighbourTri = connectivityTable[i][1];
			index0 = indices[3*neighbourTri];
			index1 = indices[3*neighbourTri+1];
			index2 = indices[3*neighbourTri+2];

			norm = vertices[index0].normal + vertices[index1].normal + vertices[index2].normal;
			norm /= 3.0f;
			
			if (D3DXVec3Dot(&norm, &light) < 0.0f)
			{
				// Neighbour is not lit! Add this edge!
				newV0 = v1 - light*200;
				newV1 = v2 - light*200;

				points[numVertices++] = v2;
				points[numVertices++] = v1;
				points[numVertices++] = newV0;
				
				points[numVertices++] = newV0;
				points[numVertices++] = newV1;
				points[numVertices++] = v2;
			}

			// EDGE 2
			neighbourTri = connectivityTable[i][2];
			index0 = indices[3*neighbourTri];
			index1 = indices[3*neighbourTri+1];
			index2 = indices[3*neighbourTri+2];

			norm = vertices[index0].normal + vertices[index1].normal + vertices[index2].normal;
			norm /= 3.0f;
			
			if (D3DXVec3Dot(&norm, &light) < 0.0f)
			{
				// Neighbour is not lit! Add this edge!
				newV0 = v2 - light*200;
				newV1 = v0 - light*200;

				points[numVertices++] = v0;
				points[numVertices++] = v2;
				points[numVertices++] = newV0;
				
				points[numVertices++] = newV0;
				points[numVertices++] = newV1;
				points[numVertices++] = v0;
			}
			
		}
	}
	
	shadowVertexBuffer->Unlock();

	shadowVertCount = numVertices;
}
Beispiel #14
0
bool GBoneObj::Load(ID3D11Device* pDevice,const TCHAR* szLoadName,const TCHAR* pLoadShaderFile,bool bThread)
{
	FILE	*fp;
	fp = _tfopen(szLoadName, _T("rb"));
	if (!fp) return false;

	char szBuffer[MAX_PATH] = { 0, };
	size_t convertedChars = 0;

	tm newtime;
	fread(&newtime, sizeof(tm), 1, fp);
	T_STR today = _tasctime(&newtime);	// The date string has a \n appended.
	today[today.size() - 1] = 0;
	fread(&m_Scene, sizeof(TScene), 1, fp);

	// 시작 프레임이 0일 아닐 경우가 있기 때문에 무조건 
	// 시작 프레임을 0으로 맞춘다.( 해당 프레임 만큼만 배열 할당 된다.)
	m_iStartFrame = 0;//m_Scene.iFirstFrame;
	m_iLastFrame = m_Scene.iLastFrame - m_Scene.iFirstFrame;
	m_fElapseTime = (float)m_iStartFrame;
	m_Scene.iFirstFrame = 0;
	m_Scene.iLastFrame = m_iLastFrame;

	SAFE_NEW_ARRAY_CLEAR(m_pMatrix, D3DXMATRIX, m_Scene.iNumMesh);
	SAFE_NEW_ARRAY_CLEAR(m_ppAniMatrix, LPD3DXMATRIX, m_Scene.iNumMesh);
	SAFE_NEW_ARRAY_CLEAR(m_ppAniQuater, LPD3DXQUATERNION, m_Scene.iNumMesh);
	SAFE_NEW_ARRAY_CLEAR(m_ppScaleVector, LPD3DXVECTOR3, m_Scene.iNumMesh);
	SAFE_NEW_ARRAY_CLEAR(m_ppTransVector, LPD3DXVECTOR3, m_Scene.iNumMesh);

	int iNumFrame = m_iLastFrame - m_iStartFrame;
	for (int i = 0; i < m_Scene.iNumMesh; i++)
	{
		SAFE_NEW_ARRAY(m_ppAniMatrix[i], D3DXMATRIX, iNumFrame);
		SAFE_NEW_ARRAY(m_ppAniQuater[i], D3DXQUATERNION, iNumFrame);
		SAFE_NEW_ARRAY(m_ppScaleVector[i], D3DXVECTOR3, iNumFrame);
		SAFE_NEW_ARRAY(m_ppTransVector[i], D3DXVECTOR3, iNumFrame);
	}

	D3DXQUATERNION qRotate;
	D3DXVECTOR3 vScale, vTrans;
	D3DXMATRIX matFrameWorld;

	for (int ibip = 0; ibip < m_Scene.iNumMesh; ibip++)
	{
		for (int iFrame = 0; iFrame < iNumFrame; iFrame++)
		{
			fread(&m_ppAniMatrix[ibip][iFrame], sizeof(D3DXMATRIX), 1, fp);
		}
	}

	for (int ibip = 0; ibip < m_Scene.iNumMesh; ibip++)
	{
		shared_ptr<tMatMesh> pData = make_shared<tMatMesh>();
		shared_ptr<GMesh> pMesh = make_shared<GMesh>();
		int iCount;

		TCHAR szBuffer[256] = { 0, };
		TCHAR szName[256] = { 0, };
		fread(&pMesh->m_ClassType, sizeof(int), 1, fp);
		fread(&iCount, sizeof(int), 1, fp);
		fread(szName, sizeof(TCHAR) * iCount, 1, fp);

		pMesh->m_strNodeName = szName;
		fread(&pMesh->m_matWorld, sizeof(D3DXMATRIX), 1, fp);
		D3DXMatrixInverse(&pData->m_matInverse, 0, &pMesh->m_matWorld);

		fread(&iCount, sizeof(int), 1, fp);
		// 메쉬 버텍스 리스트
		if (iCount == 2)
		{
			pData->m_VertexArray.resize(36);
			m_iMaxVertex += 36;
		}
		else
		{
			pData->m_VertexArray.resize(iCount);
			m_iMaxVertex += iCount;
		}

		for (int iVertex = 0; iVertex < iCount; iVertex++)
		{
			fread(&pData->m_VertexArray[iVertex], sizeof(PNC_VERTEX), 1, fp);
			if (m_Scene.iBindPose)
			{
				D3DXVec3TransformCoord(&pData->m_VertexArray[iVertex].p,
					&pData->m_VertexArray[iVertex].p,
					&pData->m_matInverse);
			}
		}

		// 본과 더미 오브젝트( 최대 및 최소값 2개 출력되어 있음 )
		if (iCount == 2)
		{
			D3DXVECTOR3 Quad[8];
			D3DXVECTOR3 vMax = pData->m_VertexArray[0].p;
			D3DXVECTOR3 vMin = pData->m_VertexArray[1].p;

			Quad[0] = D3DXVECTOR3(vMin.x, vMin.y, vMin.z);
			Quad[1] = D3DXVECTOR3(vMin.x, vMax.y, vMin.z);
			Quad[2] = D3DXVECTOR3(vMax.x, vMax.y, vMin.z);
			Quad[3] = D3DXVECTOR3(vMax.x, vMin.y, vMin.z);

			Quad[4] = D3DXVECTOR3(vMin.x, vMin.y, vMax.z);
			Quad[5] = D3DXVECTOR3(vMin.x, vMax.y, vMax.z);
			Quad[6] = D3DXVECTOR3(vMax.x, vMax.y, vMax.z);
			Quad[7] = D3DXVECTOR3(vMax.x, vMin.y, vMax.z);
			SetBoundBox(Quad, pData.get());
		}
		pMesh->m_iNumFace = pData->m_VertexArray.size() / 3;
		m_pMesh.push_back(pMesh);
		m_pData.push_back(pData);
	}

	for (int ibip = 0; ibip < m_Scene.iNumMesh; ibip++)
	{
		for (int jFrame = 0; jFrame < m_iLastFrame - m_iStartFrame; jFrame++)
		{
			if (m_Scene.iBindPose)
			{
				//m_ppAniMatrix[ibip][jFrame] = m_pData[ibip]->m_matWorld * m_ppAniMatrix[ibip][jFrame];
			}
			if (SUCCEEDED(D3DXMatrixDecompose(&vScale, &qRotate, &vTrans, &m_ppAniMatrix[ibip][jFrame])))
			{
				m_ppAniQuater[ibip][jFrame] = qRotate;
				m_ppScaleVector[ibip][jFrame] = vScale;
				m_ppTransVector[ibip][jFrame] = vTrans;
			}
			else
			{
				D3DXQuaternionRotationMatrix(&m_ppAniQuater[ibip][jFrame], &m_ppAniMatrix[ibip][jFrame]);
			}
		}
	}

	fclose(fp);

	m_dxobj.m_iNumVertex = m_iMaxVertex;
	m_dxobj.m_iNumIndex = m_iMaxIndex;
	m_dxobj.m_iVertexSize = sizeof(PNC_VERTEX);

	if (!bThread && !Create(pDevice, pLoadShaderFile))
	{
		return false;
	}
	return true;
}