Questions of start to use QuickGUI

yukito

18-04-2009 11:43:27

I'm just a beginner of using OGRE and QuickGUI

Now I have a big problem(for a long time)

I don't know how to use it :(

I've tried to read the tutorials of wiki,but I can't understand it.

Now I even can't understand "How to set up the application" from tutorial 1

I have tried to read the "playpen" demo,too,but I'm too to stupid to read it :(



I know it's a really unreasonable request

but,is there someone can provide a simplest example code for "setting up the application" & "Creating a Button and registering Event Handlers" just in "one" .cpp file ?

or help me to correct my code

I don't have any way to solve my problem,please help me :(


By the way,I don't have any experience of using CEGUI

Should I go back to learn how to use CEGUI ?


Poor english,sorry m(_ _)m

#include "ExampleApplication.h"

#include <CEGUI/CEGUISystem.h>
#include <CEGUI/CEGUISchemeManager.h>
#include <OgreCEGUIRenderer.h>

#include <QuickGUIRoot.h>
#include <QuickGUI.h>

#define CAMERA_NAME "PlayerCam"
#define CAMERA_NAME2 "PlayerCam2"



void setupViewport(RenderWindow *win, SceneManager *curr,Real cm)
{
win->removeAllViewports();
Camera *cam;
//Camera *cam = curr->getCamera(CAMERA_NAME);
if(cm==0)
cam = curr->getCamera(CAMERA_NAME);
if(cm==1)
cam = curr->getCamera(CAMERA_NAME2);

Viewport *vp = win->addViewport(cam);

vp->setBackgroundColour(ColourValue(0,0,0));
cam->setAspectRatio(Real(vp->getActualWidth()) / Real(vp->getActualHeight()));

}


class TutorialFrameListener : public ExampleFrameListener, public OIS::MouseListener, public OIS::KeyListener
{
public:
TutorialFrameListener(RenderWindow* win, Camera* cam,Entity *ent, SceneManager *sceneMgr, SceneManager *sceneMgr2,CEGUI::Renderer *renderer)
: ExampleFrameListener(win, cam, true, true), mEntity(ent), mGUIRenderer(renderer)
{

//宣告 mSceneMgr 跟 各節點
mSceneMgr=sceneMgr;
mSceneMgr2=sceneMgr2;

win=win;

mNode =mSceneMgr->getSceneNode("NinjaNode");

//mNode2=mSceneMgr->getSceneNode("NinjaNode2");

cp_node =mSceneMgr->getSceneNode("CamparentNode");
denode =mSceneMgr->getSceneNode("deNode");

//初始移動跟旋轉時的速度
r_m_speed= 100;

//初始camera總共轉了幾度
all_camera_rotate=0;

//初始現在動畫應該為何
what_move=0;

//初始現在是按前還後
f_or_b=0;

//初始偵測的點,前後各一個
de_node=0;
de_node2=0;

//初始camera name
cm=0;

//continue rendering
mContinue = true;

mMouse->setEventCallback(this);
mKeyboard->setEventCallback(this);

//x存攝影機轉動角度.y存物體應自轉角度,z存物體應移動量
rm_value = Vector3::ZERO;

mRaySceneQuery = mSceneMgr->createRayQuery(Ray());
m2RaySceneQuery = mSceneMgr->createRayQuery(Ray());

}

~TutorialFrameListener()
{
mSceneMgr->destroyQuery(mRaySceneQuery);
mSceneMgr->destroyQuery(m2RaySceneQuery);
}

// MouseListener
bool mouseMoved(const OIS::MouseEvent &e)
{
if (e.state.buttonDown(OIS::MB_Right))
{
// mCamNode->yaw(Degree(-mRotate * e.state.X.rel), Node::TS_PARENT);
// mCamNode->pitch(Degree(mRotate * e.state.Y.rel), Node::TS_LOCAL);
// mCamNode->roll(Degree(-mRotate * e.state.Z.rel), Node::TS_LOCAL);
}
return true;
}

bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
{
Light *light = mSceneMgr->getLight("Light1");
switch (id)
{
case OIS::MB_Left:
light->setVisible(! light->isVisible());
break;
}
return true;
}

bool mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) { return true; }

