Ejemplo n.º 1
0
	void RenderingGame::update_stencil_material() {
		MaterialDeferredStencil* m = m_stencil_material->As<MaterialDeferredStencil>();
		LightPoint* l = m_point_light->As<LightPoint>();
		float r = l->radius();
		XMMATRIX world = XMMatrixScaling(r, r, r) * XMMatrixTranslationFromVector(l->positionv());
		m->WVP() << world * m_camera->view_projection();
	}
Ejemplo n.º 2
0
// スケール、回転、移動行列
XMMATRIX SQTMatrix(const XMVECTOR& scale, const XMVECTOR& quat_rot, const XMVECTOR& trans)
{
	return XMMatrixMultiply(
		XMMatrixMultiply(
		XMMatrixScalingFromVector(scale),
		XMMatrixRotationQuaternion(quat_rot)),
		XMMatrixTranslationFromVector(trans));
}
Ejemplo n.º 3
0
Matrix4 Local_Light_Editor::GetWorldTransform() const
{
	//const Quat q = this->GetOrientation();
	//const Vec3D p = this->GetOrigin();
	//Matrix4 xform;
	//xform.BuildTransform( p, q );
	//return xform;
	return as_matrix4(XMMatrixTranslationFromVector( this->GetLight().m_position ));
}
Ejemplo n.º 4
0
void Physics::exe_world_curr(uint32_t const _i_zad) {
	for(uint32_t _i = 0; _i < phys_par.mtx_world.get_size(); ++_i) {
		XMStoreFloat3(&phys_par.pos[_i], XMLoadFloat3(&phys_par.pos[_i]) + XMLoadFloat3(&phys_par.v[_i]));
		XMStoreFloat4x4(
			&phys_par.mtx_world[_i],
			XMMatrixTranslationFromVector(XMLoadFloat3(&phys_par.pos[_i]))
		);
	}
}
Ejemplo n.º 5
0
XMMATRIX Transform::createWorldMatrix() const
{
	XMMATRIX world = XMMatrixIdentity();
	world *= XMMatrixScalingFromVector(XMLoadFloat3(&scale));
	world *= XMMatrixRotationQuaternion(XMLoadFloat4(&rotation));
	world *= XMMatrixTranslationFromVector(XMLoadFloat3(&position));
	if (parent != nullptr) world *= parent->createWorldMatrix();
	return world;
}
Ejemplo n.º 6
0
void HydraRenderer::Render(D3DRenderer* renderer)
{
	CBPerObject perObject;
	perObject.Material.HasDiffuseTex = false;
	perObject.Material.HasNormalTex = false;
	perObject.Material.HasSpecTex = false;
	perObject.Material.HasEmissiveTex = false;

	HydraManager* hydra = InputSystem::get()->getHydra();

	for (int controller = 0; controller < sixenseGetMaxControllers(); controller++)
	{
		if (sixenseIsControllerEnabled(controller))
		{
			XMVECTOR rotationQuat = hydra->getRotation(controller);
			XMVECTOR position = hydra->getPosition(controller);
			//XMVectorSetZ(position, -XMVectorGetZ(position));//Flip Z axis
			//position += XMVectorSet(0.0f, 0.9f, 0.0f, 0.0f);//Offset for table height

			perObject.World = XMMatrixRotationQuaternion(XMQuaternionRotationAxis(XMLoadFloat3(&XMFLOAT3(1.0f, 0.0f, 0.0f)), XMConvertToRadians(90.0f))) *
							  XMMatrixTranslation(0.0f, 0.0f, 0.07f) *
							  //XMMatrixTranslation(0.0f, 0.0f, 0.25f) *
							  XMMatrixRotationQuaternion(rotationQuat) *
							  XMMatrixTranslationFromVector(position);
			perObject.WorldInvTranspose = XMMatrixInverse(NULL, XMMatrixTranspose(perObject.World));
			perObject.WorldViewProj = perObject.World * renderer->getPerFrameBuffer()->ViewProj;

			renderer->setPerObjectBuffer(perObject);

			mpPointerRenderer->Render(renderer);

			//Render root trackers
			perObject.World = XMMatrixRotationQuaternion(XMQuaternionRotationAxis(XMLoadFloat3(&XMFLOAT3(1.0f, 0.0f, 0.0f)), XMConvertToRadians(90.0f))) *
							  XMMatrixRotationQuaternion(rotationQuat) * 
							  XMMatrixTranslationFromVector(position);
			perObject.WorldInvTranspose = XMMatrixInverse(NULL, XMMatrixTranspose(perObject.World));
			perObject.WorldViewProj = perObject.World * renderer->getPerFrameBuffer()->ViewProj;

			renderer->setPerObjectBuffer(perObject);

			mpRootRenderer->Render(renderer);
		}
	}
}
Ejemplo n.º 7
0
Box::Box(float x, float y, float z, XMVECTOR position, float mass, bool fixed, XMVECTOR orientation)
{
	this->position = position;	// its the center position of the box
	this->velocity = XMVectorSet(0.f, 0.f, 0.f, 0.f);
	length = XMVectorSet(x, y, z, 0.f);
	
	centerOfMass = Point(position, false);

	this->transform = XMMatrixTranslationFromVector(this->position);
	this->centerOfMass.fixed = fixed;
	this->orientation = XMQuaternionRotationRollPitchYawFromVector(orientation);

	if (fixed) 
	{
		centerOfMass.mass = 1.0f;
		massInverse = 0.0f;
		intertiaTensorInverse = XMMATRIX();
	}
	else 
	{
		centerOfMass.mass = mass;
		massInverse = 1.0f / mass;
		float prefix = (1.0f / 12.0f) * centerOfMass.mass;

		XMMATRIX matrix = XMMATRIX(XMVectorSet(prefix*(y*y + z*z), 0.f, 0.f, 0.f),
			XMVectorSet(0.f, prefix * (x*x + z*z), 0.f, 0.f),
			XMVectorSet(0.f, 0.f, prefix*(x*x + y*y),0.f),
			XMVectorSet(0.f, 0.f, 0.f, 1.f));
		intertiaTensorInverse = XMMatrixInverse(&XMMatrixDeterminant(matrix), matrix);
	}

	XMVECTOR xLength = XMVectorSet(x, 0.f, 0.f, 0.f) / 2;
	XMVECTOR yLength = XMVectorSet(0.f, y, 0.f, 0.f) / 2;
	XMVECTOR zLength = XMVectorSet(0.f, 0.f, z, 0.f) / 2;

	for (int i = 0; i < 8; i++) 
	{
		corners[0] = XMVECTOR();
	}

	this->angularMomentum = XMVECTOR();
	this->angularVelocity = XMVECTOR();
	this->torqueAccumulator = XMVECTOR();



	corners[0] = -xLength - yLength - zLength;
	corners[1] = xLength - yLength - zLength;
	corners[2] = -xLength + yLength - zLength;
	corners[3] = xLength + yLength - zLength;
	corners[4] = -xLength - yLength + zLength;
	corners[5] = xLength - yLength + zLength;
	corners[6] = -xLength + yLength + zLength;
	corners[7] = xLength + yLength + zLength;

}
XMMATRIX Sprite::GetWorld()
{
	XMMATRIX scale = XMMatrixScaling(mScale.x, mScale.y, 1.0f);
	XMMATRIX rot = XMMatrixRotationZ(mAngle);
	XMMATRIX trans = XMMatrixTranslationFromVector(XMVectorSet(mPos.x, mPos.y, mDepth, 1.0f));

	XMMATRIX world = scale * rot * trans;

	return world;
}
Ejemplo n.º 9
0
/**
 *	Create a translation matrix for a given position.
 *
 *  @param vPosition The position expressed as a CFVec3.
 *  @return The resulting matrix.
 */
