Revision: 7906
          http://playerstage.svn.sourceforge.net/playerstage/?rev=7906&view=rev
Author:   natepak
Date:     2009-06-25 20:34:46 +0000 (Thu, 25 Jun 2009)

Log Message:
-----------
Fixed a path problem with OGRE_RESOURCE_PATH. Added in a cone renderable

Modified Paths:
--------------
    code/gazebo/trunk/server/GazeboConfig.cc
    code/gazebo/trunk/server/rendering/OgreAdaptor.cc
    code/gazebo/trunk/server/rendering/OgreCreator.cc
    code/gazebo/trunk/server/rendering/OgreSimpleShape.cc
    code/gazebo/trunk/server/rendering/OgreSimpleShape.hh
    code/gazebo/trunk/worlds/simpleshapes.world

Modified: code/gazebo/trunk/server/GazeboConfig.cc
===================================================================
--- code/gazebo/trunk/server/GazeboConfig.cc    2009-06-25 19:56:33 UTC (rev 
7905)
+++ code/gazebo/trunk/server/GazeboConfig.cc    2009-06-25 20:34:46 UTC (rev 
7906)
@@ -66,7 +66,7 @@
     int pos2 = str.find(delim);
     while (pos2 != (int)std::string::npos)
     {
-      this->ogrePaths.push_back(str.substr(pos1,pos2-pos1+1));
+      this->ogrePaths.push_back(str.substr(pos1,pos2-pos1));
       pos1 = pos2+1;
       pos2 = str.find(delim,pos2+1);
     }

