4D星宇

c++

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  57 随笔 :: 0 文章 :: 39 评论 :: 0 Trackbacks

#

posted @ 2008-05-04 15:37 bloodbao 阅读(145) | 评论 (1)编辑 收藏

//Function to create a NewtonCollision from irrlicht mesh 
NewtonCollision 
*CreateCollisionFromMesh(NewtonWorld *nWorld, scene::IMesh *mesh) 

  
//Get number of vertices 
  u32 nVertices 
= 0, nMeshBuffer; 
  
for( nMeshBuffer = 0 ; nMeshBuffer < mesh->getMeshBufferCount(); ++nMeshBuffer) 
  { 
    scene::IMeshBuffer 
*buffer = mesh->getMeshBuffer(nMeshBuffer); 
    nVertices 
+= buffer->getVertexCount(); 
  } 

  
// allocate block for positions of every vertex in mesh, no need to delete 
  
// anything, the array cleans up for us. 
  core::
array<core::vector3df> vertices; 
  vertices.reallocate(nVertices); 

  
//Get mesh buffers and copy face vertices 
  
for( nMeshBuffer = 0 ; nMeshBuffer < mesh->getMeshBufferCount(); ++nMeshBuffer) 
  { 
    scene::IMeshBuffer 
*buffer = mesh->getMeshBuffer(nMeshBuffer); 

    
// handle the irrlicht supported vertex types 
    switch(buffer
->getVertexType()) 
    { 
    
case video::EVT_STANDARD: 
      { 
        video::S3DVertex
* verts = (video::S3DVertex*)buffer->getVertices(); 
        
for(u32 v = 0; v < buffer->getVertexCount(); ++v) 
          vertices.push_back(verts[v].Pos); 
      } 
      break; 

    
case video::EVT_2TCOORDS: 
      { 
        video::S3DVertex2TCoords
* verts = (video::S3DVertex2TCoords*)buffer->getVertices(); 
        
for(u32 v = 0; v < buffer->getVertexCount(); ++v) 
          vertices.push_back(verts[v].Pos); 
      } 
      break; 

    
case video::EVT_TANGENTS: 
      { 
        video::S3DVertexTangents
* verts = (video::S3DVertexTangents*)buffer->getVertices(); 
        
for(u32 v = 0; v < buffer->getVertexCount(); ++v) 
          vertices.push_back(verts[v].Pos); 
      } 
      break; 

    default: 
      return 
0// don't know vertex type! bail. 
    } 
  } 

  
//Create Newton collision object 
  return NewtonCreateConvexHull(nWorld, nVertices, 
&vertices[0].X, sizeof(core::vector3df), NULL); 
}

core::
array<f32> vertices; 
vertices.reallocate(nVertices 
* 3); 

// each loop should be updated 
for(u32 v = 0; v < buffer->getVertexCount(); ++v) 

  vertices.push_back(verts[v].Pos.X); 
  vertices.push_back(verts[v].Pos.Y); 
  vertices.push_back(verts[v].Pos.Z); 


// this should be passed to the convex hull function 
return NewtonCreateConvexHull(nWorld, nVertices, 
&vertices[0], sizeof(f32 * 3), NULL);
posted @ 2008-05-04 12:20 bloodbao 阅读(232) | 评论 (0)编辑 收藏

IRRLICHT的实现:
1.波浪是如何实现的?
先对每个点计算高度,

void addWave(vector3df& dest, const vector3df source, f32 time

     dest.Y 
= source.Y +
 (sinf(((source.X
/WaveLength) + time)) * WaveHeight) +
 (cosf(((source.Z
/WaveLength) + time)) * WaveHeight);
}


然后再计算法线,
recalculateNormals(Mesh);
2.ATMOSphere
太阳嘛,就是个跟随时间移动的BILLBOARD,边缘最好加上雾化效果。
3.地形编辑器代码

if( Terrain && !RightMouseDown && Terrain->getTriangleSelector() )
{
LastMousePosition.set( Device
->getCursorControl()->getPosition().X, Device->   getCursorControl()->getPosition().Y );
//计算从鼠标位置到观察点的射线
core::line3df line 
= CollisionMgr->getRayFromScreenCoordinates( 
 core::position2d
<s32>( LastMousePosition.X, LastMousePosition.Y ) );
//计算以交点为中心,一定半径范围内的点
core::vector3df spherePosition;
if( CollisionMgr->getClosestVertex( line, Terrain->getTriangleSelector(), 
 spherePosition, CurrentVertexIndex ) )
      {
       LeftMouseDown 
= true;

       
// Get all vertices with the circle
       SelectedTerrainVertices.clear();
       core::vector3df intersection;
       scene::SCollisionTriangle tri;
       
if( CollisionMgr->getCollisionPoint( line, Terrain->getTriangleSelector(), intersection, tri ) )
       {
        u32 count 
= 0;
        SelectedTerrainVertices.reallocate( Terrain
->getTriangleSelector()->getTriangleCount() );
        Terrain
->getTriangleSelector()->getVerticesInRadius( SelectedTerrainVertices.pointer(), Terrain->getTriangleSelector()->getTriangleCount(), count, intersection, RedCircleRadius );
        SelectedTerrainVertices.set_used( count );
       }

       return 
true;
      }
     }

posted @ 2008-05-04 12:17 bloodbao 阅读(186) | 评论 (0)编辑 收藏

posted @ 2008-05-01 16:40 bloodbao 阅读(172) | 评论 (0)编辑 收藏

posted @ 2008-05-01 11:16 bloodbao 阅读(162) | 评论 (0)编辑 收藏

现将场景编辑器测试版上传,望广大朋友测试,多谢!
经过一周的改写,完成部分功能,这个版本非完全版。
下载地址:http://pickup.mofile.com/7877768148587694
共享提取码:7877768148587694
图片在本博客都有!
VISTA下测试通过!
嗯,显卡至少要DX9吧,下一阶段把草地,水面,碰撞补齐!

posted @ 2008-04-30 19:22 bloodbao 阅读(197) | 评论 (1)编辑 收藏

                              郁闷,重写架构
IRRLICHT的SVN更新到最新版后,出现很多BUG,一调试就出错。
原因是用到了FKEDITOR的架构,不适合我的需求,所以下定决心重写架构,
还要加上一些脚本支持。
希望能尽快完工,以便找到工作。
哎,哪家公司要我啊?
posted @ 2008-04-26 19:53 bloodbao 阅读(173) | 评论 (0)编辑 收藏

各种动作:直飞,翻转,旋转。。。

posted @ 2008-04-24 17:17 bloodbao 阅读(213) | 评论 (0)编辑 收藏

posted @ 2008-04-24 16:50 bloodbao 阅读(120) | 评论 (0)编辑 收藏

posted @ 2008-04-24 16:48 bloodbao 阅读(176) | 评论 (0)编辑 收藏

仅列出标题
共6页: 1 2 3 4 5 6