CFMat4x4	CFMat4x4::CreateTranslation( CFVec3Arg vPosition )
{
	CFMat4x4 matReturn;

	XMMATRIX& matResult = *reinterpret_cast<XMMATRIX*>( &matReturn );
	const XMVECTOR& vArg = *reinterpret_cast<const XMVECTOR*>( &vPosition );

	matResult = XMMatrixTranslationFromVector( vArg );

	return matReturn;
}
Ejemplo n.º 10
0
void JF::Component::ColisionBox::Render()
{
	// Declear)
	float blendFactors[] = { 0.0f, 0.0f, 0.0f, 0.0f };

	// Get)
	auto* pTransform = GetOwner()->GetComponent<JF::Component::Transform>();

	// Check)
	RETURN_IF(pTransform == nullptr, );

	// Set Layout And Topology
	gRENDERER->DeviceContext()->IASetInputLayout(InputLayouts::PosColor);
	gRENDERER->DeviceContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST);

	// Set VertexBuffer And IndexBuffer
	UINT stride = sizeof(JF::Vertex::PosColor);
	UINT offset = 0;
	gRENDERER->DeviceContext()->IASetVertexBuffers(0, 1, &m_VertBuff, &stride, &offset);
	gRENDERER->DeviceContext()->IASetIndexBuffer(m_IndexBuff, DXGI_FORMAT_R32_UINT, 0);

	// worldViewProj 행렬을 구한다.
	XMFLOAT3 rPosition	= XMFLOAT3(pTransform->GetPosition().x + m_Center.x, pTransform->GetPosition().y + m_Center.y, pTransform->GetPosition().z + m_Center.z);
	XMFLOAT3 rScale		= XMFLOAT3(pTransform->GetScale().x * m_Size.x, pTransform->GetScale().y * m_Size.y, pTransform->GetScale().z * m_Size.z);
	XMFLOAT4 rRotation	= pTransform->GetRotation();

	XMMATRIX scl, rot, tsl;
	scl = XMMatrixScalingFromVector(XMLoadFloat3(&rScale));
	rot = XMMatrixRotationQuaternion(XMLoadFloat4(&rRotation));
	tsl = XMMatrixTranslationFromVector(XMLoadFloat3(&rPosition));

	XMMATRIX world = scl*rot*tsl;
	XMMATRIX view = Camera::g_pMainCamera->GetView();
	XMMATRIX proj = Camera::g_pMainCamera->GetProj();
	XMMATRIX worldViewProj = world * view * proj;

	Effects::SimpleFX->SetWorldViewProj(worldViewProj);

	// 노말맵이 있는지에따라 FX Tech 설정 변경.
	ID3DX11EffectTechnique* Tech;
	Tech = Effects::SimpleFX->ColorTech;

	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_indexCnt, 0, 0);
	}

	// 기본 랜더상태로 복원한다.
	gRENDERER->DeviceContext()->RSSetState(0);
	gRENDERER->DeviceContext()->OMSetBlendState(0, blendFactors, 0xffffffff);
}
Ejemplo n.º 11
0
XMFLOAT4X4& ITransform::GetTransformMatrix()
{
	XMMATRIX scl, rot, tsl;
	scl = XMMatrixScalingFromVector(XMLoadFloat3(&m_vScale));
	rot = XMMatrixRotationRollPitchYawFromVector(XMLoadFloat3(&m_vRotation));
	tsl = XMMatrixTranslationFromVector(XMLoadFloat3(&m_vPosition));

	// worldMat = S*R*T
	XMStoreFloat4x4(&m_mTransform, (scl*rot*tsl));

	return m_mTransform;
}
Ejemplo n.º 12
0
XMFLOAT4X4 Transform::RecalculateWorldMatrix()
{
	//TODO: figure out a better way to handle rotaions
	if (!GetIsDirty()) return worldMatrix;//Dont know if I want to keep it.
	XMMATRIX allignedWorldMatrix = XMLoadFloat4x4(&worldMatrix);
	if (parent == nullptr) {
		XMMATRIX  calculatedWorldMatrix =
			XMMatrixScalingFromVector(XMLoadFloat3(&scale)) * //XMMatrixRotationRollPitchYawFromVector(XMLoadFloat3(&rotation)) *
			//XMMatrixRotationX(rotation.x) * XMMatrixRotationY(rotation.y) * XMMatrixRotationZ(rotation.z) *
			XMMatrixRotationQuaternion(XMQuaternionRotationRollPitchYawFromVector(XMLoadFloat3(&rotation))) * 
			XMMatrixTranslationFromVector(XMLoadFloat3(&position));
		XMStoreFloat4x4(&worldMatrix, XMMatrixTranspose(calculatedWorldMatrix));
	} else {
		XMMATRIX  calculatedWorldMatrix =
			XMMatrixScalingFromVector(XMLoadFloat3(&scale)) * //XMMatrixRotationRollPitchYawFromVector(XMLoadFloat3(&rotation)) *
			XMMatrixRotationQuaternion(XMQuaternionRotationRollPitchYawFromVector(XMLoadFloat3(&rotation))) *
			XMMatrixTranslationFromVector(XMLoadFloat3(&position));
		XMStoreFloat4x4(&worldMatrix, XMMatrixTranspose(
			XMMatrixMultiply(XMMatrixTranspose(XMLoadFloat4x4(&parent->GetWorldMatrix())), calculatedWorldMatrix)));
	}
	return worldMatrix;
}
	void EntitySphere::render()
	{
		XMMATRIX translation = XMMatrixTranslationFromVector(m_position);
		XMMATRIX orientation = XMMatrixRotationRollPitchYaw(m_orientation.x, m_orientation.y, m_orientation.z);
		XMMATRIX scaling = XMMatrixScaling(m_diameter, m_diameter, m_diameter);

		XMMATRIX viewMatrix, projectionMatrix, transform;
		transform = scaling * orientation * translation;

		GRAPHICS->getCamera()->GetViewMatrix(viewMatrix);
		GRAPHICS->getDirectXWrapper()->getProjectionMatrix(projectionMatrix);
	
		m_gfx->render(transform, viewMatrix, projectionMatrix, m_color, m_texture, m_wireframe);
	}