Modified: code/gazebo/trunk/server/rendering/OgreAdaptor.cc
===================================================================
--- code/gazebo/trunk/server/rendering/OgreAdaptor.cc   2009-06-25 19:56:33 UTC 
(rev 7905)
+++ code/gazebo/trunk/server/rendering/OgreAdaptor.cc   2009-06-25 20:34:46 UTC 
(rev 7906)
@@ -310,6 +310,7 @@
   {
     std::string path(*iter);
     DIR *dir=opendir(path.c_str()); 
+
     if (dir == NULL)
     {
       continue;
@@ -330,7 +331,6 @@
       {
         // Load the plugin into OGRE
         this->root->loadPlugin(*piter);
-        //gzmsg(2) << "Loaded plugin:" << (*piter);
       }
       catch (Ogre::Exception e)
       {
@@ -380,7 +380,6 @@
       while ( (dir_entry_p = readdir(dir))!=NULL )
       {
         filename =(*iter)+"/Media/sets/"+ dir_entry_p->d_name;
-        //std::cout << filename << std::endl;
         archNames.push_back(filename);
       }
       closedir(dir);

Modified: code/gazebo/trunk/server/rendering/OgreCreator.cc
===================================================================
--- code/gazebo/trunk/server/rendering/OgreCreator.cc   2009-06-25 19:56:33 UTC 
(rev 7905)
+++ code/gazebo/trunk/server/rendering/OgreCreator.cc   2009-06-25 20:34:46 UTC 
(rev 7906)
@@ -77,6 +77,7 @@
   OgreSimpleShape::CreateBox("unit_box_U1V1", Vector3(1,1,1), 
                              Vector2<double>(1,1));
   OgreSimpleShape::CreateCylinder("unit_cylinder", 0.5, 1.0, 1, 32);
+  OgreSimpleShape::CreateCone("unit_cone", 0.5, 1.0, 5, 32);
 }
 
 
////////////////////////////////////////////////////////////////////////////////

Modified: code/gazebo/trunk/server/rendering/OgreSimpleShape.cc
===================================================================
--- code/gazebo/trunk/server/rendering/OgreSimpleShape.cc       2009-06-25 
19:56:33 UTC (rev 7905)
+++ code/gazebo/trunk/server/rendering/OgreSimpleShape.cc       2009-06-25 
20:34:46 UTC (rev 7906)
@@ -558,5 +558,229 @@
   {
     std::cerr << "Unable to create a basic Unit cylinder object" << std::endl;
   }
+}
 
+////////////////////////////////////////////////////////////////////////////////
+/// Create a cone mesh
+void OgreSimpleShape::CreateCone(const std::string &name, float radius, float 
height, int rings, int segments)
+{
+  Ogre::MeshPtr mesh;
+  Ogre::SubMesh *subMesh;
+  Ogre::VertexData *vertexData;
+  Ogre::VertexDeclaration* vertexDecl;
+  Ogre::HardwareVertexBufferSharedPtr vBuf;
+  Ogre::HardwareIndexBufferSharedPtr iBuf;
+  float *vertices, *vertStart;
+  unsigned short *indices, *indStart;
+  Vector3 vert, norm;
+  unsigned short verticeIndex = 0;
+  size_t currOffset = 0;
+  unsigned int i,j;
+  int ring, seg;
+
+  if (segments <3)
+    segments = 3;
+
+  float deltaSegAngle = (2.0 * M_PI / segments);
+
+  try
+  {
+    // Create a new mesh specifically for manual definition.
+    mesh = Ogre::MeshManager::getSingleton().createManual(name,
+           Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
+
+    subMesh = mesh->createSubMesh();
+
+    mesh->sharedVertexData = new Ogre::VertexData();
+    vertexData = mesh->sharedVertexData;
+
+    // define the vertex format
+    vertexDecl = vertexData->vertexDeclaration;
+
+    // The vertexDecl should contain positions, blending weights, normals,
+    // diffiuse colors, specular colors, tex coords. In that order.
+
+    // positions
+    vertexDecl->addElement(0, currOffset, Ogre::VET_FLOAT3, 
Ogre::VES_POSITION);
+    currOffset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
+
+    // TODO: blending weights
+
+    // normals
+    vertexDecl->addElement(0, currOffset, Ogre::VET_FLOAT3, Ogre::VES_NORMAL);
+    currOffset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
+
+    // TODO: diffuse colors
+
+    // TODO: specular colors
+
+    // two dimensional texture coordinates
+    vertexDecl->addElement(0, currOffset, Ogre::VET_FLOAT2,
+                           Ogre::VES_TEXTURE_COORDINATES, 0);
+    currOffset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT2);
+
+
+    // allocate the vertex buffer
+    vertexData->vertexCount = rings * (segments+1) + 2;
+    vBuf = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
+             vertexDecl->getVertexSize(0),
+             vertexData->vertexCount,
+             Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY,
+             false);
+
+
+    vertexData->vertexBufferBinding->setBinding(0, vBuf);
+    vertices = 
static_cast<float*>(vBuf->lock(Ogre::HardwareBuffer::HBL_DISCARD));
+
+    // allocate index buffer
+    subMesh->indexData->indexCount = 6 * (rings-1) * (segments+1) + 
(segments*6);
+    subMesh->indexData->indexBuffer =
+      Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(
+        Ogre::HardwareIndexBuffer::IT_16BIT,
+        subMesh->indexData->indexCount,
+        Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY,
+        false);
+
+    iBuf = subMesh->indexData->indexBuffer;
+    indices = static_cast<unsigned 
short*>(iBuf->lock(Ogre::HardwareBuffer::HBL_DISCARD));
+
+    vertStart = vertices;
+    indStart = indices;
+
+    double ringRadius;
+
+    // Generate the group of rings for the cone
+    for (ring = 0; ring < rings; ring++)
+    {
+      vert.z = ring * height/rings - height/2.0;
+
+      ringRadius = ((height - (vert.z+height/2.0)) / height) * radius;
+
+      // Generate the group of segments for the current ring
+      for (seg = 0; seg <= segments; seg++)
+      {
+        vert.y = ringRadius * cosf(seg * deltaSegAngle);
+        vert.x = ringRadius * sinf(seg * deltaSegAngle);
+
+        // TODO: Don't think these normals are correct.
+        norm = vert;
+        norm.Normalize();
+
+        // Add one vertex to the strip which makes up the sphere
+        *vertices++ = vert.x;
+        *vertices++ = vert.y;
+        *vertices++ = vert.z;
+
+        *vertices++ = norm.x;
+        *vertices++ = norm.y;
+        *vertices++ = norm.z;
+
+        // Texture coords
+        *vertices++ = (float) seg / (float) segments;
+        *vertices++ = (float) ring / (float) rings;
+
+        if (ring != (rings-1))
+        {
+          // each vertex (except the last) has six indices pointing to it
+          *indices++ = verticeIndex + segments + 1;
+          *indices++ = verticeIndex;
+          *indices++ = verticeIndex + segments;
+          *indices++ = verticeIndex + segments + 1;
+          *indices++ = verticeIndex + 1;
+          *indices++ = verticeIndex;
+
+          verticeIndex++;
+        }
+      }
+    }
+
+    /// The top point vertex
+    *vertices++ = 0;
+    *vertices++ = 0;
+    *vertices++ = height/2.0;
+
+    *vertices++ = 0;
+    *vertices++ = 0;
+    *vertices++ = 1;
+
+    *vertices++ = 0;
+    *vertices++ = 0;
+
+
+    // The bottom cap vertex
+    *vertices++ = 0;
+    *vertices++ = 0;
+    *vertices++ = -height/2.0;
+
+    *vertices++ = 0;
+    *vertices++ = 0;
+    *vertices++ = -1;
+
+    *vertices++ = 0;
+    *vertices++ = 0;
+
+    // Create the top fan
+    verticeIndex += segments+1;
+    for (seg=0; seg < segments; seg++)
+    {
+      *indices++ = verticeIndex;
+      *indices++ = verticeIndex - segments + seg;
+      *indices++ = verticeIndex - segments + seg - 1;
+    }
+
+    // Create the bottom fan
+    verticeIndex++;
+    //verticeIndex += segments + 1;
+    for (seg=0; seg < segments; seg++)
+    {
+      *indices++ = verticeIndex;
+      *indices++ = seg;
+      *indices++ = seg+1;
+    }
+
+    // Fix all the normals
+    for (i=0; i+3<subMesh->indexData->indexCount; i+=3)
+    {
+      norm.Set();
+
+      for (j=0; j<3; j++)
+      {
+        int index = indStart[i+j];
+        norm += Vector3(vertStart[index*8+3],
+                        vertStart[index*8+4],
+                        vertStart[index*8+5]);
+      }
+
+      norm /= 3;
+      norm.Normalize();
+
+      for (j=0; j<3; j++)
+      {
+        for (int k=0; k<3; k++)
+        {
+          int index = indStart[i+j];
+          vertStart[index*8+3+k] = norm[k];
+        }
+      }
+    }
+
+    // Unlock
+    vBuf->unlock();
+    iBuf->unlock();
+
+    // Generate face list
+    subMesh->useSharedVertices = true;
+
+    mesh->_setBounds( Ogre::AxisAlignedBox(
+                        Ogre::Vector3(-radius, -height/2, -radius),
+                        Ogre::Vector3(radius, height/2, radius)), false);
+
+    // this line makes clear the mesh is loaded (avoids memory leaks)
+    mesh->load();
+  }
+  catch (Ogre::Exception e)
+  {
+    std::cerr << "Unable to create a basic Unit cylinder object" << std::endl;
+  }
+
 }

