Hi Waruck,
thx for replying and wow how could i not think about that,in the class before u post here i was trying ,Ogre::SceneNode* virtual bool createObject(int id, Ogre::Vector3 pos) lol i know that looks rediculous but thats what i have tried before u last post here lol!
bro after u posted here now everything works fine except for the separate factory class i created..its not working, i am obviously missing something but i dont know where..im going to post the header file and the .cpp file so u can analyze and see whats wrong with my code...i promise u that as soon as i get it to work i will change the thread status and consider it as solved!
ok so here its the the FactoryClass header file :
Code: Select all
#include "BaseApplication.h"
#ifndef FACTORYCLASS_H
#define FACTORYCLASS_H
class FactoryClass : public BaseApplication
{
public:
FactoryClass(void);
virtual~FactoryClass(void);
enum QueryFlags
{
NINJA_MASK = 1<<0,
ROBOT_MASK = 1<<1,
KNOT_MASK = 1<<2,
PENGUIN_MASK = 1<<3
};
Ogre::SceneNode* createObject(int ObjID, Ogre::Vector3 pos);
protected:
virtual bool keyPressed(const OIS::KeyEvent& arg);
int mCount;
int ObjID;
};
#endif
and the FactoryClass implementation file :
Code: Select all
#include "FactoryClass.h"
FactoryClass::FactoryClass(void)
{
mCount = 0;
int ObjID = 0;
}
FactoryClass::~FactoryClass(void)
{
}
Ogre::SceneNode* FactoryClass::createObject(int ObjID, Ogre::Vector3 pos)
{
Ogre::Entity* ent;
char name[16];
switch(ObjID)
{
case 1:
sprintf(name, "Robot%d", mCount++);
ent = mSceneMgr->createEntity(name, "robot.mesh");
ent->setQueryFlags(ROBOT_MASK);
break;
case 2:
sprintf(name, "Ninja%d", mCount++);
ent = mSceneMgr->createEntity(name, "ninja.mesh");
ent->setQueryFlags(NINJA_MASK);
break;
case 3:
sprintf(name, "Knot%d", mCount++);
ent = mSceneMgr->createEntity(name, "knot.mesh");
ent->setQueryFlags(KNOT_MASK);
break;
case 4:
sprintf(name, "Penguin%d", mCount++);
ent = mSceneMgr->createEntity(name, "penguin.mesh");
ent->setQueryFlags(PENGUIN_MASK);
break;
default:
//unknown id, maybe throw an exeption, for now just return silently
return 0;
}
Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode(std::string(name) + "Node", pos);
node->attachObject(ent);
node->setScale(0.1f, 0.1f, 0.1f);
return node;
}
bool FactoryClass::keyPressed(const OIS::KeyEvent& arg)
{
switch(arg.key)
{
case OIS::KC_0:
ObjID = 1;
break;
case OIS::KC_1:
ObjID = 2;
break;
case OIS::KC_2:
ObjID = 3;
break;
case OIS::KC_3:
ObjID = 4;
break;
}
// then we return the base app keypressed function so that we get all of the functionality
//and the return value in one line
return BaseApplication::keyPressed(arg);
}
and the intermediateTurtorial implementation:
Code: Select all
/*
-----------------------------------------------------------------------------
Filename: IntermediateTutorial2.cpp
-----------------------------------------------------------------------------
This source file is generated by the
___ _ __ __ _ _
/___\__ _ _ __ ___ /_\ _ __ _ __/ / /\ \ (_)______ _ _ __ __| |
// // _` | '__/ _ \ //_\\| '_ \| '_ \ \/ \/ / |_ / _` | '__/ _` |
/ \_// (_| | | | __/ / _ \ |_) | |_) \ /\ /| |/ / (_| | | | (_| |
\___/ \__, |_| \___| \_/ \_/ .__/| .__/ \/ \/ |_/___\__,_|_| \__,_|
|___/ |_| |_|
Ogre 1.7.x Application Wizard for VC10 (July 2011)
http://code.google.com/p/ogreappwizards/
-----------------------------------------------------------------------------
*/
#include "IntermediateTutorial2.h"
#include <CEGUISystem.h>
#include <CEGUISchemeManager.h>
#include <RendererModules/Ogre/CEGUIOgreRenderer.h>
//-------------------------------------------------------------------------------------
IntermediateTutorial2::IntermediateTutorial2(void)
{
//bRobotMode = true;
}
//-------------------------------------------------------------------------------------
IntermediateTutorial2::~IntermediateTutorial2(void)
{
mSceneMgr->destroyQuery(mRaySceneQuery);
}
//-------------------------------------------------------------------------------------
void IntermediateTutorial2::createScene(void)
{
//Set ambient light
mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
//World geometry
mSceneMgr->setWorldGeometry("terrain.cfg");
//Set camera look point
mCamera->setPosition(40, 100, 580);
mCamera->pitch(Ogre::Degree(-30));
mCamera->yaw(Ogre::Degree(-45));
// CEGUI setup
mGUIRenderer = &CEGUI::OgreRenderer::bootstrapSystem();
//Mouse
CEGUI::SchemeManager::getSingleton().create((CEGUI::utf8*)"TaharezLook.scheme");
CEGUI::MouseCursor::getSingleton().setImage("TaharezLook", "MouseArrow");
/*Ogre::Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh");
Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
headNode->attachObject(ogreHead);
// Set ambient light
mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
// Create a light
Ogre::Light* l = mSceneMgr->createLight("MainLight");
l->setPosition(20,80,50);*/
}
void IntermediateTutorial2::createFrameListener(void)
{
BaseApplication::createFrameListener();
//Setup default variables
//mCount = 0;
ObjID = 1;
mCurrentObject = NULL;
mLMouseDown = false;
mRMouseDown = false;
//Reduce rotate speed
mRotateSpeed = .1;
//Create RaySceneQuery
mRaySceneQuery = mSceneMgr->createRayQuery(Ogre::Ray());
}
void IntermediateTutorial2::chooseSceneManager(void)
{
mSceneMgr = mRoot->createSceneManager(Ogre::ST_EXTERIOR_CLOSE);
}
bool IntermediateTutorial2::frameRenderingQueued(const Ogre::FrameEvent& evt)
{
return BaseApplication::frameRenderingQueued(evt);
//Setup the scene query
Ogre::Vector3 camPos = mCamera->getPosition();
Ogre::Ray cameraRay(Ogre::Vector3(camPos.x, 5000.0f, camPos.z), Ogre::Vector3::NEGATIVE_UNIT_Y);
mRaySceneQuery->setRay(cameraRay);
mRaySceneQuery->setSortByDistance(false);
//Perform the scene query
Ogre::RaySceneQueryResult &result = mRaySceneQuery->execute();
Ogre::RaySceneQueryResult::iterator itr = result.begin();
//Get the results , set the camera height
//if(itr != result.end() && itr->worldFragment)
for(itr; itr != result.end(); itr++)
{
if(itr->worldFragment)
{
Ogre::Real terrainHeight = itr->worldFragment->singleIntersection.y;
if((terrainHeight + 10.0f) > camPos.y)
{
mCamera->setPosition(camPos.x, terrainHeight + 10.0f, camPos.z);
}
break;
}//if
}//for
return true;
return false;
}
bool IntermediateTutorial2::mouseMoved(const OIS::MouseEvent& arg)
{
//Update CEGUI with the mouse motion
CEGUI::System::getSingleton().injectMouseMove(arg.state.X.rel, arg.state.Y.rel);
//If we are dragging the left mouse button
if(mLMouseDown)
{
CEGUI::Point mousePos = CEGUI::MouseCursor::getSingleton().getPosition();
Ogre::Ray mouseRay = mCamera->getCameraToViewportRay(mousePos.d_x / float(arg.state.width), mousePos.d_y / float(arg.state.height));
mRaySceneQuery->setRay(mouseRay);
mRaySceneQuery->setSortByDistance(false);
Ogre::RaySceneQueryResult &result = mRaySceneQuery->execute();
Ogre::RaySceneQueryResult::iterator itr = result.begin();
//if(itr != result.end() && itr->worldFragment)
for(itr; itr != result.end(); itr++)
{
if(itr->worldFragment)
{
mCurrentObject->setPosition(itr->worldFragment->singleIntersection);
break;
}//if
}//for
}//if
//if we are dragging the right mouse button
else if(mRMouseDown)
{
mCamera->yaw(Ogre::Degree(-arg.state.X.rel * mRotateSpeed));
mCamera->pitch(Ogre::Degree(-arg.state.Y.rel * mRotateSpeed));
}//else if
return true;
}
/*bool IntermediateTutorial2::ObjectID(const OIS::KeyEvent& key, Ogre::Entity* ent)
{
switch(key.key)
{
case OIS::KC_0:
mObjectList.push_back(Ogre::Entity::EntitySet("Ninja", "ninja.mesh"));
break;
case OIS::KC_1:
mObjectList.push_back(Ogre::Entity::EntitySet("Robot", "robot.mesh"));
break;
case OIS::KC_2:
mObjectList.push_back(Ogre::Entity::EntitySet("Knot", "knot.mesh"));
break;
};
return true;
}*/
bool IntermediateTutorial2::mousePressed(const OIS::MouseEvent& arg, OIS::MouseButtonID id)
{
//Left mouse button down
if(id == OIS::MB_Left)
{
if(mCurrentObject)
{
//show that the current object has been deselected by removing box visual
mCurrentObject->showBoundingBox(false);
}
//Setup the ray scene query, use CEGUI's mouse position
CEGUI::Point mousePos = CEGUI::MouseCursor::getSingleton().getPosition();
Ogre::Ray mouseRay = mCamera->getCameraToViewportRay(mousePos.d_x / float(arg.state.width), mousePos.d_y / float(arg.state.height));
mRaySceneQuery->setRay(mouseRay);
mRaySceneQuery->setSortByDistance(true);
mRaySceneQuery->setQueryMask(ROBOT_MASK | NINJA_MASK | KNOT_MASK | PENGUIN_MASK);
//Execute query
Ogre::RaySceneQueryResult &result = mRaySceneQuery->execute();
Ogre::RaySceneQueryResult::iterator itr = result.begin();
//Get results, create a node /entity on the position
/*if(itr != result.end() && itr->worldFragment)
{
mFactory->CreateObject(mID),itr->worldFragment->singleIntersection;
char name[16];
if(bRobotMode)
{
sprintf(name, "Robot%d", mCount++ );
Ogre::Entity* ent = mSceneMgr->createEntity(name, "robot.mesh");
mCurrentObject = mSceneMgr->getRootSceneNode()->createChildSceneNode(std::string(name) + "Node", itr->worldFragment->singleIntersection);
mCurrentObject->attachObject(ent);
mCurrentObject->setScale(0.1f, 0.1f, 0.1f);
}
else
{
sprintf(name, "Ninja%d", mCount++);
Ogre::Entity* entNin = mSceneMgr->createEntity(name, "ninja.mesh");
mCurrentObject = mSceneMgr->getRootSceneNode()->createChildSceneNode(std::string(name) + "Node", itr->worldFragment->singleIntersection);
mCurrentObject->attachObject(entNin);
mCurrentObject->setScale(0.1f, 0.1f, 0.1f);
}
}//if*/
//Get results, create a node/entity on the position
for(itr; itr != result.end(); itr++)
{
if(itr->movable && itr->movable->getName().substr(0, 5) != "tile[")
{
mCurrentObject = itr->movable->getParentSceneNode();
break;
}//if
else if(itr->worldFragment)
{
mCurrentObject = mFactory->createObject(ObjID, itr->worldFragment->singleIntersection);
/*
Ogre::Entity* ent;
char name[16];
if(mID == 1)
{
//mObjectList.front();
sprintf(name, "Robot%d", mCount++);
ent = mSceneMgr->createEntity(name, "robot.mesh");
ent->setQueryFlags(ROBOT_MASK);
}//if
else if(mID == 2)
{
sprintf(name, "Ninja%d", mCount++);
ent = mSceneMgr->createEntity(name, "ninja.mesh");
ent->setQueryFlags(NINJA_MASK);
}//else if
else if(mID == 3)
{
sprintf(name, "Knot%d", mCount++);
ent = mSceneMgr->createEntity(name, "knot.mesh");
ent->setQueryFlags(KNOT_MASK);
}
else
{
sprintf(name, "Penguin%d", mCount++);
ent = mSceneMgr->createEntity(name, "penguin.mesh");
ent->setQueryFlags(PENGUIN_MASK);
}
mCurrentObject = mSceneMgr->getRootSceneNode()->createChildSceneNode(std::string(name) + "Node", itr->worldFragment->singleIntersection);
mCurrentObject->attachObject(ent);
mCurrentObject->setScale(0.1f, 0.1f, 0.1f);
break;*/
}//else if
}
mLMouseDown = true;
}//for
//Right mouse button down
else if(id == OIS::MB_Right)
{
CEGUI::MouseCursor::getSingleton().hide();
mRMouseDown = true;
}//else if
if(mCurrentObject)
{
mCurrentObject->showBoundingBox(true);
}
return true;
}
bool IntermediateTutorial2::mouseReleased(const OIS::MouseEvent& arg, OIS::MouseButtonID id)
{
//Left mouse button up
if(id == OIS::MB_Left)
{
mLMouseDown = false;
}
//Right mouse button up
else if(id == OIS::MB_Right)
{
CEGUI::MouseCursor::getSingleton().show();
mRMouseDown = false;
}//else if
return true;
}
/*Ogre::SceneNode* IntermediateTutorial2::createObject(int ObjID, Ogre::Vector3 pos)
{
Ogre::Entity* ent;
char name[16];
switch(ObjID)
{
case 1:
sprintf(name, "Robot%d", mCount++);
ent = mSceneMgr->createEntity(name, "robot.mesh");
ent->setQueryFlags(ROBOT_MASK);
break;
case 2:
sprintf(name, "Ninja%d", mCount++);
ent = mSceneMgr->createEntity(name, "ninja.mesh");
ent->setQueryFlags(NINJA_MASK);
break;
case 3:
sprintf(name, "Knot%d", mCount++);
ent = mSceneMgr->createEntity(name, "knot.mesh");
ent->setQueryFlags(KNOT_MASK);
break;
case 4:
sprintf(name, "Penguin%d", mCount++);
ent = mSceneMgr->createEntity(name, "penguin.mesh");
ent->setQueryFlags(PENGUIN_MASK);
break;
default:
//unknown id, maybe throw an exeption, for now just return silently
return 0;
}
Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode(std::string(name) + "Node", pos);
node->attachObject(ent);
node->setScale(0.1f, 0.1f, 0.1f);
return node;
}*/
/*bool IntermediateTutorial2::keyPressed(const OIS::KeyEvent& arg)
{
//Check and see if the space barf was hit, and this will switch which mesh is spawned
//if(arg.key == OIS::KC_SPACE)
//{
// bRobotMode = !bRobotMode;
//}
switch(arg.key)
{
case OIS::KC_0:
ObjID = 1;
break;
case OIS::KC_1:
ObjID = 2;
break;
case OIS::KC_2:
ObjID = 3;
break;
case OIS::KC_3:
ObjID = 4;
break;
}
// then we return the base app keypressed function so that we get all of the functionality
//and the return value in one line
return BaseApplication::keyPressed(arg);
}*/
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char *argv[])
#endif
{
// Create application object
IntermediateTutorial2 app;
try {
app.go();
} catch( Ogre::Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
std::cerr << "An exception has occured: " <<
e.getFullDescription().c_str() << std::endl;
#endif
}
return 0;
}
#ifdef __cplusplus
}
#endif
and the IntermediateTutorial class header:
Code: Select all
/*
-----------------------------------------------------------------------------
Filename: IntermediateTutorial2.h
-----------------------------------------------------------------------------
This source file is generated by the
___ _ __ __ _ _
/___\__ _ _ __ ___ /_\ _ __ _ __/ / /\ \ (_)______ _ _ __ __| |
// // _` | '__/ _ \ //_\\| '_ \| '_ \ \/ \/ / |_ / _` | '__/ _` |
/ \_// (_| | | | __/ / _ \ |_) | |_) \ /\ /| |/ / (_| | | | (_| |
\___/ \__, |_| \___| \_/ \_/ .__/| .__/ \/ \/ |_/___\__,_|_| \__,_|
|___/ |_| |_|
Ogre 1.7.x Application Wizard for VC10 (July 2011)
http://code.google.com/p/ogreappwizards/
-----------------------------------------------------------------------------
*/
#ifndef __IntermediateTutorial2_h_
#define __IntermediateTutorial2_h_
#include "BaseApplication.h"
#include <CEGUI.h>
#include <RendererModules\Ogre\CEGUIOgreRenderer.h>
#include "FactoryClass.h"
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#include "../res/resource.h"
#endif
class IntermediateTutorial2 : public BaseApplication
{
public:
IntermediateTutorial2(void);
virtual ~IntermediateTutorial2(void);
enum QueryFlags
{
NINJA_MASK = 1<<0,
ROBOT_MASK = 1<<1,
KNOT_MASK = 1<<2,
PENGUIN_MASK = 1<<3
};
protected:
virtual void createScene(void);
virtual void chooseSceneManager(void);
virtual void createFrameListener(void);
//virtual void CreateObjectID(int ID);
//frame listener
virtual bool frameRenderingQueued(const Ogre::FrameEvent& evt);
//mouse listener
virtual bool mouseMoved(const OIS::MouseEvent& arg);
virtual bool mousePressed(const OIS::MouseEvent& arg, OIS::MouseButtonID id);
virtual bool mouseReleased(const OIS::MouseEvent& arg, OIS::MouseButtonID id);
//Ogre::SceneNode* createObject(int ObjID, Ogre::Vector3 pos);
//virtual bool keyPressed(const OIS::KeyEvent& arg);
//virtual bool createObject(int ObjID, Ogre::Vector3 pos);
//virtual bool ObjectID(const OIS::KeyEvent& arg, Ogre::Entity* ent);
Ogre::RaySceneQuery* mRaySceneQuery;// The Ray scene query pointer
bool mLMouseDown, mRMouseDown; //True if the mouse buttons are down
//int mCount; //the number of robots on the screen
Ogre::SceneNode* mCurrentObject; // The newly created object
CEGUI::Renderer *mGUIRenderer; //CEGUI renderer
float mRotateSpeed;
//bool bRobotMode; //The current state
//std::deque<Ogre::Entity::EntitySet> mObjectList;
//std::pair<Ogre::SceneManager, Ogre::SceneNode> mList;
//std::vector<FactoryClass*> mFactory;
FactoryClass* mFactory;
//int mID;
int ObjID;
};
#endif // #ifndef __IntermediateTutorial2_h_
i hope ur patient enough to teach me one more lesson before i move on with the other intermediate tutorials!
thx a lot for everything you have showed me so far and i hope to get it solved soon !
Kind regards,
Romulo Romero
EDIT: something seems to be wrong with the mCount name incrementation in the factoryclass .cpp file