void make_worldmatrix(QuaternionTransform const& qt, XMFLOAT4X4 &mat)
{
	XMVECTOR trans_vec = XMLoadFloat3(&qt.pos);
	XMMATRIX trans_mat = XMMatrixTranslationFromVector(trans_vec);

	XMVECTOR scale_vec = XMLoadFloat3(&qt.scale);
	XMMATRIX scale_mat = XMMatrixScalingFromVector(scale_vec);

	XMVECTOR rotat_vec = XMLoadFloat4(&qt.quat);
	XMMATRIX rotat_mat = XMMatrixRotationQuaternion(rotat_vec);

	XMMATRIX world = scale_mat * rotat_mat * trans_mat;

	XMStoreFloat4x4(&mat, world);
}
Ejemplo n.º 15
0
void Player::FrameMove(float fElapsedTime)
{
	GetInput();

	XMMATRIX mBodyCameraRot = XMMatrixRotationRollPitchYaw(0, m_fYawAngle, 0);
	XMMATRIX mHeadCameraRot = XMMatrixRotationRollPitchYaw(m_fPitchAngle, 0, 0);

	mHeadCameraRot.r[3] = XMVectorSet(0.f, 0.6f, 0.f, 1.f);

	mWorld = mBodyCameraRot * XMMatrixTranslationFromVector(mWorld.Translation());
	m_pHead->SetRelativeWorld(mHeadCameraRot);

	UpdateAcceleration(fElapsedTime);

	ControllerNode::FrameMove(fElapsedTime);
}
Ejemplo n.º 16
0
	void RenderingGame::update_light_material() {
		MaterialDeferredPLight* m = m_light_material->As<MaterialDeferredPLight>();
		m->VP() << m_camera->view_projection();
		m->CameraPosition() << XMLoadFloat3(&m_camera->position());
		//m->ScreenResolution() << XMLoadFloat2(&XMFLOAT2(m_screen_width, m_screen_height));
		LightPoint* l = m_point_light->As<LightPoint>();
		XMVECTOR pos = l->positionv();
		float r = l->radius();
		m->World() << XMMatrixScaling(r, r, r) * XMMatrixTranslationFromVector(pos);
		m->LightColor() << l->colorv();
		m->LightPosition() << pos;
		m->LightAttenuation() << l->attenuation();
		//
		m->PositionBuffer() << m_render_targets[0]->output_texture();
		m->NormalBuffer() << m_render_targets[1]->output_texture();
		m->AlbedoSpecularBuffer() << m_render_targets[2]->output_texture();
	}
