예제 #1
0
void EditorCamera::mainLoop()
{
   if (mRenderCamera == NULL)
      return;

   mVerticalAngle = mClampF(mVerticalAngle, -4.7f, -1.7f);
   VectorF rotation = mTransform.getRotationEuler();
   rotation.y = mVerticalAngle;
   rotation.z = mHorizontalAngle;
   mTransform.setRotation(rotation);

   VectorF up(0.0f, 0.0f, 1.0f);
   Point3F look;
   Point3F cameraForward(1.0f, 0.0f, 0.0f);

   bx::vec3MulMtx(look, cameraForward, mTransform.matrix);

   if (mForwardVelocity.len() > 0.01f)
   {
      MatrixF lookMatrix;
      bx::mtxLookAt(lookMatrix, mWorldPosition, look, up);
      mWorldPosition += (lookMatrix.getForwardVector() * mForwardVelocity.x);
      mWorldPosition -= (lookMatrix.getRightVector() * mForwardVelocity.y);
      mTransform.setPosition(mWorldPosition);
   }

   bx::vec3MulMtx(look, cameraForward, mTransform.matrix);
   bx::mtxLookAt(mRenderCamera->viewMatrix, mWorldPosition, look, up);
   mRenderCamera->position = mWorldPosition;
}
예제 #2
0
void OrientedBox3F::set( const MatrixF& transform, const Point3F& extents )
{
   mCenter = transform.getPosition();

   mAxes[ RightVector ] = transform.getRightVector();
   mAxes[ ForwardVector ] = transform.getForwardVector();
   mAxes[ UpVector ] = transform.getUpVector();

   mHalfExtents = extents * 0.5f;

   _initPoints();
}
예제 #3
0
void OrientedBox3F::set( const MatrixF& transform, const Box3F& aabb )
{
   mCenter = aabb.getCenter();
   transform.mulP( mCenter );

   mAxes[ RightVector ] = transform.getRightVector();
   mAxes[ ForwardVector ] = transform.getForwardVector();
   mAxes[ UpVector ] = transform.getUpVector();

   mHalfExtents[ 0 ] = aabb.len_x() / 2.f;
   mHalfExtents[ 1 ] = aabb.len_y() / 2.f;
   mHalfExtents[ 2 ] = aabb.len_z() / 2.f;

   _initPoints();
}
void AdvancedLightBinManager::_setupPerFrameParameters( const SceneRenderState *state )
{
   PROFILE_SCOPE( AdvancedLightBinManager_SetupPerFrameParameters );
   const Frustum &frustum = state->getCameraFrustum();

   MatrixF invCam( frustum.getTransform() );
   invCam.inverse();

   const Point3F *wsFrustumPoints = frustum.getPoints();
   const Point3F& cameraPos = frustum.getPosition();

   // Perform a camera offset.  We need to manually perform this offset on the sun (or vector) light's
   // polygon, which is at the far plane.
   const Point2F& projOffset = frustum.getProjectionOffset();
   Point3F cameraOffsetPos = cameraPos;
   if(!projOffset.isZero())
   {
      // First we need to calculate the offset at the near plane.  The projOffset
      // given above can be thought of a percent as it ranges from 0..1 (or 0..-1).
      F32 nearOffset = frustum.getNearRight() * projOffset.x;

      // Now given the near plane distance from the camera we can solve the right
      // triangle and calcuate the SIN theta for the offset at the near plane.
      // SIN theta = x/y
      F32 sinTheta = nearOffset / frustum.getNearDist();

      // Finally, we can calcuate the offset at the far plane, which is where our sun (or vector)
      // light's polygon is drawn.
      F32 farOffset = frustum.getFarDist() * sinTheta;

      // We can now apply this far plane offset to the far plane itself, which then compensates
      // for the project offset.
      MatrixF camTrans = frustum.getTransform();
      VectorF offset = camTrans.getRightVector();
      offset *= farOffset;
      cameraOffsetPos += offset;
   }

   // Now build the quad for drawing full-screen vector light
   // passes.... this is a volatile VB and updates every frame.
   FarFrustumQuadVert verts[4];
   {
      verts[0].point.set( wsFrustumPoints[Frustum::FarBottomLeft] - cameraPos );
      invCam.mulP( wsFrustumPoints[Frustum::FarBottomLeft], &verts[0].normal );
      verts[0].texCoord.set( -1.0, -1.0 );
      verts[0].tangent.set(wsFrustumPoints[Frustum::FarBottomLeft] - cameraOffsetPos);

      verts[1].point.set( wsFrustumPoints[Frustum::FarTopLeft] - cameraPos );
      invCam.mulP( wsFrustumPoints[Frustum::FarTopLeft], &verts[1].normal );
      verts[1].texCoord.set( -1.0, 1.0 );
      verts[1].tangent.set(wsFrustumPoints[Frustum::FarTopLeft] - cameraOffsetPos);

      verts[2].point.set( wsFrustumPoints[Frustum::FarTopRight] - cameraPos );
      invCam.mulP( wsFrustumPoints[Frustum::FarTopRight], &verts[2].normal );
      verts[2].texCoord.set( 1.0, 1.0 );
      verts[2].tangent.set(wsFrustumPoints[Frustum::FarTopRight] - cameraOffsetPos);

      verts[3].point.set( wsFrustumPoints[Frustum::FarBottomRight] - cameraPos );
      invCam.mulP( wsFrustumPoints[Frustum::FarBottomRight], &verts[3].normal );
      verts[3].texCoord.set( 1.0, -1.0 );
      verts[3].tangent.set(wsFrustumPoints[Frustum::FarBottomRight] - cameraOffsetPos);
   }
   mFarFrustumQuadVerts.set( GFX, 4 );
   dMemcpy( mFarFrustumQuadVerts.lock(), verts, sizeof( verts ) );
   mFarFrustumQuadVerts.unlock();

   PlaneF farPlane(wsFrustumPoints[Frustum::FarBottomLeft], wsFrustumPoints[Frustum::FarTopLeft], wsFrustumPoints[Frustum::FarTopRight]);
   PlaneF vsFarPlane(verts[0].normal, verts[1].normal, verts[2].normal);

   // Parameters calculated, assign them to the materials
   LightMatTable::Iterator iter = mLightMaterials.begin();
   for ( ; iter != mLightMaterials.end(); iter++ )
   {
      if ( iter->value )
         iter->value->setViewParameters(  frustum.getNearDist(), 
                                          frustum.getFarDist(), 
                                          frustum.getPosition(), 
                                          farPlane, 
                                          vsFarPlane);
   }
}