Changeset 134 in flair-src for trunk/lib/FlairSimulator/src
- Timestamp:
- Feb 9, 2017, 5:10:24 PM (8 years ago)
- Location:
- trunk/lib/FlairSimulator/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairSimulator/src/GenericObject.cpp
r69 r134 17 17 #ifdef GL 18 18 #include "GenericObject.h" 19 #include "Simulator.h" 19 20 #include "Simulator_impl.h" 21 #include "Gui.h" 20 22 21 23 #include "Quaternion.h" 24 #include "Euler.h" 22 25 #include <ISceneManager.h> 26 #include <IMeshSceneNode.h> 23 27 24 28 using namespace irr; … … 33 37 namespace simulator { 34 38 35 GenericObject::GenericObject(Simulator *parent, std::string name, 36 ISceneManager *sceneManager) 37 : IMeshSceneNode(sceneManager->getRootSceneNode(), sceneManager, 38 -1) //, IODevice(parent,name) 39 GenericObject::GenericObject(Simulator *parent, IMesh *mesh) 39 40 { 40 setMaterialFlag(EMF_LIGHTING, false);41 Material = getMaterial(0); 42 // setMaterialTexture(0,sceneManager->getVideoDriver()->getTexture("/home/cesar/igep/uav_dev_svn/trunk/media/nskinbl.jpg"));43 Material.NormalizeNormals = true;44 Material.Wireframe = false; 45 Material.Lighting = false;41 meshSceneNode=getGui()->getSceneManager()->addMeshSceneNode(mesh); 42 43 selector = getGui()->getSceneManager()->createTriangleSelector(mesh, meshSceneNode); 44 meshSceneNode->setTriangleSelector(selector); 45 46 meshSceneNode->setMaterialFlag(EMF_LIGHTING, false); 46 47 47 48 parent->pimpl_->objects.push_back(this); … … 50 51 GenericObject::~GenericObject() {} 51 52 53 ITriangleSelector *GenericObject::TriangleSelector(void) { return selector; } 54 52 55 void GenericObject::setScale(float value) { 53 ISceneNode::setScale(vector3df(value, value, value));56 meshSceneNode->setScale(vector3df(value, value, value)); 54 57 } 55 58 56 void GenericObject::setScale(vector3df scale) { ISceneNode::setScale(scale); } 57 58 ITriangleSelector *GenericObject::TriangleSelector(void) { return selector; } 59 60 void GenericObject::OnRegisterSceneNode(void) { 61 if (IsVisible) 62 SceneManager->registerNodeForRendering(this); 63 64 ISceneNode::OnRegisterSceneNode(); 59 void GenericObject::setScale(const vector3df& scale) { 60 meshSceneNode->setScale(scale); 65 61 } 66 62 67 void GenericObject::render(void) { 68 IVideoDriver *driver = SceneManager->getVideoDriver(); 69 70 driver->setMaterial(Material); 71 72 driver->setTransform(ETS_WORLD, AbsoluteTransformation); 73 driver->drawMeshBuffer(mesh->getMeshBuffer(0)); 63 void GenericObject::setPosition(const vector3df& pos) { 64 meshSceneNode->setPosition(ToIrrlichtCoordinates(pos)); 74 65 } 75 66 76 void GenericObject::setMesh(IMesh *mesh) { 77 this->mesh = mesh; 78 box = mesh->getBoundingBox(); 79 80 selector = getSceneManager()->createTriangleSelector(mesh, this); 81 setTriangleSelector(selector); 82 } 83 84 IMesh *GenericObject::getMesh(void) { return mesh; } 85 86 void GenericObject::setPosition(irr::core::vector3df pos) { 87 ISceneNode::setPosition(ToIrrlichtCoordinates(pos)); 88 } 89 90 void GenericObject::setRotation(irr::core::vector3df rotation) { 67 void GenericObject::setRotation(const vector3df& rotation) { 91 68 Euler eulerA(rotation.X, rotation.Y, rotation.Z); 92 69 Euler eulerB; … … 96 73 quatB.ToEuler(eulerB); 97 74 98 ISceneNode::setRotation(Euler::ToDegree(1) *75 meshSceneNode->setRotation(Euler::ToDegree(1) * 99 76 vector3df(eulerB.roll, eulerB.pitch, eulerB.yaw)); 100 77 } -
trunk/lib/FlairSimulator/src/Gui_impl.cpp
r70 r134 22 22 #include "Model.h" 23 23 #include "Model_impl.h" 24 #include "VisualizationCamera.h" 25 #include "FollowMeCamera.h" 24 26 #include <Object.h> 25 27 #include <Euler.h> -
trunk/lib/FlairSimulator/src/Man.cpp
r70 r134 27 27 #include "FollowMeCamera.h" 28 28 29 class addAnimatedMeshSceneNode; 29 30 using namespace irr; 30 31 using namespace irr::core; -
trunk/lib/FlairSimulator/src/Parser.cpp
r87 r134 18 18 #include "Parser.h" 19 19 #include "Simulator.h" 20 #include "FixedCamera.h" 20 21 #include "GenericObject.h" 21 #include "FixedCamera.h"22 22 #include <vector3d.h> 23 23 #include <Vector3D.h> 24 24 #include <IrrlichtDevice.h> 25 25 #include <IFileSystem.h> 26 #include "GenericObject.h" 26 #include <IAnimatedMesh.h> 27 #include <IGeometryCreator.h> 28 #include <ISceneManager.h> 27 29 28 30 using namespace irr; … … 108 110 109 111 void Parser::processObjects(xmlNode *a_node) { 110 FILE *fp; 111 std::string fileName; 112 xmlNode *cur_node = NULL; 113 114 const IGeometryCreator *geo; 115 116 geo = getGui()->getSceneManager()->getGeometryCreator(); 112 xmlNode *cur_node = NULL; 117 113 118 114 for (cur_node = a_node; cur_node; cur_node = cur_node->next) { 119 115 if (xmlStrEqual(cur_node->name, (xmlChar *)"mesh")) { 120 fileName = this->media_path; 116 FILE *fp; 117 std::string fileName = this->media_path+"/"; 121 118 fp = NULL; 122 119 fp = fopen(fileName.append((char *)xmlGetProp( 123 cur_node, (xmlChar *)"model")).c_str(), 124 "rb"); 120 cur_node, (xmlChar *)"model")).c_str(),"rb"); 125 121 if (fp != NULL) { 126 122 GenericObject *object = 127 new GenericObject(parent, "Object", getSceneManager()); 128 object->setMesh(getGui()->getMesh( 129 (char *)xmlGetProp(cur_node, (xmlChar *)"model"))); 123 new GenericObject(parent, getGui()->getMesh((char *)xmlGetProp(cur_node, (xmlChar *)"model"))); 130 124 object->setPosition( 131 125 getMeshVect(cur_node->children, (xmlChar *)"position")); … … 133 127 getMeshVect(cur_node->children, (xmlChar *)"rotation")); 134 128 object->setScale(getMeshVect(cur_node->children, (xmlChar *)"scale")); 135 object->render();136 129 } else { 137 Err("FATAL ERROR : File %s doesn't exist !\r\n",138 (char *)xmlGetProp(cur_node, (xmlChar *)"model") );130 Err("FATAL ERROR : File %s %s doesn't exist !\r\n", 131 (char *)xmlGetProp(cur_node, (xmlChar *)"model"),fileName.c_str()); 139 132 } 140 133 } else if (xmlStrEqual(cur_node->name, (xmlChar *)"cylinder")) { 134 const IGeometryCreator *geo; 135 geo = getGui()->getSceneManager()->getGeometryCreator(); 136 IMesh* mesh=geo->createCylinderMesh( 137 ToIrrlichtScale(atof((char *)xmlGetProp(cur_node, (xmlChar *)"radius"))), 138 ToIrrlichtScale(atof((char *)xmlGetProp(cur_node, (xmlChar *)"length"))), 139 atof((char *)xmlGetProp(cur_node, (xmlChar *)"tesselation")), 140 SColor(100, 255, 100, 100)); 141 GenericObject *object = new GenericObject(parent, mesh); 142 object->setPosition(getMeshVect(cur_node->children, (xmlChar *)"position")); 143 object->setRotation(getMeshVect(cur_node->children, (xmlChar *)"rotation")); 144 object->setScale(getMeshVect(cur_node->children, (xmlChar *)"scale")); 145 } else if (xmlStrEqual(cur_node->name, (xmlChar *)"eight")) { 146 const IGeometryCreator *geo; 147 geo = getGui()->getSceneManager()->getGeometryCreator(); 148 IMesh* mesh=geo->createCubeMesh( 149 vector3df(atof((char *)xmlGetProp(cur_node, (xmlChar *)"length")), 150 atof((char *)xmlGetProp(cur_node, (xmlChar *)"width")), 151 atof((char *)xmlGetProp(cur_node, (xmlChar *)"eight")))); 152 141 153 GenericObject *object = 142 new GenericObject(parent, "Object", getSceneManager()); 143 object->setMesh(geo->createCylinderMesh( 144 ToIrrlichtScale( 145 atof((char *)xmlGetProp(cur_node, (xmlChar *)"radius"))), 146 ToIrrlichtScale( 147 atof((char *)xmlGetProp(cur_node, (xmlChar *)"length"))), 148 atof((char *)xmlGetProp(cur_node, (xmlChar *)"tesselation")), 149 SColor(100, 255, 100, 100))); 154 new GenericObject(parent, mesh); 150 155 object->setPosition( 151 156 getMeshVect(cur_node->children, (xmlChar *)"position")); … … 153 158 getMeshVect(cur_node->children, (xmlChar *)"rotation")); 154 159 object->setScale(getMeshVect(cur_node->children, (xmlChar *)"scale")); 155 // object->setMaterialTexture(0,getTexture("/home/apeiron/igep/uav_dev_svn/trunk/media/nskinbl.jpg"));156 object->setMaterialType(video::EMT_SOLID);157 object->render();158 } else if (xmlStrEqual(cur_node->name, (xmlChar *)"eight")) {159 GenericObject *object =160 new GenericObject(parent, "Object", getSceneManager());161 object->setMesh(geo->createCubeMesh(162 vector3df(atof((char *)xmlGetProp(cur_node, (xmlChar *)"length")),163 atof((char *)xmlGetProp(cur_node, (xmlChar *)"width")),164 atof((char *)xmlGetProp(cur_node, (xmlChar *)"eight")))));165 object->setPosition(166 getMeshVect(cur_node->children, (xmlChar *)"position"));167 object->setRotation(168 getMeshVect(cur_node->children, (xmlChar *)"rotation"));169 object->setScale(getMeshVect(cur_node->children, (xmlChar *)"scale"));170 object->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);171 // object->getMaterial(0).Textures[0] =172 // getTexture("/home/apeiron/igep/uav_dev_svn/trunk/media/nskinbl.jpg");173 object->setMaterialFlag(EMF_LIGHTING, false);174 object->render();175 160 } 176 161 } -
trunk/lib/FlairSimulator/src/unexported/GenericObject.h
r69 r134 19 19 #ifdef GL 20 20 21 #include "Simulator.h" 22 23 #include "ConditionVariable.h" 24 #include "Gui.h" 25 #include "Gui_impl.h" 26 #include <ISceneManager.h> 27 #include <ISceneNodeAnimatorCollisionResponse.h> 28 #include <IMetaTriangleSelector.h> 29 #include <IVideoDriver.h> 30 #include <ICameraSceneNode.h> 31 #include "FollowMeCamera.h" 32 33 #include <IODevice.h> 34 #include <Euler.h> 35 #include <Vector3D.h> 36 37 #include <aabbox3d.h> 38 #include <IMeshSceneNode.h> 21 #include <vector3d.h> 39 22 40 23 namespace irr { 41 class SEvent; 42 namespace scene { 43 class IMesh; 44 class ISceneManager; 45 class ITriangleSelector; 46 class IMetaTriangleSelector; 47 class ISceneNodeAnimatorCollisionResponse; 48 } 24 namespace scene { 25 class IMesh; 26 class IMeshSceneNode; 27 class ITriangleSelector; 28 class ISceneNode; 29 } 49 30 } 50 31 51 class Gui_impl;52 32 class Simulator_impl; 53 33 54 34 namespace flair { 55 namespace core {56 class ConditionVariable;57 }58 35 namespace simulator { 59 36 class Simulator; 60 class AnimPoursuite;61 37 62 class GenericObject : public irr::scene::IMeshSceneNode{38 class GenericObject { 63 39 friend class ::Simulator_impl; 64 40 65 41 public: 66 GenericObject(Simulator *parent, std::string name, 67 irr::scene::ISceneManager *sceneManager); 42 GenericObject(Simulator *parent,irr::scene::IMesh *mesh); 68 43 virtual ~GenericObject(); 69 44 70 // FROM IMPL71 45 irr::scene::ITriangleSelector *TriangleSelector(void); 72 irr::core::aabbox3d<irr::f32> box;73 // END FROM IMPL74 75 irr::scene::ISceneNode *getSceneNode();76 virtual const irr::core::aabbox3d<irr::f32> &getBoundingBox(void) const {77 return box;78 }79 80 void setPosition(irr::core::vector3df position);81 46 void setScale(float value); 82 void setScale(irr::core::vector3df scale); 83 void setRotation(irr::core::vector3df rotation); 84 void OnRegisterSceneNode(void); 85 void setMesh(irr::scene::IMesh *mesh); 86 irr::scene::IMesh *getMesh(void); 87 void render(void); 88 virtual void setReadOnlyMaterials(bool readonly){}; 89 virtual bool isReadOnlyMaterials(void) const { return false; } 90 virtual irr::scene::IShadowVolumeSceneNode * 91 addShadowVolumeSceneNode(const irr::scene::IMesh *shadowMesh = 0, 92 irr::s32 id = -1, bool zfailmethod = true, 93 irr::f32 infinity = 1000.0f) { 94 return NULL; 95 } 96 47 void setScale(const irr::core::vector3df& scale); 48 void setPosition(const irr::core::vector3df& position); 49 void setRotation(const irr::core::vector3df& rotation); 50 97 51 private: 98 void UpdateFrom(core::io_data *data){};99 irr::scene::IMesh *mesh;100 52 irr::scene::ITriangleSelector *selector; 101 flair::core::ConditionVariable *cond; 102 irr::video::SMaterial Material; 103 }; 53 irr::scene::IMeshSceneNode *meshSceneNode; 54 }; 104 55 } // end namespace simulator 105 56 } // end namespace flair
Note:
See TracChangeset
for help on using the changeset viewer.