Ejemplo n.º 17
0
XMFLOAT4X4 gameObject::CalculateWorldMatrix()
{
	XMMATRIX scale, rot, trans, world;

	scale = XMMatrixScalingFromVector(XMLoadFloat3(&m_scaleVector));
	rot = XMMatrixRotationRollPitchYawFromVector(XMLoadFloat3(&m_rotationVector));
	trans = XMMatrixTranslationFromVector(XMLoadFloat3(&m_positionVector));

	world = scale* rot* trans;

	XMStoreFloat4x4(&m_matScale, scale);
	XMStoreFloat4x4(&m_matRot, rot);
	XMStoreFloat4x4(&m_matTranslation, trans);
	XMStoreFloat4x4(&m_matTransform, world);


	return m_matTransform;
}
Ejemplo n.º 18
0
void Transform::CacheTransform()
{
	XMMATRIX transform;

	// Scale -> Rotate -> Translate
	transform = XMMatrixTranslationFromVector(XMLoadFloat3(&m_position))*
				m_rotation.GetMatrixFormXM() *
				XMMatrixScalingFromVector(XMLoadFloat3(&m_scale));

	if (m_bMirrorX)
		transform *= XMLoadFloat4x4(&s_mirrorXMat);

	if (m_bMirrorY)
		transform *= XMLoadFloat4x4(&s_mirrorYMat);

	if (m_bMirrorZ)
		transform *= XMLoadFloat4x4(&s_mirrorZMat);

	XMStoreFloat4x4(&m_transformMatrix, transform);
}
Ejemplo n.º 19
0
VOID DebugDraw::DrawCubeQuery( const XMFLOAT3& Center, const XMFLOAT3& HalfSize )
{
    // Index buffer data for a cube (using a quad list).
    static const WORD pIndexData[] =
    {
        3, 2, 0, 1,
        1, 0, 4, 5,
        3, 1, 5, 7,
        2, 3, 7, 6,
        0, 2, 6, 4,
        5, 4, 6, 7
    };
    static const XMFLOAT3 pVertexData[] =
    {
        XMFLOAT3( -1, -1, -1 ),
        XMFLOAT3( 1, -1, -1 ),
        XMFLOAT3( -1, -1, 1 ),
        XMFLOAT3( 1, -1, 1 ),
        XMFLOAT3( -1, 1, -1 ),
        XMFLOAT3( 1, 1, -1 ),
        XMFLOAT3( -1, 1, 1 ),
        XMFLOAT3( 1, 1, 1 )
    };

    XMMATRIX matTranslate = XMMatrixTranslationFromVector( XMLoadFloat3( &Center ) );
    XMMATRIX matScale = XMMatrixScalingFromVector( XMLoadFloat3( &HalfSize ) );
    XMMATRIX matTransform = matScale * matTranslate * g_matViewProjection;

    SimpleShaders::SetDeclPos();
    SimpleShaders::BeginShader_Transformed_DepthOnly( matTransform );
    g_pd3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );
    g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
    g_pd3dDevice->DrawIndexedPrimitiveUP( D3DPT_QUADLIST, 0, 8, 6, pIndexData, D3DFMT_INDEX16,
                                          pVertexData, sizeof( XMFLOAT3 ) );
    SimpleShaders::EndShader();
}
Ejemplo n.º 20
0
	XMMATRIX Transform::GetTransformMatrix()
	{
		XMVECTOR scaleVector(m_Scale.AsXMVECTOR());
		XMVECTOR rotationVector(m_Rotation.AsXMVECTOR());
		XMVECTOR positionVector(m_Position.AsXMVECTOR());
		return XMMatrixScalingFromVector(scaleVector) * XMMatrixRotationQuaternion(rotationVector) * XMMatrixTranslationFromVector(positionVector);
	}
