28 #include <OgreMatrix4.h>
43 , mMaterialName(
"_NULL_")
63 Ogre::MeshManager::getSingleton().remove(
"HydraxMesh");
82 Ogre::AxisAlignedBox meshBounds;
95 mMesh->_setBounds(meshBounds);
125 mMesh = Ogre::MeshManager::getSingleton().createManual(
"HydraxMesh",
126 Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
128 mSubMesh->useSharedVertices =
false;
139 Ogre::AxisAlignedBox meshBounds;
152 mMesh->_setBounds(meshBounds);
158 mEntity->setCastShadows(
false);
159 mEntity->setRenderQueueGroup(Ogre::RENDER_QUEUE_1);
173 int numVertices = Complexity*Complexity;
174 int numEle = 6 * (Complexity-1)*(Complexity-1);
177 mSubMesh->vertexData =
new Ogre::VertexData();
178 mSubMesh->vertexData->vertexStart = 0;
179 mSubMesh->vertexData->vertexCount = numVertices;
181 Ogre::VertexDeclaration* vdecl =
mSubMesh->vertexData->vertexDeclaration;
182 Ogre::VertexBufferBinding* vbind =
mSubMesh->vertexData->vertexBufferBinding;
190 vdecl->addElement(0, 0, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
191 offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
192 vdecl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_NORMAL);
193 offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
194 vdecl->addElement(0, offset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES);
199 Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY);
205 vdecl->addElement(0, 0, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
206 offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
207 vdecl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_NORMAL);
212 Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY);
218 vdecl->addElement(0, 0, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
219 offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
220 vdecl->addElement(0, offset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES);
225 Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY);
231 vdecl->addElement(0, 0, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
236 Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY);
243 unsigned int *indexbuffer =
new unsigned int[numEle];
246 for(
int v=0; v<Complexity-1; v++){
247 for(
int u=0; u<Complexity-1; u++){
249 indexbuffer[i++] = v*Complexity + u;
250 indexbuffer[i++] = v*Complexity + u + 1;
251 indexbuffer[i++] = (v+1)*Complexity + u;
254 indexbuffer[i++] = (v+1)*Complexity + u;
255 indexbuffer[i++] = v*Complexity + u + 1;
256 indexbuffer[i++] = (v+1)*Complexity + u + 1;
262 Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(
263 Ogre::HardwareIndexBuffer::IT_32BIT,
265 Ogre::HardwareBuffer::HBU_STATIC,
true);
273 delete []indexbuffer;
277 mSubMesh->indexData->indexStart = 0;
278 mSubMesh->indexData->indexCount = numEle;
302 Ogre::AxisAlignedBox WordMeshBox =
mEntity->getWorldBoundingBox();
311 a = WordMeshBox.getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM),
312 b = WordMeshBox.getCorner(Ogre::AxisAlignedBox::FAR_RIGHT_BOTTOM),
313 c = WordMeshBox.getCorner(Ogre::AxisAlignedBox::NEAR_RIGHT_BOTTOM),
314 d = WordMeshBox.getCorner(Ogre::AxisAlignedBox::NEAR_LEFT_BOTTOM);
317 Ogre::Vector2 Corners2D[4] =
318 {Ogre::Vector2(a.x, a.z),
319 Ogre::Vector2(b.x, b.z),
320 Ogre::Vector2(c.x, c.z),
321 Ogre::Vector2(d.x, d.z)};
327 int NumberOfCollisions = 0;
329 Ogre::Vector2 DestPoint = Corners2D[0] + (Corners2D[1]-Corners2D[0])*2;
330 for (
int k = 0; k < 3; k++)
334 NumberOfCollisions ++;
341 NumberOfCollisions ++;
345 if (NumberOfCollisions == 1)
362 return Ogre::Vector2(-1,-1);
365 Ogre::AxisAlignedBox WordMeshBox =
mEntity->getWorldBoundingBox();
374 a = WordMeshBox.getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM),
375 b = WordMeshBox.getCorner(Ogre::AxisAlignedBox::FAR_RIGHT_BOTTOM),
376 c = WordMeshBox.getCorner(Ogre::AxisAlignedBox::NEAR_LEFT_BOTTOM);
379 Ogre::Vector2 Corners2D[3] =
380 {Ogre::Vector2(a.x, a.z),
381 Ogre::Vector2(b.x, b.z),
382 Ogre::Vector2(c.x, c.z)};
385 Ogre::Vector2 AB = Corners2D[1]-Corners2D[0],
386 AC = Corners2D[2]-Corners2D[0];
389 Ogre::Vector2 XProjectedPoint = Position-AC,
390 YProjectedPoint = Position-AB;
397 Ogre::Real ABLength = AB.length(),
398 ACLength = AC.length(),
399 XLength = (XPoint-Corners2D[0]).length(),
400 YLength = (YPoint-Corners2D[0]).length();
403 Ogre::Real XFinal = XLength / ABLength,
404 YFinal = YLength / ACLength;
406 return Ogre::Vector2(XFinal,YFinal);
411 Ogre::Affine3 mWorldMatrix;
415 mWorldMatrix =
mEntity->getParentSceneNode()->_getFullTransform();
419 Ogre::SceneNode *mTmpSN =
new Ogre::SceneNode(0);
422 mWorldMatrix = mTmpSN->_getFullTransform();
427 return mWorldMatrix.inverse()*(WorldSpacePosition);
432 Ogre::Affine3 mWorldMatrix;
436 mWorldMatrix =
mEntity->getParentSceneNode()->_getFullTransform();
440 Ogre::SceneNode *mTmpSN =
new Ogre::SceneNode(0);
443 mWorldMatrix = mTmpSN->_getFullTransform();
449 return mWorldMatrix*(ObjectSpacePosition);