コード例 #1
0
TriangleMesh* DebugGeometryBuilder::createBoxHeadedArrow( float size, const Vector& start, const Vector& end )
{
   FastFloat simdSize; simdSize.setFromFloat( size );

   Vector dir;
   dir.setSub( end, start );
   dir.normalize();

   Vector perpVec1, perpVec2;
   VectorUtil::calculatePerpendicularVector( dir, perpVec1 );
   perpVec1.normalize();
   perpVec2.setCross( dir, perpVec1 );

   perpVec1.mul( simdSize );
   perpVec2.mul( simdSize );


   // the line
   std::vector<LitVertex> vertices;
   std::vector<Face> faces;
   addCuboid( simdSize, start, end, vertices, faces );
   
   // and the box-shaped tip
   FastFloat tipSize; tipSize.setFromFloat( 6 * size );
   Vector tipEnd;
   tipEnd.setMulAdd( dir, tipSize, end );
   addCuboid( tipSize, end, tipEnd, vertices, faces );
   
   TriangleMesh* mesh = new TriangleMesh( FilePath(), vertices, faces );
   return mesh;
}
コード例 #2
0
void DebugGeometryBuilder::addCone( const FastFloat& baseSize, const Vector& start, const Vector& end, std::vector< LitVertex >& outVertices, std::vector< Face >& outFaces )
{
   // calculate additional vectors needed for cuboid construction
   Vector dir;
   dir.setSub( end, start );
   dir.normalize();

   Vector perpVec1, perpVec2;
   VectorUtil::calculatePerpendicularVector( dir, perpVec1 );
   perpVec1.normalize();
   perpVec2.setCross( dir, perpVec1 );

   perpVec1.mul( baseSize );
   perpVec2.mul( baseSize );

   // calculate the vertices and outFaces
   uint firstVtxIdx = outVertices.size();
   uint firstFaceIdx = outFaces.size();

   for( uint i = 0; i < 5; ++i )
   {
      outVertices.push_back( LitVertex() );
   }
   for( uint i = 0; i < 6; ++i )
   {
      outFaces.push_back( Face() );
   }

   Vector tmpVec;
   {
      perpVec1.mul( Float_6 );
      perpVec2.mul( Float_6 );

      tmpVec.setAdd( start, perpVec1 ); tmpVec.sub( perpVec2 ); tmpVec.store( outVertices[firstVtxIdx + 0].m_coords );
      tmpVec.setSub( start, perpVec1 ); tmpVec.sub( perpVec2 ); tmpVec.store( outVertices[firstVtxIdx + 1].m_coords );
      tmpVec.setAdd( start, perpVec1 ); tmpVec.add( perpVec2 ); tmpVec.store( outVertices[firstVtxIdx + 2].m_coords );
      tmpVec.setSub( start, perpVec1 ); tmpVec.add( perpVec2 ); tmpVec.store( outVertices[firstVtxIdx + 3].m_coords );

      FastFloat tipSizeMultiplier; tipSizeMultiplier.setFromFloat( 12 );
      tipSizeMultiplier.mul( baseSize );
      tmpVec.setMulAdd( dir, tipSizeMultiplier, end ); tmpVec.store( outVertices[firstVtxIdx + 4].m_coords );

      // cone bottom
      outFaces[firstFaceIdx + 0].idx[0] = firstVtxIdx + 0; outFaces[firstFaceIdx + 0].idx[1] = firstVtxIdx + 1; outFaces[firstFaceIdx + 0].idx[2] = firstVtxIdx + 2;
      outFaces[firstFaceIdx + 1].idx[0] = firstVtxIdx + 1; outFaces[firstFaceIdx + 1].idx[1] = firstVtxIdx + 3; outFaces[firstFaceIdx + 1].idx[2] = firstVtxIdx + 2;

      // cone top
      outFaces[firstFaceIdx + 2].idx[0] = firstVtxIdx + 0;   outFaces[firstFaceIdx + 2].idx[1] = firstVtxIdx + 4;   outFaces[firstFaceIdx + 2].idx[2] = firstVtxIdx + 1;
      outFaces[firstFaceIdx + 3].idx[0] = firstVtxIdx + 1;   outFaces[firstFaceIdx + 3].idx[1] = firstVtxIdx + 4;   outFaces[firstFaceIdx + 3].idx[2] = firstVtxIdx + 3;
      outFaces[firstFaceIdx + 4].idx[0] = firstVtxIdx + 3;   outFaces[firstFaceIdx + 4].idx[1] = firstVtxIdx + 4;   outFaces[firstFaceIdx + 4].idx[2] = firstVtxIdx + 2;
      outFaces[firstFaceIdx + 5].idx[0] = firstVtxIdx + 2;   outFaces[firstFaceIdx + 5].idx[1] = firstVtxIdx + 4;   outFaces[firstFaceIdx + 5].idx[2] = firstVtxIdx + 0;
   }

}
コード例 #3
0
void CameraMovementController::update( float timeElapsed )
{
   float speedMul =m_uic->isKeyPressed( VK_SHIFT ) ? 4.0f : 1.0f;
   FastFloat movementSpeed; movementSpeed.setFromFloat( 10.0f * speedMul * timeElapsed );
   FastFloat negMovementSpeed; negMovementSpeed.setNeg( movementSpeed );
   float rotationSpeed = 0.1f * timeElapsed;

   // check which keys are pressed
   m_movementDir[MD_FRONT] = m_uic->isKeyPressed( 'W' );
   m_movementDir[MD_BACK] = m_uic->isKeyPressed( 'S' );
   m_movementDir[MD_LEFT] = m_uic->isKeyPressed( 'A' );
   m_movementDir[MD_RIGHT] = m_uic->isKeyPressed( 'D' );

   m_rotating = m_uic->isKeyPressed( VK_RBUTTON );
   m_uic->setRelativeMouseMovement( m_rotating );

   // process the keys
   Vector moveVec;
   if ( m_movementDir[MD_FRONT] )  
   { 
      moveVec.setMul( m_cameraController->getLookVec(), movementSpeed );
      m_cameraController->move( moveVec ); 
   }

   if ( m_movementDir[MD_BACK] )
   { 
      moveVec.setMul( m_cameraController->getLookVec(), negMovementSpeed );
      m_cameraController->move( moveVec ); 
   }

   if ( m_movementDir[MD_LEFT] )   
   { 
      moveVec.setMul( m_cameraController->getRightVec(), negMovementSpeed );
      m_cameraController->move( moveVec ); 
   }

   if ( m_movementDir[MD_RIGHT] )
   { 
      moveVec.setMul( m_cameraController->getRightVec(), movementSpeed );
      m_cameraController->move( moveVec ); 
   }

   if ( m_rotating )
   {
      float mouseSpeedX = m_uic->getMouseSpeed().v[0] * rotationSpeed;
      float mouseSpeedY = m_uic->getMouseSpeed().v[1] * rotationSpeed;
      m_cameraController->rotate( mouseSpeedY, mouseSpeedX );
   }
}
コード例 #4
0
ファイル: BTAMoveWithVelocity.cpp プロジェクト: dabroz/Tamy
BehTreeNode::Result BTAMoveWithVelocity::execute( BehaviorTreeRunner& runner ) const
{   
   RuntimeDataBuffer& data = runner.data( );
   PhysicsCharacterController* characterController = data[m_characterController];

   if ( !m_velocity  )
   {
      LOG( "BTAMoveWithVelocity: Assign a velocity variable" );
      return FAILED;
   }

   if ( !m_characterRotation )
   {
      LOG( "BTAMoveWithVelocity: Assign a character rotation variable" );
      return FAILED;
   }

   if ( !characterController )
   {
      LOG( "BTAMoveWithVelocity: The character doesn't have a PhysicsCharacterController component" );
      return FAILED;
   }

   StoryBehTreeContext* context = (StoryBehTreeContext*)runner.getContext();
   StoryNodeInstance* controlledNodeInstance = context->m_ownerInstance;

   // calculate displacement
   TimeController& timeController = TSingleton< TimeController >::getInstance();

   Vector movementVelocity = m_velocity->getRuntime( &runner );
   characterController->setLinearVelocity( movementVelocity );


   // calculate new facing direction and a corresponding orientation
   {
      Matrix nodeTransform = controlledNodeInstance->getLocalMtx( );

      FastFloat dYaw; dYaw.setFromFloat( m_characterRotation->getRuntime( &runner ) );

      Vector angularVelocity; angularVelocity.set( Float_0, Float_0, dYaw );

      characterController->setAngularVelocity( angularVelocity );
   }

   return FINISHED;
}
コード例 #5
0
void DeferredPointLightRenderer::render( Renderer& renderer, const PointLight* light, const DeferredLightingRenderData& data )
{
   if ( !m_pixelShader || !m_vertexShader || !m_pointLightMesh )
   {
      return;
   }

   Camera& activeCamera = renderer.getActiveCamera();
   Matrix globalMtx = light->getGlobalMtx();

   Matrix viewProjMtx;
   viewProjMtx.setMul( activeCamera.getViewMtx(), activeCamera.getProjectionMtx() ); 

   // activate the final render target
   new ( renderer() ) RCActivateRenderTarget( data.m_finalLightColorTarget );

   // set and configure the pixel shader
   RCBindPixelShader* psComm = new ( renderer() ) RCBindPixelShader( *m_pixelShader, renderer );
   {
      Matrix mtxInvProj;
      mtxInvProj.setInverse( activeCamera.getProjectionMtx() );

      Vector lightOriginViewSpace;
      activeCamera.getViewMtx().transform( globalMtx.position(), lightOriginViewSpace );

      Vector halfPixel;
      ShaderUtils::calculateHalfPixel( renderer, data.m_depthTex, halfPixel );

      psComm->setVec4( "g_halfPixel", halfPixel );
      psComm->setVec4( "g_lightOriginVS", lightOriginViewSpace );
      psComm->setVec4( "g_lightColor", ( const Vector& )light->m_color );
      psComm->setFloat( "g_strength", light->m_strength );
      psComm->setFloat( "g_attenuation", light->m_attenuation );
      psComm->setFloat( "g_radius", light->m_radius );
      psComm->setFloat( "g_farZ", activeCamera.getFarClippingPlane() );
      psComm->setMtx( "g_mtxProjToView", mtxInvProj );
      psComm->setTexture( "g_Depth", data.m_depthTex );
      psComm->setTexture( "g_Normals", data.m_normalsTex );
      psComm->setTexture( "g_Specular", data.m_specularTex );
      psComm->setTexture( "g_SceneColor", data.m_sceneColorTex );
      psComm->setInt( "g_materialsTexSize", data.m_materialsDescriptorsTex->getWidth() );
      psComm->setTexture( "g_MaterialIndices", data.m_materialIndicesTex );
      psComm->setTexture( "g_MaterialsDescr", data.m_materialsDescriptorsTex );
   }

   // set and configure the vertex shader
   RCBindVertexShader* vsComm = new ( renderer() ) RCBindVertexShader( *m_vertexShader, renderer );
   {
      FastFloat rad; rad.setFromFloat( light->m_radius );
      Matrix scaleMtx; scaleMtx.scaleUniform( rad );
      Matrix modelViewProjMtx;      
      modelViewProjMtx.setMul( scaleMtx, globalMtx );
      modelViewProjMtx.mul( viewProjMtx );

      vsComm->setMtx( "g_mtxModelViewProj", modelViewProjMtx );
   }

   // draw the geometry
   m_pointLightMesh->render( renderer );

   // cleanup
   new ( renderer() ) RCUnbindVertexShader( *m_vertexShader );
   new ( renderer() ) RCUnbindPixelShader( *m_pixelShader, renderer );
   new ( renderer() ) RCDeactivateRenderTarget();
}
コード例 #6
0
ファイル: FastFloat.cpp プロジェクト: chenwenbin928/tamy
const FastFloat FastFloat::fromFloat( float val )
{
   FastFloat f;
   f.setFromFloat( val );
   return f;
}
コード例 #7
0
TriangleMesh* DebugGeometryBuilder::createTorus( float innerRadius, float outerRadius, const Matrix& transform, int segmentsCount, int segmentVerticesCount )
{
   const Vector& origin = transform.position();
   const Vector& mainAxis = transform.forwardVec();
   const Vector& sideAxis = transform.sideVec();
   Vector circumferenceAxis = transform.upVec();

   FastFloat circumferenceWidth; circumferenceWidth.setFromFloat( outerRadius - innerRadius );
   FastFloat radius; radius.setFromFloat( innerRadius + outerRadius - innerRadius );

   // calculate torus vertices
   const uint verticesCount = segmentsCount * segmentVerticesCount;
   std::vector<LitVertex> vertices( verticesCount );
   {
      FastFloat dMainAngle; dMainAngle.setFromFloat( DEG2RAD( 360.0f / (float)segmentsCount ) );
      FastFloat dSegmentAngle; dSegmentAngle.setFromFloat( DEG2RAD( 360.0f / (float)segmentVerticesCount ) );
      FastFloat mainAngle = Float_0;

      Quaternion mainRot, circumferenceRot;
      Vector vtxPos, posOnCircumference, radiusDisplacement, radiusVec, torusVtx;
      radiusVec.setMul( sideAxis, radius );
      uint vtxIdx = 0;
      for ( uint segmentIdx = 0; segmentIdx < segmentsCount; ++segmentIdx, mainAngle.add( dMainAngle ) )
      {
         mainRot.setAxisAngle( mainAxis, mainAngle );
         mainRot.transform( radiusVec, radiusDisplacement );

         FastFloat segmentAngle = Float_0;
         for ( uint segVtxIdx = 0; segVtxIdx < segmentVerticesCount; ++segVtxIdx, segmentAngle.add( dSegmentAngle ) )
         {
            circumferenceRot.setAxisAngle( circumferenceAxis, segmentAngle );
            Quaternion rotQ;
            rotQ.setMul( circumferenceRot, mainRot );

            // first - create a point on the circumference of the toruses' segment
            vtxPos.setMul( sideAxis, circumferenceWidth );
            rotQ.transform( vtxPos, posOnCircumference );

            // and displace the circumference point so that it ends up in its final position on the toruses' circumference
            torusVtx.setAdd( radiusDisplacement, posOnCircumference );
            torusVtx.add( origin );

            // store the vertex
            torusVtx.store( vertices[vtxIdx].m_coords );
            ++vtxIdx;
         }
      }
   }

   // set torus indices
   const uint outFacesCount = verticesCount * 2;
   std::vector<Face> outFaces( outFacesCount );
   {
      uint faceIdx = 0;
      for ( uint segmentIdx = 0; segmentIdx < segmentsCount; ++segmentIdx )
      {
         uint currSegmentFirstVtx = segmentIdx * segmentVerticesCount;
         uint nextSegmentFirstVtx = ( currSegmentFirstVtx + segmentVerticesCount ) % verticesCount;

         for ( uint segVtxIdx = 0; segVtxIdx < segmentVerticesCount; ++segVtxIdx )
         {
            uint skipOffset = 0;
            if ( segVtxIdx == 0 )
            {
               skipOffset = segmentVerticesCount;
            }

            outFaces[faceIdx].idx[0] = currSegmentFirstVtx + segVtxIdx - 1 + skipOffset;
            outFaces[faceIdx].idx[1] = currSegmentFirstVtx + segVtxIdx;
            outFaces[faceIdx].idx[2] = nextSegmentFirstVtx + segVtxIdx - 1 + skipOffset;
            ++faceIdx;

            outFaces[faceIdx].idx[0] = currSegmentFirstVtx + segVtxIdx;
            outFaces[faceIdx].idx[1] = nextSegmentFirstVtx + segVtxIdx;
            outFaces[faceIdx].idx[2] = nextSegmentFirstVtx + segVtxIdx - 1 + skipOffset;
            ++faceIdx;
         }
      }
   }

   TriangleMesh* mesh = new TriangleMesh( FilePath(), vertices, outFaces );
   return mesh;
}