// KeyListener
bool keyPressed(const OIS::KeyEvent &e)
{
switch (e.key)
{
case OIS::KC_ESCAPE:
mContinue = false;
break;

case OIS::KC_1:
//mCamera->getParentSceneNode()->detachObject(mCamera);
//mCamNode = mSceneMgr->getSceneNode("CamNode1");
//mCamNode->attachObject(mCamera);
cm=0;
setupViewport(mWindow, mSceneMgr,0);
break;

case OIS::KC_2:
//mCamera->getParentSceneNode()->detachObject(mCamera);
//mCamNode = mSceneMgr->getSceneNode("CamNode2");
//mCamNode->attachObject(mCamera);
cm=1;
setupViewport(mWindow, mSceneMgr2,1);
break;

case OIS::KC_UP:
rm_value.z -= r_m_speed;
what_move+=1;
f_or_b=1;
de_node=1;
break;

case OIS::KC_DOWN:
rm_value.z+= r_m_speed;
what_move+=1;
f_or_b=2;
de_node2=1;
break;

case OIS::KC_LEFT:
rm_value.y -= r_m_speed;
what_move+=1;
f_or_b=3;
break;

case OIS::KC_RIGHT:
rm_value.y += r_m_speed;
what_move+=1;
f_or_b=3;
break;

case OIS::KC_W:
break;

case OIS::KC_S:
break;

case OIS::KC_A:
rm_value.x -= r_m_speed;
break;

case OIS::KC_D:
rm_value.x += r_m_speed;
break;

case OIS::KC_PGDOWN:
case OIS::KC_E:
break;

case OIS::KC_PGUP:
case OIS::KC_Q:
break;
}
return true;
}

bool keyReleased(const OIS::KeyEvent &e)
{
switch (e.key)
{
case OIS::KC_UP:
rm_value.z += r_m_speed;
what_move-=1;
de_node=0;
break;

case OIS::KC_DOWN:
rm_value.z -= r_m_speed;
what_move-=1;
de_node2=0;
break;

case OIS::KC_LEFT:
rm_value.y += r_m_speed;
what_move-=1;
break;

case OIS::KC_RIGHT:
rm_value.y -= r_m_speed;
what_move-=1;
break;

case OIS::KC_W:
break;

case OIS::KC_S:
break;

case OIS::KC_A:
rm_value.x += r_m_speed;
break;

case OIS::KC_D:
rm_value.x -= r_m_speed;
break;

case OIS::KC_PGDOWN:
case OIS::KC_E:
break;

case OIS::KC_PGUP:
case OIS::KC_Q:
break;
}
return true;
}