Modified: code/gazebo/trunk/server/rendering/OgreSimpleShape.hh
===================================================================
--- code/gazebo/trunk/server/rendering/OgreSimpleShape.hh       2009-06-25 
19:56:33 UTC (rev 7905)
+++ code/gazebo/trunk/server/rendering/OgreSimpleShape.hh       2009-06-25 
20:34:46 UTC (rev 7906)
@@ -28,8 +28,12 @@
                                 const Vector2<double> &uvCoords);
 
   /// \brief Create a cylinder mesh
-  public: static void CreateCylinder(const std::string &name, float radius, 
float height, int rings, int segments);
+  public: static void CreateCylinder(const std::string &name, float radius, 
+                                     float height, int rings, int segments);
 
+  /// \brief Create a cone mesh
+  public: static void CreateCone(const std::string &name, float radius, 
+                                 float height, int rings, int segments);
 };
 
 /// \}

Modified: code/gazebo/trunk/worlds/simpleshapes.world
===================================================================
--- code/gazebo/trunk/worlds/simpleshapes.world 2009-06-25 19:56:33 UTC (rev 
7905)
+++ code/gazebo/trunk/worlds/simpleshapes.world 2009-06-25 20:34:46 UTC (rev 
7906)
@@ -99,6 +99,25 @@
     </body:cylinder>
   </model:physical>
 
+  <model:physical name="cone1_model">
+    <xyz>1 -3.5 0.5</xyz>
+    <rpy>0.0 0.0 0.0</rpy>
+
+    <body:cone name="cone_body">
+      <geom:cylinder name="cylinder_geom">
+        <size>0.5 1</size>
+        <mass>1.0</mass>
+        <mu1>1000.0</mu1>
+
+        <visual>
+          <mesh>unit_cone</mesh>
+          <material>Gazebo/RustyBarrel</material>
+        </visual>
+      </geom:cylinder>
+    </body:cone>
+  </model:physical>
+
+
    <!-- Ground Plane -->
    <model:physical name="plane1_model">
     <xyz>0 0 0</xyz>


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to