Permalink
Browse files

Merge branch 'kchen' of https://github.com/mdfeist/BlinkAnalysis into…

… Mike
  • Loading branch information...
2 parents 5e9c22b + c9afb71 commit 2d7d9c3290b4bb0cff117dc1c75c0084309c7307 @mdfeist committed Jun 18, 2013

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -377,9 +377,11 @@ void AppViewer::initAppViewer(HWND hwnd)
}
bool AppViewer::addNodeToViewer(osg::Node* node) {
+ if (!sceneNode) return false;
return sceneNode->addChild(node);
}
bool AppViewer::removeNodeFromViewer(osg::Node* node) {
+ if (!sceneNode) return false;
return sceneNode->removeChild(node);
}
@@ -2,6 +2,7 @@
#include "StdAfx.h"
#include <osg/Geometry>
+#include <osg/ShapeDrawable>
#include <osgUtil/SmoothingVisitor>
#include <osg/Texture2D>
@@ -10,24 +11,26 @@
#include "CaptureObject.h"
-int CaptureObject::getNumVertices()
-{
- return vertices->size();
-}
+///////////////////////////
+// CaptureObject
+///////////////////////////
-void CaptureObject::setVertices(osg::Vec3Array* vertices) {
- this->vertices = vertices;
+osg::Node* CaptureObject::setRender(bool ren)
+{
+ // state unchanged, no need to return node
+ if (render == ren)
+ return NULL;
+
+ render = ren;
+ return node;
}
-void CaptureObject::addFace(osg::DrawElementsUInt* face) {
- faces.push_back(face);
-}
-void CaptureObject::removeFaces() {
- faces.clear();
-}
+///////////////////////////
+// CaptureObjectCustom
+///////////////////////////
-osg::Geode* CaptureObject::getAsGeode()
+osg::Geode* CaptureObjectCustom::getAsGeode()
{
if (!node)
node = new osg::Geode();
@@ -59,14 +62,128 @@ osg::Geode* CaptureObject::getAsGeode()
return geo;
}
-osg::Node* CaptureObject::setRender(bool ren)
+
+
+///////////////////////////
+// CaptureObjectPlane
+///////////////////////////
+
+CaptureObjectPlane::CaptureObjectPlane(osg::Vec3 corner, osg::Vec3 pt1, osg::Vec3 pt2)
+ : CaptureObject()
{
- // state unchanged, no need to return node
- if (render == ren)
- return NULL;
+ setType(PLANE);
+ setVertices(corner, pt1, pt2);
+}
+
+void CaptureObjectPlane::setVertices(osg::Vec3 corner, osg::Vec3 pt1, osg::Vec3 pt2)
+{
+ // set up plane vertices
+ if (!vertices)
+ vertices = new osg::Vec3Array();
+ else
+ vertices->clear();
+
+ osg::Vec3 opposite = pt1 + pt2 - corner;
+ vertices->push_back(corner);
+ vertices->push_back(pt1);
+ vertices->push_back(opposite);
+ vertices->push_back(pt2);
+
+ // set up face
+ if (!face)
+ face = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLE_FAN);
+ else
+ face->clear();
+
+ face->push_back(0);
+ face->push_back(1);
+ face->push_back(2);
+ face->push_back(2);
+ face->push_back(3);
+}
+
+osg::Geode* CaptureObjectPlane::getAsGeode()
+{
+ if (!node)
+ node = new osg::Geode();
+
+ osg::Geode* geo = node->asGeode();
+ geo->removeDrawables(0, 1);
+ osg::Geometry *geom = new osg::Geometry();
+ geom->setVertexArray(vertices.get());
+
+ geom->addPrimitiveSet(face);
- render = ren;
- return node;
+ osgUtil::SmoothingVisitor::smooth(*geom);
+ geo->addDrawable(geom);
+
+ return geo;
+}
+
+
+///////////////////////////
+// CaptureObjectBox
+///////////////////////////
+
+CaptureObjectBox::CaptureObjectBox(osg::Vec3 centre, osg::Vec3 halfLen, osg::Quat rot)
+{
+ box = new osg::Box();
+ box->set(centre, halfLen);
+ box->setRotation(rot);
+}
+
+osg::Geode* CaptureObjectBox::getAsGeode()
+{
+ if (!node)
+ node = new osg::Geode();
+
+ osg::Geode* geo = node->asGeode();
+ geo->removeDrawables(0, 1);
+ if (box)
+ geo->addDrawable(new osg::ShapeDrawable(box));
+
+ return geo;
}
+void CaptureObjectBox::setCentre(osg::Vec3 centre)
+{
+ if (!box)
+ box = new osg::Box();
+ box->setCenter(centre);
+}
+
+osg::Vec3 CaptureObjectBox::getCentre()
+{
+ if (box)
+ return box->getCenter();
+ return osg::Vec3(0, 0, 0);
+}
+
+void CaptureObjectBox::setHalfLengths(osg::Vec3 halfLen)
+{
+ if (!box)
+ box = new osg::Box();
+ box->setHalfLengths(halfLen);
+}
+
+osg::Vec3 CaptureObjectBox::getHalfLengths()
+{
+ if (box)
+ return box->getHalfLengths();
+ return osg::Vec3(0, 0, 0);
+}
+
+void CaptureObjectBox::setRotation(osg::Quat rot)
+{
+ if (!box)
+ box = new osg::Box();
+ box->setRotation(rot);
+}
+
+osg::Quat CaptureObjectBox::getRotation()
+{
+ if (box)
+ return box->getRotation();
+ return osg::Quat(0, 0, 0, 1); // zero rotation
+}
@@ -5,27 +5,36 @@
#include <string>
#include <osg/PrimitiveSet>
#include <osg/Node>
+#include <osg/Shape>
#include "CaptureObjectUtil.h"
+enum ObjectType {
+ CUSTOM,
+ BOX,
+ CYLINDER,
+ PLANE
+};
+
+
typedef std::vector<osg::ref_ptr<osg::DrawElementsUInt>>::iterator faces_iterator;
+///////////////////////////
+
// TODO: eventually support texture?
-// TODO: check for NULL
class CaptureObject
{
-private:
+protected:
// for tracking object with a rigid body
int rigidBody; // -1 if static object
// identifier for this object (generated)
int id;
std::string name;
- osg::ref_ptr<osg::Vec3Array> vertices;
- std::vector<osg::ref_ptr<osg::DrawElementsUInt>> faces;
osg::ref_ptr<osg::Node> node;
bool render;
+ ObjectType type;
public:
@@ -34,33 +43,122 @@ class CaptureObject
id = -1;
rigidBody = -1;
render = true;
+ type = CUSTOM;
}
~CaptureObject() {
- faces.clear();
node = NULL;
}
void setID(int id) { this->id = id; }
int getID() { return id; }
-
- int getNumVertices();
- void setVertices(osg::Vec3Array* vertices);
-
- int getNumFaces() { return faces.size(); }
- void addFace(osg::DrawElementsUInt* face);
- void removeFaces();
+ void setType(ObjectType t) { type = t; }
+ ObjectType getType() { return type; }
+
void setRigidBody(int rid) { rigidBody = rid; }
int getRigidBody() { return rigidBody; }
void setName(std::string name) { this->name = name; }
std::string getName() { return name; }
- // returns a Geode representing this object
- osg::Geode* getAsGeode();
bool renderObject() { return render; }
osg::Node* setRender(bool ren); // returns geode so world can remove it from node
+
+ // virtual functions
+ // returns a Geode representing this object
+ virtual osg::Geode* getAsGeode() = 0;
+ virtual int getNumVertices() = 0;
+ virtual int getNumFaces() = 0;
+
+};
+
+
+///////////////////////////
+
+class CaptureObjectCustom : public CaptureObject
+{
+private:
+ osg::ref_ptr<osg::Vec3Array> vertices;
+ std::vector<osg::ref_ptr<osg::DrawElementsUInt>> faces;
+
+public:
+
+ int getNumVertices() { return vertices->size(); }
+ void setVertices(osg::Vec3Array* vertices) {
+ this->vertices = vertices;
+ }
+
+ int getNumFaces() { return faces.size(); }
+ void addFace(osg::DrawElementsUInt* face) {
+ faces.push_back(face);
+ }
+ void removeFaces() {
+ faces.clear();
+ }
+
+ osg::Geode* getAsGeode();
+};
+
+
+///////////////////////////
+
+class CaptureObjectPlane : public CaptureObject
+{
+private:
+ osg::ref_ptr<osg::Vec3Array> vertices;
+ osg::ref_ptr<osg::DrawElementsUInt> face;
+
+public:
+ CaptureObjectPlane()
+ : CaptureObject()
+ {
+ type = PLANE;
+ vertices = NULL;
+ face = NULL;
+ }
+
+ CaptureObjectPlane(osg::Vec3 corner, osg::Vec3 pt1, osg::Vec3 pt2);
+
+ int getNumVertices() { return 4; }
+ void setVertices(osg::Vec3 corner, osg::Vec3 pt1, osg::Vec3 pt2);
+
+ int getNumFaces() { return 1; }
+
+ osg::Geode* getAsGeode();
+
+};
+
+
+///////////////////////////
+
+class CaptureObjectBox : public CaptureObject
+{
+private:
+ osg::ref_ptr<osg::Box> box;
+
+public:
+ CaptureObjectBox()
+ : CaptureObject()
+ {
+ type = BOX;
+ box = NULL;
+ }
+
+ CaptureObjectBox(osg::Vec3 centre, osg::Vec3 halfLen, osg::Quat rot);
+
+ int getNumVertices() { return 8; }
+ int getNumFaces() { return 6; }
+ osg::Geode* getAsGeode();
+
+ void setCentre(osg::Vec3 centre);
+ osg::Vec3 getCentre();
+
+ void setHalfLengths(osg::Vec3 halfLen);
+ osg::Vec3 getHalfLengths();
+
+ void setRotation(osg::Quat rot);
+ osg::Quat getRotation();
};
#endif
@@ -8,7 +8,7 @@ bool CaptureObjectUtil::orthogonalCheckFuzzy(osg::Vec3 v1, osg::Vec3 v2, double
}
// based on MATLAB function MakeCoordSystem by J. Lanovaz
-osg::Matrix* CaptureObjectUtil::makeGlobalToLocalMatrix(
+osg::Matrix* CaptureObjectUtil::makeLocalToGlobalMatrix(
osg::Vec3 origin, osg::Vec3 x, osg::Vec3 y)
{
// form axis vectors
@@ -12,7 +12,7 @@ class CaptureObjectUtil
public:
static bool orthogonalCheckFuzzy(osg::Vec3 v1, osg::Vec3 v2, double epsilon);
- static osg::Matrix* makeGlobalToLocalMatrix(osg::Vec3 origin, osg::Vec3 x, osg::Vec3 y);
+ static osg::Matrix* makeLocalToGlobalMatrix(osg::Vec3 origin, osg::Vec3 x, osg::Vec3 y);
};
Oops, something went wrong.

0 comments on commit 2d7d9c3

Please sign in to comment.