bool frameStarted(const FrameEvent &evt)
{
//第一場景
if(cm==0)
{
if(!ExampleFrameListener::frameStarted(evt))
return false;

//地行偵測,讓物體一直在地形上
Vector3 enPos = mNode->getPosition();
Ray cameraRay(Vector3(enPos.x, 5000.0f, enPos.z), Vector3::NEGATIVE_UNIT_Y);
mRaySceneQuery->setRay(cameraRay);

RaySceneQueryResult &result = mRaySceneQuery->execute();
RaySceneQueryResult::iterator itr = result.begin();

if(itr != result.end() && itr->worldFragment)
{
Real terrainHeight = itr->worldFragment->singleIntersection.y;
if (terrainHeight != enPos.y)
{
mNode->setPosition( enPos.x, terrainHeight , enPos.z );
}

enPos = mNode->getPosition();
cp_node->setPosition(enPos);
denode->setPosition(enPos);

}

//判斷輸入種類為何
if(mMouse)
mMouse->capture();

if(mKeyboard)
mKeyboard->capture();

cp_node->yaw(Degree(rm_value.x* evt.timeSinceLastFrame), Node::TS_WORLD);

all_camera_rotate+=rm_value.x*evt.timeSinceLastFrame;


if(f_or_b==1||f_or_b==2||f_or_b==3)
{
cp_node->yaw(Degree((-all_camera_rotate)),Node::TS_WORLD);
all_camera_rotate=0;
f_or_b=0;
}

mNode->yaw(Degree(-rm_value.y* evt.timeSinceLastFrame), Node::TS_WORLD);
cp_node->yaw(Degree(-rm_value.y* evt.timeSinceLastFrame), Node::TS_WORLD);
denode->yaw(Degree(-rm_value.y* evt.timeSinceLastFrame), Node::TS_WORLD);

//檢查碰撞偵測,往前進時
denode->translate(0,0,-10,Node::TS_LOCAL);
enPos = denode->getPosition();
denode->translate(0,0,10,Node::TS_LOCAL);
Ray deRay2(Vector3(enPos.x, enPos.y-1, enPos.z), Vector3::UNIT_Y);
m2RaySceneQuery->setRay(deRay2);
m2RaySceneQuery->setSortByDistance(true);

// Execute query
RaySceneQueryResult &result2 = m2RaySceneQuery->execute();
RaySceneQueryResult::iterator itr2;

// Get results, create a node/entity on the position
for ( itr2 = result2.begin(); itr2!= result2.end(); itr2++ )
{
if (itr2->movable && itr2->movable->getName().substr(0, 5) != "tile["&&itr2->movable->getName()!="PlayerCam"&&itr2->movable->getName()!="Ninja" )
{
if(de_node==1)
{
std::cout << "MovableObject: " << itr2->movable->getName();
// node2=itr2->movable->getParentSceneNode();
// Vector3 enPos2 =mNode->getPosition();
// enPos = node2->getPosition();
// enPos.y=0;
// Vector3 enPos3 =enPos2-enPos;
// node2->translate(-enPos3,Node::TS_LOCAL);

mNode->translate(rm_value.z* evt.timeSinceLastFrame,0,0,Node::TS_LOCAL);
break;
}
} //if

else if(itr2->worldFragment)
{
break;
}
}

//檢查碰撞偵測,往後退時
denode->translate(0,0,10,Node::TS_LOCAL);
enPos = denode->getPosition();
denode->translate(0,0,-10,Node::TS_LOCAL);
Ray deRay3(Vector3(enPos.x, enPos.y-1, enPos.z), Vector3::UNIT_Y);
m2RaySceneQuery->setRay(deRay3);
m2RaySceneQuery->setSortByDistance(true);

// Execute query
RaySceneQueryResult &result3 = m2RaySceneQuery->execute();
RaySceneQueryResult::iterator itr3;

// Get results, create a node/entity on the position
for(itr3 = result3.begin(); itr3!= result3.end(); itr3++ )
{
if (itr3->movable && itr3->movable->getName().substr(0, 5) != "tile["&&itr3->movable->getName()!="PlayerCam"&&itr3->movable->getName()!="Ninja" )
{
if(de_node2==1)
{
std::cout << "MovableObject: " << itr3->movable->getName();

mNode->translate(rm_value.z* evt.timeSinceLastFrame,0,0,Node::TS_LOCAL);
break;
}
} // if

else if (itr3->worldFragment)
{
// mNode->translate(-rm_value.z* evt.timeSinceLastFrame,0,0,Node::TS_LOCAL);
break;
}
}


mNode->translate(-rm_value.z* evt.timeSinceLastFrame,0,0,Node::TS_LOCAL);



//判斷物體現在該有的動畫
if(what_move==0)
{
mAnimationState = mEntity->getAnimationState("Idle");
mAnimationState->setLoop(true);
mAnimationState->setEnabled(true);
}
if(what_move>0)
{
mAnimationState = mEntity->getAnimationState("Walk");
mAnimationState->setLoop(true);
mAnimationState->setEnabled(true);
}
mAnimationState->addTime(evt.timeSinceLastFrame);




enPos = denode->getPosition();

if(350<enPos.x&&enPos.x<450)
{
if(650<enPos.z&&enPos.z<750)
{
//cm=1;
// setupViewport(mWindow, mSceneMgr2,1);
}
}

}

return mContinue;
}

