Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1387 - trunk/Model/Primitives


Chronological Thread 
  • From: thiago@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1387 - trunk/Model/Primitives
  • Date: Mon, 14 May 2007 03:05:40 -0600 (MDT)

Author: thiago
Date: Mon May 14 03:05:38 2007
New Revision: 1387

Added:
   trunk/Model/Primitives/TessellatedCylinder.cc
   trunk/Model/Primitives/TessellatedCylinder.h
Modified:
   trunk/Model/Primitives/CMakeLists.txt
Log:
Added a tessellated cylinder primitive. This is of course completely
inferior to the Cylinder primitive already in manta. But, it's useful
for testing stuff, or if you want a jagged looking cylinder.


Modified: trunk/Model/Primitives/CMakeLists.txt
==============================================================================
--- trunk/Model/Primitives/CMakeLists.txt       (original)
+++ trunk/Model/Primitives/CMakeLists.txt       Mon May 14 03:05:38 2007
@@ -36,6 +36,8 @@
      Primitives/Sphere.h
      Primitives/SuperEllipsoid.cc
      Primitives/SuperEllipsoid.h
+     Primitives/TessellatedCylinder.cc
+     Primitives/TessellatedCylinder.h
      Primitives/TexTriangle.cc
      Primitives/TexTriangle.h
      Primitives/Triangle.cc

Added: trunk/Model/Primitives/TessellatedCylinder.cc
==============================================================================
--- (empty file)
+++ trunk/Model/Primitives/TessellatedCylinder.cc       Mon May 14 03:05:38 
2007
@@ -0,0 +1,52 @@
+#include <Model/Primitives/TessellatedCylinder.h>
+#include <Model/Primitives/Triangle.h>
+#include <Core/Geometry/AffineTransform.h>
+#include <assert.h>
+
+using namespace Manta;
+
+TessellatedCylinder::TessellatedCylinder(Material* mat, 
+      const Vector& axis, const Vector& center, Real radius,
+      Real height, int tessellation)
+{
+  assert(tessellation>2);
+
+  AffineTransform t;
+  t.initWithRotation(axis, Vector(0,1,0));
+
+  //generate vertices
+  Vector verticesTop[tessellation+1];
+  Vector verticesBottom[tessellation+1];
+  const float angleIncr = M_PI*2 / tessellation; 
+  for (int i=0; i < tessellation; ++i) {
+    Real x = radius * cos(angleIncr*i);
+    Real y = radius * sin(angleIncr*i);
+    
+    verticesTop[i]    = t.multiply_point(Vector(x, y, height)) + center;
+    verticesBottom[i] = t.multiply_point(Vector(x, y, 0)) + center;
+  }
+  verticesTop[tessellation] = verticesTop[0];
+  verticesBottom[tessellation] = verticesBottom[0];
+
+  //make disks
+  for (int i=0; i < tessellation-2; ++i) {
+    objs.push_back(new Triangle(mat, verticesTop[tessellation-1],
+                                verticesTop[i], verticesTop[i+1]));
+    objs.push_back(new Triangle(mat, verticesBottom[tessellation-1],
+                                verticesBottom[i], verticesBottom[i+1]));
+  }
+  
+  //make actual cylinder part
+  for (int i=0; i < tessellation; ++i) {
+    objs.push_back(new Triangle(mat, verticesTop[i], verticesTop[i+1],
+                                verticesBottom[i]));
+    objs.push_back(new Triangle(mat, verticesTop[i+1],
+                                verticesBottom[i+1], verticesBottom[i]));
+  }
+}
+
+TessellatedCylinder::~TessellatedCylinder()
+{
+  for (unsigned int i=0; i < objs.size(); ++i)
+    delete objs[i];
+}

Added: trunk/Model/Primitives/TessellatedCylinder.h
==============================================================================
--- (empty file)
+++ trunk/Model/Primitives/TessellatedCylinder.h        Mon May 14 03:05:38 
2007
@@ -0,0 +1,23 @@
+
+#ifndef Manta_Model_TessellatedCylinder_h
+#define Manta_Model_TessellatedCylinder_h
+
+#include <Model/Groups/Group.h>
+#include <Core/Geometry/Vector.h>
+#include <Interface/Material.h>
+namespace Manta
+{
+  //Creates a cylinder made of triangles.
+  //Only use this over the normal Cylinder if you must have only triangles.
+  class TessellatedCylinder : public Group {
+  public:
+    //tessellation*2 is the number of vertices of cylinder.
+    TessellatedCylinder(Material* mat, const Vector& axis, const Vector& 
center,
+                        Real radius, Real height, int tessellation);
+    virtual ~TessellatedCylinder();
+  };
+}
+
+#endif
+
+




  • [MANTA] r1387 - trunk/Model/Primitives, thiago, 05/14/2007

Archive powered by MHonArc 2.6.16.

Top of page