Ejemplo n.º 21
0
bool CollisionMesh::CheckCollisionsCustom(CollisionMesh &otherMesh)
{
  bool collision = false;
  std::vector<XMFLOAT3> convexHull;

  std::vector<VPCNTDesc> vertices = GetVertices();
  std::vector<VPCNTDesc> otherVertices = otherMesh.GetVertices();
  XMMATRIX otherWorld = otherMesh.GetWorldTransform();
  XMMATRIX world = GetWorldTransform();
  XMFLOAT3 origin = XMFLOAT3(0.0f, 0.0f, 0.0f);

  // Create a vector to ease the inversion calculation (we want the opposite direction for the translation vector).
  XMVECTOR inverse = XMVectorSet(-1.0f, -1.0f, -1.0f, 0.0f);
  
  XMVECTOR ourOriginDisplacement = XMVector3Transform(XMVectorSet(origin.x, origin.y, origin.z, 0.0f), world);
  XMMATRIX ourOriginTransform = XMMatrixTranslationFromVector(XMVectorMultiply(ourOriginDisplacement, inverse));

  // This is used for the purposes of moving the normals of the other object back to around (0, 0, 0).
  XMVECTOR theirOriginDisplacement = XMVector3Transform(XMVectorSet(origin.x, origin.y, origin.z, 0.0f), otherWorld);
  XMMATRIX theirOriginTransform = XMMatrixTranslationFromVector(XMVectorMultiply(theirOriginDisplacement, inverse));

  XMMATRIX ourOriginTranslatedWorld = world * ourOriginTransform;
  XMMATRIX theirOriginTranslatedWorld = otherWorld * ourOriginTransform;
  XMMATRIX theirOriginTranslatedWorldNormalAdjustment = theirOriginTransform * otherWorld;

  // Pre-multiply the model's vertices so as to avoid transforming them during comparison.
  for (int vertIndex = 0; vertIndex < vertices.size(); vertIndex++)
  {
    XMStoreFloat3(&vertices[vertIndex].Position, XMVector3Transform(XMLoadFloat3(&vertices[vertIndex].Position), ourOriginTranslatedWorld));
    XMStoreFloat3(&vertices[vertIndex].Normal, XMVector3Transform(XMLoadFloat3(&vertices[vertIndex].Normal), ourOriginTranslatedWorld));
  }

  for (int otherVertIndex = 0; otherVertIndex < otherVertices.size(); otherVertIndex++)
  {
    XMStoreFloat3(&otherVertices[otherVertIndex].Position, XMVector3Transform(XMLoadFloat3(&otherVertices[otherVertIndex].Position), theirOriginTranslatedWorld));
    XMStoreFloat3(&otherVertices[otherVertIndex].Normal, XMVector3Transform(XMLoadFloat3(&otherVertices[otherVertIndex].Normal), theirOriginTranslatedWorldNormalAdjustment));
  }

  int potentialCollisions = 0;
  std::vector<XMFLOAT3> positions;

  // Now that the pre-multiplication is done, time to do our first-case checking: are we inside of it?
  for (int vertIndex = 0; vertIndex < vertices.size(); vertIndex++)
  {
    bool localCollision = true;
    XMVECTOR ourVertex = XMLoadFloat3(&vertices[vertIndex].Position);
    XMVECTOR ourNormal = XMLoadFloat3(&vertices[vertIndex].Normal);

    // For each vertex in our mesh, we'll check to see if it resides inside our other mesh.
    for (int otherVertIndex = 0; otherVertIndex < otherVertices.size(); otherVertIndex++)
    {
      XMVECTOR otherVertex = XMLoadFloat3(&otherVertices[otherVertIndex].Position);
      XMVECTOR otherNormal = XMLoadFloat3(&otherVertices[otherVertIndex].Normal);

      XMVECTOR difference = XMVectorSubtract(ourVertex, otherVertex);
      XMFLOAT3 differenceDotValue, normalDotValue;
      XMVECTOR diffLength = XMVector3Length(difference);
      XMVECTOR normLength = XMVector3Length(otherNormal);
      XMVECTOR magnitude = XMVectorMultiply(diffLength, normLength);

      XMStoreFloat3(&differenceDotValue, XMVectorDivide(XMVector3Dot(difference, otherNormal), magnitude));
      // At this point, we should have the cosine of the angle.
      float angleInRads = acosf(differenceDotValue.x);
      float angleInDegs = XMConvertToDegrees(angleInRads);

      XMStoreFloat3(&normalDotValue, XMVector3Dot(ourNormal, otherNormal));

      if (angleInDegs < 90.0f)
      {
        localCollision = false;
      }
    }

    if (localCollision)
    {
      positions.push_back(vertices[vertIndex].Position);
    }
  }

  if (positions.empty())
  {
    // Time to do our second-case checking: is it inside of us?
    for (int otherVertIndex = 0; otherVertIndex < otherVertices.size(); otherVertIndex++)
    {
      bool localCollision = true;
      XMVECTOR otherVertex = XMLoadFloat3(&otherVertices[otherVertIndex].Position);
      XMVECTOR otherNormal = XMVector3Normalize(XMLoadFloat3(&otherVertices[otherVertIndex].Normal));

      // For each vertex in our mesh, we'll check to see if it resides inside our other mesh.
      for (int vertIndex = 0; vertIndex < vertices.size(); vertIndex++)
      {
        XMVECTOR ourVertex = XMLoadFloat3(&vertices[vertIndex].Position);
        XMVECTOR ourNormal = XMVector3Normalize(XMLoadFloat3(&vertices[vertIndex].Normal));

        XMVECTOR difference = XMVectorSubtract(otherVertex, ourVertex);
        XMFLOAT3 differenceDotValue, normalDotValue;
        XMVECTOR diffLength = XMVector3Length(difference);
        XMVECTOR normLength = XMVector3Length(ourNormal);
        XMVECTOR magnitude = XMVectorMultiply(diffLength, normLength);

        XMStoreFloat3(&differenceDotValue, XMVectorDivide(XMVector3Dot(difference, ourNormal), magnitude));
        // At this point, we should have the cosine of the angle.
        float angleInRads = acosf(differenceDotValue.x);
        float angleInDegs = XMConvertToDegrees(angleInRads);

        XMStoreFloat3(&normalDotValue, XMVector3Dot(ourNormal, otherNormal));

        if (angleInDegs < 90.0f)
        {
          localCollision = false;
        }
      }

      if (localCollision)
      {
        positions.push_back(otherVertices[otherVertIndex].Position);
      }
    }
  }

  if(positions.size())
  {
    mDelegate->CollisionOccurred(otherMesh.mDelegate);
    otherMesh.mDelegate->CollisionOccurred(mDelegate);
  }
  return positions.size();
}
Ejemplo n.º 22
0
bool IcePatchViewModel::RenderEntity(ID3D11DeviceContext* deviceContext, XMFLOAT4X4 viewMatrix, XMFLOAT4X4 projectionMatrix, ColorShader* colorShader, TextureShader* textureShader, IcePatchObstacle* entity)
{
	//writeTextToConsole(L"IcePatchViewModel::RenderEntity");

	if(!textureShader) return false; //we were not provided with a shader

	XMFLOAT3 positionVector = entity->getPosition();
	positionVector.z += 0.01f;
	positionVector.x -= 1.5f;
	XMFLOAT4X4 worldMatrix;
	XMStoreFloat4x4(&worldMatrix, XMLoadFloat4x4( &GetOrientation()));

	//SNOWFIELD MODEL RENDER
	XMFLOAT4X4 snowFieldMatrix;
	XMStoreFloat4x4(&snowFieldMatrix, XMLoadFloat4x4( &worldMatrix) * XMMatrixScaling(3.0f, entity->getLength(), 0.0f) * XMMatrixTranslationFromVector( XMLoadFloat3( &positionVector )));

	icePatchVertexModel->Render(deviceContext);

	bool result = textureShader->Render(deviceContext, 
										icePatchVertexModel->GetIndexCount(), 
										snowFieldMatrix, 
										viewMatrix, 
										projectionMatrix,
										icePatchTexture->GetTexture()); //get the texture to render

	return result; 
}
Ejemplo n.º 23
0
// Where the main rendering occurs
void ForwardRenderer::render(float dt, ID3D11Device* pDevice, ID3D11DeviceContext* pContext, IDXGISwapChain* pSwapChain) {
    if (!pRenderTarget) {
        return;
    }
    
    // Update our time
    static float t = 0.0f;
    if( g_driverType == D3D_DRIVER_TYPE_REFERENCE )
    {
        t += ( float )XM_PI * 0.0125f;
    }
    else
    {
        static DWORD dwTimeStart = 0;
        DWORD dwTimeCur = GetTickCount();
        if( dwTimeStart == 0 )
            dwTimeStart = dwTimeCur;
        t = ( dwTimeCur - dwTimeStart ) / 1000.0f;
    }

    // Rotate cube around the origin
	g_World = XMMatrixRotationY( t );

    // Setup our lighting parameters
    XMFLOAT4 vLightDirs[2] =
    {
        XMFLOAT4( -0.577f, 0.577f, -0.577f, 1.0f ),
        XMFLOAT4( 0.0f, 0.0f, -1.0f, 1.0f ),
    };
    XMFLOAT4 vLightColors[2] =
    {
        XMFLOAT4( 0.5f, 0.7f, 0.5f, 1.0f ),
        XMFLOAT4( 0.7f, 0.0f, 0.0f, 1.0f )
    };

    // Rotate the second light around the origin
	XMMATRIX mRotate = XMMatrixRotationY( -2.0f * t );
	XMVECTOR vLightDir = XMLoadFloat4( &vLightDirs[1] );
	vLightDir = XMVector3Transform( vLightDir, mRotate );
	XMStoreFloat4( &vLightDirs[1], vLightDir );

    //
    // Animate the cube
    //
    // TODO Replace this withe the object's world matrix
	g_World = XMMatrixRotationY( t );

    //
    // Clear the back buffer
    //
    float ClearColor[4] = { 0.0f, 0.125f, 0.3f, 1.0f }; // red,green,blue,alpha
    pContext->ClearRenderTargetView( pRenderTarget, ClearColor );
    
    //
    // Clear the depth buffer to 1.0 (max depth)
    //
    pContext->ClearDepthStencilView( mDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0 );

    //
    // Update variables
    //
    XMMATRIX cameraMatrix = XMLoadFloat4x4(&pTestCamera->updateCamera(dt));

    ConstantBuffer cb;
	cb.mWorld = XMMatrixTranspose( g_World );
	cb.mView = XMMatrixTranspose( cameraMatrix );
	cb.mProjection = XMMatrixTranspose( g_Projection );
	cb.vLightDir[0] = vLightDirs[0];
	cb.vLightDir[1] = vLightDirs[1];
	cb.vLightColor[0] = vLightColors[0];
	cb.vLightColor[1] = vLightColors[1];
	cb.vOutputColor = XMFLOAT4(0, 0, 0, 0);
	pContext->UpdateSubresource( (g_pConstantBuffer), 0, NULL, &cb, 0, 0 );

    pTestShader->prepareToDraw(pContext,(g_pConstantBuffer));

    pTestMesh->SetAndDraw(pContext);

    //
    // Render each light
    //
    for( int m = 0; m < 2; m++ )
    {
		XMMATRIX mLight = XMMatrixTranslationFromVector( 5.0f * XMLoadFloat4( &vLightDirs[m] ) );
		XMMATRIX mLightScale = XMMatrixScaling( 0.2f, 0.2f, 0.2f );
        mLight = mLightScale * mLight;

        // Update the world variable to reflect the current light
		cb.mWorld = XMMatrixTranspose( mLight );
		cb.vOutputColor = vLightColors[m];
		pContext->UpdateSubresource( g_pConstantBuffer, 0, NULL, &cb, 0, 0 );

		pContext->PSSetShader( g_pPixelShaderSolid, NULL, 0 );
        pTestMesh->SetAndDraw(pContext);
    }
    
    //
    // Present our back buffer to our front buffer
    //
    pSwapChain->Present( 0, 0 );
}
void Triangle::setPosition(CXMVECTOR a_Position)
{
    XMMATRIX transform = XMMatrixTranslationFromVector(a_Position);
    XMStoreFloat4x4(&m_Transform, transform);
}
Ejemplo n.º 25
0
		static Matrix translation(const Vector3& v)
		{
			return static_cast<Matrix>(XMMatrixTranslationFromVector(v));
		}