protected:
Real r_m_speed; //用來判斷移動跟旋轉時的速度
Real all_camera_rotate; //用來判斷camera總共轉度角度
Real what_move; //用來判斷現在動作為何
Real f_or_b; //用來判斷是否按前了,當案前進後退時,要把角度轉回來,1是前,2是後,3是轉棟,0為無動作
Real de_node; //用來判斷現在往前還往後,判斷要用哪一個偵測點
Real de_node2;
Real cm; //用來判斷現在camera name 該用哪個

Vector3 rm_value; //x存攝影機轉動角度.y存物體應自轉角度,z存物體應移動量

SceneManager *mSceneMgr; //The current SceneManager
SceneManager *mSceneMgr2;


SceneNode *mNode; //物體本身node
//SceneNode *node2; //當想玩碰撞位移時,來當碰撞node(目前無用)

SceneNode *mNode2; //物體本身node

SceneNode *cp_node; //camera的父節點
SceneNode *denode;

Entity *mEntity ;
//Entity *m3Entity ;

AnimationState *mAnimationState;

bool mContinue; // Whether to continue rendering or not


RaySceneQuery *mRaySceneQuery;
RaySceneQuery *m2RaySceneQuery;
CEGUI::Renderer *mGUIRenderer;

};

class TutorialApplication : public ExampleApplication
{
public:
Entity *mEntity;
Entity *m2Entity;
Entity *m3Entity;

SceneManager *mSceneMgr2;

SceneManager *mSceneManager;

Camera *mCamera2;
Camera *mCamera3;

CEGUI::OgreCEGUIRenderer *mGUIRenderer;
CEGUI::System *mGUISystem;
QuickGUI::GUIManagerDesc d;
QuickGUI::GUIManager *mGUIManager;


void createQuickGUI()
{
QuickGUI::registerScriptReader();

Ogre::ResourceGroupManager::getSingleton().addResourceLocation("media/gui/QuickQuiResources","FileSystem","QuickGUI");
Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("QuickGUI");

new QuickGUI::Root();

QuickGUI::SkinTypeManager::getSingletonPtr()->loadTypes();

d.sceneManager = mSceneManager;
d.viewport = mCamera3->getViewport();

d.queueID = Ogre::RENDER_QUEUE_OVERLAY;

QuickGUI::GUIManager* mGUIManager = QuickGUI::Root::getSingletonPtr()->createGUIManager(d);

QuickGUI::SheetDesc* sd = QuickGUI::DescManager::getSingleton().getDefaultSheetDesc();
sd->resetToDefault();
sd->widget_dimensions.size = QuickGUI::Size(800,600);

QuickGUI::Sheet* mySheet = new QuickGUI::Sheet(sd);
mGUIManager->setActiveSheet(mySheet);
}

void createCamera(void)
{
mCamera = mSceneMgr->createCamera("PlayerCam");
mCamera2 = mSceneMgr2->createCamera("PlayerCam2");
mCamera3 = mSceneManager -> createCamera("QuickCam");
//mCamera->setNearClipDistance(5);
}

void chooseSceneManager(void)
{
mSceneMgr = mRoot->createSceneManager(ST_EXTERIOR_CLOSE);
//mSceneMgr2 =mRoot->createSceneManager(ST_GENERIC, "secondary");
mSceneMgr2 =mRoot->createSceneManager(ST_EXTERIOR_CLOSE);
ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
}


void createScene(void)
{
mSceneMgr->setSkyDome(true, "Examples/CloudySky",5,8);
mSceneMgr2->setSkyBox(true, "Examples/SpaceSkyBox");

mSceneMgr ->setWorldGeometry("terrain.cfg");
mSceneMgr2->setWorldGeometry("terrain.cfg");

mSceneMgr->setAmbientLight(ColourValue(0.25, 0.25, 0.25));

mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mSceneMgr);
mGUISystem = new CEGUI::System(mGUIRenderer);

QuickGUI::Sheet* defaultSheet = mGUIManager->getActiveSheet();
QuickGUI::DescManager::getSingleton();
QuickGUI::ButtonDesc* bd = QuickGUI::DescManager::getSingleton().getDefaultButtonDesc();
bd->widget_name = "MyButton";
bd->widget_dimensions.size = QuickGUI::Size(100,25);
bd->widget_dimensions.position = QuickGUI::Point(50,50);
QuickGUI::Button* myButton = defaultSheet->createButton(bd);



//主場景物件-----------------------------------------------------------------------------------------------------------
{

mEntity = mSceneMgr->createEntity("Ninja","robot.mesh");
SceneNode *mNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("NinjaNode", Vector3(400, 0, 600));
mNode->attachObject(mEntity);
mNode->scale( 1, 1, 1 );
mNode->yaw( Degree( 90 ) );

m2Entity = mSceneMgr->createEntity("Ninja2","robot.mesh");
SceneNode *m2Node = mSceneMgr->getRootSceneNode()->createChildSceneNode("NinjaNode2", Vector3(400, 0, 700));
m2Node->attachObject(m2Entity);
m2Node->scale( 1, 1, 1 );

//偵測點
SceneNode *denode =mSceneMgr->getRootSceneNode()->createChildSceneNode("deNode", Vector3(400, 0 , 600));

// create the light
Light *light = mSceneMgr->createLight("Light1");
light->setType(Light::LT_POINT);
light->setPosition(Vector3(250, 150, 250));
light->setDiffuseColour(ColourValue::White);
light->setSpecularColour(ColourValue::White);

// Create camera的父節點
SceneNode *cp_node= mSceneMgr->getRootSceneNode()->createChildSceneNode("CamparentNode", Vector3(400, 0, 600));

// Create camera本身節點
SceneNode *c_node = cp_node->createChildSceneNode("CamNode1", Vector3(0, 130, 100));
c_node->pitch(Degree(-30));
c_node->attachObject(mCamera);
}
//------------------------------------------------------------------------------------------------------------------------


//戰鬥場景物件------------------------------------------------------------------------------------------------------------
{

m3Entity = mSceneMgr2->createEntity("Ninja3","robot.mesh");
SceneNode *m3Node = mSceneMgr2->getRootSceneNode()->createChildSceneNode("NinjaNode3", Vector3(200, 100, 400));
m3Node->attachObject(m3Entity);
m3Node->scale( 1, 1, 1 );

SceneNode *c_node2 = mSceneMgr2->getRootSceneNode()->createChildSceneNode("CamNode2", Vector3(200, 130, 400));
c_node2->pitch(Degree(-30));
c_node2->attachObject(mCamera2);
}
//----------------------------------------------------------------------------------------------------------------------
}

