6 #include "OsgMovableItem.h"
8 #include "OsgRigidBody.h"
11 #include "OsgSimulator.h"
12 #include "OsgUserData.h"
13 #include "OsgUserDataVisitor.h"
14 #include "OsgDragger.h"
41 {
Std_TraceMsg(0,
"Caught Error in desctructor of OsgLine\r\n",
"", -1,
false,
true);}
44 void OsgLine::SetThisLinePointers()
46 m_lpLineBase =
dynamic_cast<LineBase *
>(
this);
48 THROW_TEXT_ERROR(Osg_Err_lThisPointerNotDefined, Osg_Err_strThisPointerNotDefined,
"m_lpLineBase ");
51 osg::Geometry *OsgLine::CreateLineGeometry()
53 osg::Geometry* linesGeom =
new osg::Geometry();
54 int iCount = BuildLines(linesGeom);
57 CStdColor &aryDiffuse = *m_lpLineBase->Diffuse();
58 osg::Vec4Array* colors =
new osg::Vec4Array;
59 colors->push_back(osg::Vec4(aryDiffuse[0], aryDiffuse[1], aryDiffuse[2], aryDiffuse[3]));
60 linesGeom->setColorArray(colors);
61 linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
65 osg::Vec3Array* normals =
new osg::Vec3Array;
66 normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f));
67 linesGeom->setNormalArray(normals);
68 linesGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
73 osg::PrimitiveSet *lpSet =
new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, iCount);
74 linesGeom->addPrimitiveSet(lpSet);
76 linesGeom->setDataVariance(osg::Object::DYNAMIC);
77 linesGeom->setUseDisplayList(
false);
79 m_lpLinesGeom = linesGeom;
83 int OsgLine::BuildLines(osg::Geometry *linesGeom)
86 CStdArray<Attachment *> *aryAttachments = m_lpLineBase->AttachmentPoints();
87 int iCount = aryAttachments->GetSize();
90 if(m_aryLines.valid())
93 m_aryLines =
new osg::Vec3Array;
99 Attachment *lpPrevAttach=NULL;
100 Attachment *lpAttach=NULL;
102 for(
int iIndex=1; iIndex<iCount; iIndex++)
104 lpPrevAttach = aryAttachments->at(iIndex-1);
105 lpAttach = aryAttachments->at(iIndex);
107 vPos = lpPrevAttach->AbsolutePosition();
108 m_aryLines->push_back(osg::Vec3(vPos.x, vPos.y, vPos.z));
110 vPos = lpAttach->AbsolutePosition();
111 m_aryLines->push_back(osg::Vec3(vPos.x, vPos.y, vPos.z));
115 linesGeom->setVertexArray(m_aryLines.get());
116 linesGeom->dirtyBound();
118 return m_aryLines->getNumElements();
121 void OsgLine::DrawLine()
123 CStdArray<Attachment *> *aryAttachments = m_lpLineBase->AttachmentPoints();
124 int iCount = aryAttachments->GetSize();
130 Attachment *lpPrevAttach=NULL;
131 Attachment *lpAttach=NULL;
134 for(
int iIndex=1; iIndex<iCount; iIndex++)
136 lpPrevAttach = aryAttachments->at(iIndex-1);
137 lpAttach = aryAttachments->at(iIndex);
139 vPos = lpPrevAttach->AbsolutePosition();
140 (*m_aryLines)[iLineIdx].set(vPos.x, vPos.y, vPos.z);
142 vPos = lpAttach->AbsolutePosition();
143 (*m_aryLines)[iLineIdx+1].set(vPos.x, vPos.y, vPos.z);
149 m_lpLinesGeom->dirtyBound();
153 void OsgLine::CalculateForceVector(Attachment *lpPrim, Attachment *lpSec,
float fltTension, CStdFPoint &oPrimPos, CStdFPoint &oSecPos, CStdFPoint &oPrimForce)
155 oPrimPos = lpPrim->AbsolutePosition();
156 oSecPos = lpSec->AbsolutePosition();
158 oPrimForce = oSecPos - oPrimPos;
159 oPrimForce.Normalize();
160 oPrimForce *= fltTension;
163 void OsgLine::StepLineSimulation(
bool bEnabled,
float fltTension)
173 if(fabs(fltTension) > 1e-5)
175 CStdArray<Attachment *> *aryAttachments = m_lpLineBase->AttachmentPoints();
176 int iCount = aryAttachments->GetSize();
177 Attachment *lpAttach1 = aryAttachments->at(0), *lpAttach2 = NULL;
178 CStdFPoint oPrimPos, oPrimPlusPos, oSecPos, oSecMinusPos;
179 CStdFPoint oPrimForce, oSecForce;
180 RigidBody *lpAttach1Parent, *lpAttach2Parent;
184 for(
int iIndex=1; iIndex<iCount; iIndex++)
186 lpAttach2 = aryAttachments->at(iIndex);
188 lpAttach1Parent = lpAttach1->Parent();
189 lpAttach2Parent = lpAttach2->Parent();
191 CalculateForceVector(lpAttach1, lpAttach2, fltTension, oPrimPos, oPrimPlusPos, oPrimForce);
192 CalculateForceVector(lpAttach2, lpAttach1, fltTension, oSecPos, oSecMinusPos, oSecForce);
194 lpAttach1Parent->AddForceAtWorldPos(oPrimPos.x, oPrimPos.y, oPrimPos.z, oPrimForce.x, oPrimForce.y, oPrimForce.z,
true);
195 lpAttach2Parent->AddForceAtWorldPos(oSecPos.x, oSecPos.y, oSecPos.z, oSecForce.x, oSecForce.y, oSecForce.z,
true);
197 lpAttach1 = lpAttach2;
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
void Std_TraceMsg(const int iLevel, std::string strMessage, std::string strSourceFile, int iSourceLine, bool bLogToFile, bool bPrintHeader)
Traces a message to the debugger window.
Declares the vortex structure class.