// Sets the rotation matrix to a given value.
void GameObject::SetRotation(glm::mat4* rotMatrix)
{
	rotation = *rotMatrix;

	// Then we have to recalculate the transformation matrix.
	CalculateMatrices();
}
// Sets the translations to the exact x, y, and z position values given.
void GameObject::SetTranslation(glm::vec3 transFactor)
{
	// Translates the identity matrix.
	translation = glm::translate(glm::mat4(), transFactor);

	// Then we have to recalculate the transformation matrix.
	CalculateMatrices();
}
// Translates in the x, y, and z directions based on the given values.
void GameObject::Translate(glm::vec3 transFactor)
{
	// Translates the translation matrix.
	translation = glm::translate(translation, transFactor);

	// Then we have to recalculate the transformation matrix.
	CalculateMatrices();
}
// Sets the scale in the x, y, and z position to the given values.
void GameObject::SetScale(glm::vec3 scaleFactor)
{
	// Scales the identity matrix.
	scale = glm::scale(glm::mat4(), scaleFactor);

	// Then we have to recalculate the transformation matrix.
	CalculateMatrices();
}
// Scales the current scale value by the x, y and z values given. (So if the scale is [0.5, 0.5, 0.5] and we pass in [0.5, 0.5, 0.5] we end up with [0.25, 0.25, 0.25].)
void GameObject::Scale(glm::vec3 scaleFactor)
{
	// Scales the scale matrix.
	scale = glm::scale(scale, scaleFactor);

	// Then we have to recalculate the transformation matrix.
	CalculateMatrices();
}
Exemple #6
0
void cShadowMapping::BeginRenderToShadowMap(opengl::cContext& context, const spitfire::math::cVec3& lightPosition, const spitfire::math::cVec3& lightDirection)
{
  const spitfire::math::cColour clearColour(0.0f, 0.0f, 0.0f);
  context.SetClearColour(clearColour);

  context.BeginRenderToTexture(textureDepthTexture);

  context.BindShader(shaderRenderToDepthTexture);

  CalculateMatrices(context, lightPosition, lightDirection);
}
// Sets the rotation matrix to a given value of x, y, and z radians.
void GameObject::SetRotation(glm::vec3 rotFactor)
{
	// WARNING: These are interpreted as radian values, so be sure to specify them not as degrees.

	// Set our quaternion equal to a quaternion created from the given euler angles.
	quaternion = glm::quat(rotFactor);

	// Turn our quaternion into a mat4.
	rotation = glm::toMat4(quaternion);

	// Then we have to recalculate the transformation matrix.
	CalculateMatrices();
}
// Rotates in x, y, and z radians based on given values.
void GameObject::Rotate(glm::vec3 rotFactor)
{
	// WARNING: These are interpreted as radian values, so be sure to specify them not as degrees.
	
	// Create a quaternion based on the euler angles given.
	glm::quat q = glm::quat(rotFactor);

	// Rotate our quaternion by that quaternion's value.
	quaternion *= q;

	// Turn our quaternion into a mat4.
	rotation = glm::toMat4(quaternion);

	// Then we have to recalculate the transformation matrix.
	CalculateMatrices();
}
void Model::Render(
    ComPtr<ID3D11DeviceContext> const devcon,
    const D3DXMATRIX& viewProjectionMatrix)
{
    // Set the model's input layout as active
    devcon->IASetInputLayout(modelLayout.Get());

    // Set the vertex buffer
    UINT stride = sizeof(Vertex);
    UINT offset = 0;
    devcon->IASetVertexBuffers(0, 1, vertexBuffer.GetAddressOf(), &stride, &offset);
    devcon->IASetIndexBuffer(indexBuffer.Get(), INDEX_FORMAT, 0);

    // Render the model's texture
    material->Render(devcon);

    // Calculate the transformation matrices
    CalculateMatrices(viewProjectionMatrix);
}
Exemple #10
0
// adjust the camera planes to contain the visible scene as tightly as possible
void ShadowCamera::AdjustPlanes(const std::vector<SceneObject *> &VisibleObjects)
{
  if(VisibleObjects.size() == 0) return;

  // find the nearest and farthest points of given
  // scene objects in camera's view space
  //
  float fMaxZ = 0;
  float fMinZ = FLT_MAX;

  noVec3 vDir = Normalize(m_vTarget - m_vSource);

  // for each object
  for(unsigned int i = 0; i < VisibleObjects.size(); i++)
  {
    SceneObject *pObject = VisibleObjects[i];

    // for each point in AABB
    for(int j = 0; j < 8; j++)
    {
      // calculate z-coordinate distance to near plane of camera
      noVec3 vPointToCam = pObject->m_AABB.m_pPoints[j] - m_vSource;
      float fZ = Dot(vPointToCam, vDir);

      // find boundary values
      if(fZ > fMaxZ) fMaxZ = fZ;
      if(fZ < fMinZ) fMinZ = fZ;
    }
  }

  // use smallest distance as new near plane
  // and make sure it is not too small
  m_fNear = Max(fMinZ, m_fNearMin);
  // use largest distance as new far plane
  // and make sure it is larger than nearPlane
  m_fFar = Max(fMaxZ, m_fNear + 1.0f);
  // update matrices
  CalculateMatrices();
}
Exemple #11
0
// processes camera controls
void ShadowCamera::DoControls(void)
{
  float fDeltaTime = DeltaTimeUpdate(m_ControlState.fLastUpdate);

  noVec3 vZ = Normalize(m_vTarget - m_vSource);
  noVec3 vX = Normalize(Cross(m_vUpVector, vZ));
  noVec3 vY = Normalize(Cross(vZ, vX));

  // Rotating with mouse left
  //
  //
  if(GetMouseDown(VK_LBUTTON))
  {

    if(!m_ControlState.bRotating)
    {
      GetCursorPos(&m_ControlState.pntMouse);
      m_ControlState.bZooming = false;
      m_ControlState.bStrafing = false;
      m_ControlState.bRotating = true;
    }

    POINT pntMouseCurrent;
    GetCursorPos(&pntMouseCurrent);

    noVec3 vTargetToSource = m_vTarget - m_vSource;
    float fLength = vTargetToSource.Length();

    m_ControlState.fRotX += 0.005f * (float)(pntMouseCurrent.x - m_ControlState.pntMouse.x);
    m_ControlState.fRotY += 0.005f * (float)(pntMouseCurrent.y - m_ControlState.pntMouse.y);

    m_ControlState.fRotY = Clamp(m_ControlState.fRotY, DegreeToRadian(-89.9f), DegreeToRadian(89.9f));

    Matrix mRotation;
    mRotation.SetIdentity();
    mRotation.SetRotation(noVec3(m_ControlState.fRotX, m_ControlState.fRotY,0));
    m_vTarget.x = mRotation._31 * fLength + m_vSource.x;
    m_vTarget.y = mRotation._32 * fLength + m_vSource.y;
    m_vTarget.z = mRotation._33 * fLength + m_vSource.z;

    m_ControlState.pntMouse = pntMouseCurrent;

  // Strafing with mouse middle
  //
  //
  } else if(GetMouseDown(VK_MBUTTON)) {

    if(!m_ControlState.bStrafing)
    {
      GetCursorPos(&m_ControlState.pntMouse);
      m_ControlState.bZooming = false;
      m_ControlState.bRotating = false;
      m_ControlState.bStrafing = true;
    }

    POINT pntMouseCurrent;
    GetCursorPos(&pntMouseCurrent);

    m_vSource -= vX * 0.15f * (float)(pntMouseCurrent.x - m_ControlState.pntMouse.x);
    m_vTarget -= vX * 0.15f * (float)(pntMouseCurrent.x - m_ControlState.pntMouse.x);

    m_vSource += vY * 0.15f * (float)(pntMouseCurrent.y - m_ControlState.pntMouse.y);
    m_vTarget += vY * 0.15f * (float)(pntMouseCurrent.y - m_ControlState.pntMouse.y);

    m_ControlState.pntMouse = pntMouseCurrent;


  // Zooming with mouse right
  //
  //
  } else if(GetMouseDown(VK_RBUTTON)) {

    if(!m_ControlState.bZooming)
    {
      GetCursorPos(&m_ControlState.pntMouse);
      m_ControlState.bZooming = true;
      m_ControlState.bRotating = false;
      m_ControlState.bStrafing = false;
    }

    POINT pntMouseCurrent;
    GetCursorPos(&pntMouseCurrent);

    m_vSource += vZ * 0.5f * (float)(pntMouseCurrent.y - m_ControlState.pntMouse.y);
    m_vTarget += vZ * 0.5f * (float)(pntMouseCurrent.y - m_ControlState.pntMouse.y);

    m_ControlState.pntMouse = pntMouseCurrent;

  // Mouse is idle
  //
  } else {
    m_ControlState.bZooming = false;
    m_ControlState.bRotating = false;
    m_ControlState.bStrafing = false;
  }


  // Move forward/backward
  //
  if(GetKeyDown('W'))
  {
    m_vSource += vZ * fDeltaTime;
    m_vTarget += vZ * fDeltaTime;
  }
  else if(GetKeyDown('S'))
  {
    m_vSource -= vZ * fDeltaTime;
    m_vTarget -= vZ * fDeltaTime;
  }

  // Strafing
  //
  if(GetKeyDown('D'))
  {
    m_vSource += vX * fDeltaTime;
    m_vTarget += vX * fDeltaTime;
  }
  else if(GetKeyDown('A'))
  {
    m_vSource -= vX * fDeltaTime;
    m_vTarget -= vX * fDeltaTime;
  }

  // Up/down (many control preferences here :)
  //
  if(GetKeyDown('Q') || GetKeyDown(VK_SPACE))
  {
    m_vSource += vY * fDeltaTime;
    m_vTarget += vY * fDeltaTime;
  }
  else if(GetKeyDown('E') || GetKeyDown('C') || GetKeyDown(VK_CONTROL))
  {
    m_vSource -= vY * fDeltaTime;
    m_vTarget -= vY * fDeltaTime;
  }

  CalculateMatrices();
}