void createFrameListener(void)
{
// Create the FrameListener
mFrameListener = new TutorialFrameListener(mWindow, mCamera2,mEntity ,mSceneMgr,mSceneMgr2,mGUIRenderer);
mRoot->addFrameListener(mFrameListener);

// Show the frame stats overlay
mFrameListener->showDebugOverlay(true);
}
};

#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN__MEAN
#include "windows.h"

INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
#else
int main(int argc, char **argv)
#endif
{
// Create application object
TutorialApplication app;

try {
app.go();
} catch(Exception& e) {
#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBox(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
fprintf(stderr, "An exception has occurred: %s\n",
e.getFullDescription().c_str());
#endif
}

return 0;
}

kungfoomasta

18-04-2009 18:09:20

Hi yukito. I skimmed through your code, and I don't see where

createQuickGUI()

is being called. When/where do you call this? Does the PlayPen app compile? What platform are you on?

yukito

19-04-2009 05:56:22

> When/where do you call this?
OH!I haven't call this,Where should I call ? I just have this code , I didn't call another code. :D

> Does the PlayPen app compile?
YES~

>What platform are you on?
VisualStudio 2008 , OGRE 1.61 , QuickGUI 9.04

kungfoomasta

19-04-2009 19:28:46

All of the information is in this wiki article:

http://www.ogre3d.org/wiki/index.php/QuickGUI_Beginner_Tutorial_1

You can't put it all into one function, you have to register the script parser before you initialise all the resource groups, and after initialization of the groups, then you can create the Root and GUIManager.