Ogre commands in NXogre

OgreNewbie123

02-04-2007 20:21:14

Hi there

I am able to build and run the nxogre tutorials.
But now I wanted to make something on my own

I wanted to put a robot mesh into a tutorial for experimenting
I added the this code under void start()

Entity *ent1 = mSceneMgr->createEntity( "Robot", "robot.mesh" );
SceneNode *node1 = mSceneMgr->getRootSceneNode()->createChildSceneNode( "RobotNode" );
node1->attachObject( ent1 );
node1->scale(0.5, 1, 2 );


the build succeeds but if I want to run the exe. The dos screen appears and when the second "render" screens appears it suddenly quits.

some log file says this:


...
21:14:32: Texture: debug.png: Loading 1 faces(PF_A8R8G8B8,22x22x1) with 4 generated mipmaps from Image. Internal format is PF_A8R8G8B8,22x22x1.
21:14:32: Texture: bgui.pointer.png: Loading 1 faces(PF_A8R8G8B8,24x24x1) with 4 generated mipmaps from Image. Internal format is PF_A8R8G8B8,24x24x1.
21:14:32: Texture: gui_pause.png: Loading 1 faces(PF_A8R8G8B8,128x128x1) with hardware generated mipmaps from Image. Internal format is PF_A8R8G8B8,128x128x1.
21:14:32: Font nxogrefontusing texture size 512x256
21:14:32: Info: Freetype returned null for character 160 in font nxogrefont
21:14:32: Texture: nxogrefontTexture: Loading 1 faces(PF_BYTE_LA,512x256x1) with 0 generated mipmaps from Image. Internal format is PF_BYTE_LA,512x256x1.
21:14:32: Mesh: Loading nx.bodyguide.mesh.
21:14:32: WARNING: nx.bodyguide.mesh is an older format ([MeshSerializer_v1.30]); you should upgrade it as soon as possible using the OgreMeshUpgrade tool.
21:14:32: Texture: bodyguide1m.png: Loading 1 faces(PF_A8R8G8B8,256x256x1) with hardware generated mipmaps from Image. Internal format is PF_A8R8G8B8,256x256x1.
21:14:32: Registering ResourceManager for type NxSCM
21:14:32: OGRE EXCEPTION(5:ItemIdentityException): Unable to derive resource group for robot.mesh automatically since the resource was not found. in ResourceGroupManager::findGroupContainingResource at ..\src\OgreResourceGroupManager.cpp (line 1366)


I think I included everything there is to be included, but how do I "tell" visual studio 8 where he is going to find the materials?

thank you

CaseyB

02-04-2007 20:27:46

You don't tell Visual Studio, you need to tell Ogre by editing the Resources.cfg file.

OgreNewbie123

02-04-2007 20:41:41

IT WORKS thank you very much. You will probably see me more asking questions these days, since I am moving from the tutorials stage, to creating something myself :D

CaseyB

02-04-2007 20:56:25

You will probably see me more asking questions these daysThat's what the forums are here for! ;)

OgreNewbie123

02-04-2007 20:57:11

New question: how do u work with lights in nxogre?
because

light = mSceneMgr->createLight( "Light3" );
light->setType( Light::LT_DIRECTIONAL );
light->setDiffuseColour( ColourValue( .25, .25, 0 ) );
light->setSpecularColour( ColourValue( .25, .25, 0 ) );


Does not work, it gives errors
Sorry, but I am very new to this.

I am also confuses about the classes, in Ogre there is a class for scene and framelistener etc and in nxogre there is only void start(). How can I use those classes from ogre in nxogre

OgreNewbie123

02-04-2007 20:59:25

Im sorry, it does work, I forgot

Light *light;

:D

But it would be fun if you explain the difference in classes/setup thing

CaseyB

02-04-2007 21:03:26

in Ogre there is a class for scene and framelistener etc and in nxogre there is only void start(). How can I use those classes from ogre in nxogreYou use them the same way that you would with in Ogre without NxOgre. NxOgre is just there to do the physics simulation, so you set up your scene and then start NxOgre, but you will still get frame events and everythin like you did before.

OgreNewbie123

02-04-2007 21:15:43

I tried this but it wont show the robot
I also tried to put the ogre code beneath void start() but I get the same result. It's just showing it like I didnt put ogre code. The build succeeded

#include "nxOgre.h"
#include "Ogre.h"
#include "tutorialApplication.h"

#include "ExampleApplication.h"

using namespace nxOgre;
using namespace Ogre;

class TutorialApplication : public ExampleApplication
{
protected:
public:
TutorialApplication()
{
}

~TutorialApplication()
{
}
protected:
void createScene(void)
{
mSceneMgr->setAmbientLight( ColourValue( 1, 1, 1 ) );

Entity *ent1 = mSceneMgr->createEntity( "Robot", "robot.mesh" );
SceneNode *node1 = mSceneMgr->getRootSceneNode()->createChildSceneNode( "RobotNode" );
node1->attachObject( ent1 );
//node1->scale(0.5, 1, 2 );

Entity *ent2 = mSceneMgr->createEntity( "Robot2", "robot.mesh" );
SceneNode *node2 = mSceneMgr->getRootSceneNode()->createChildSceneNode( "RobotNode2", Vector3( 50, 0, 0 ) );
node2->attachObject( ent2 );
node2->translate( Vector3( 50, 50, 50 ) );
}
};


class NxTutorial : public SimpleTutorial {

public:


world *mWorld;
scene *mScene;


body *myCube[3];

//////////////////////////////////////////////////////////////////////////////////////////////////

void start() {



mWorld = new world(mRoot);
mScene = mWorld->createScene("Main",mSceneMgr);



mScene->hasGravityAndFloor();

/*

Developer meet Static, Static meet developer.


Static bodies are bodies which never ever move, no matter how many cubes you
throw at it it won't budge, and gravity can't touch it.

Static bodies are created a little differently than regular bodies using it's
scenes createStaticBody method and that it has no mass.

In later tutorials you'll see how to use a meshShape which only works best
with static bodies to create full playable game levels.


*/
myCube[0] = mScene->createStaticBody("myStaticCube","cube.1m.mesh",new cubeShape(1.0f),Vector3(0,1.5,0));


/*

Dynamic bodies


You've met him before.


*/
myCube[1] = mScene->createBody("myDynamicCube","cube.1m.mesh",new cubeShape(1.0f),10.0f,Vector3(2,1.5,0));


/*

Kinematic bodies


*/

myCube[2] = mScene->createBody("myKinematicCube","cube.1m.mesh",new cubeShape(1.0f),10.0f,Vector3(4,1.5,0));
myCube[2]->setKinematic(true);


}

//////////////////////////////////////////////////////////////////////////////////////////////////

void stop() {
// Time to go, better tell NxOgre we are leaving.
delete mWorld;
}

//////////////////////////////////////////////////////////////////////////////////////////////////

void newFrame(float _time) {

if (targetBody == 0)
return;

if (isKeyDown(Z)) {
targetBody->addForce(Ogre::Vector3(0,0,150));
}

if (isKeyDown(NEG_Z)) {
targetBody->addForce(Ogre::Vector3(0,0,-150));
}

if (isKeyDown(X)) {
targetBody->addForce(Ogre::Vector3(150,0,0));
}

if (isKeyDown(NEG_X)) {
targetBody->addForce(Ogre::Vector3(-150,0,0));
}

if (isKeyDown(Y)) {
targetBody->addForce(Ogre::Vector3(0,150,0));
}

if (isKeyDown(NEG_Y)) {
targetBody->addForce(Ogre::Vector3(0,-150,0));
}
}

//////////////////////////////////////////////////////////////////////////////////////////////////

void getTutorialSettings() {
mTutorialName = "107";
mTutorialDescription = "Static and kinematic bodies";
timeSince = 0.0f;
}

//////////////////////////////////////////////////////////////////////////////////////////////////

void prestart() {}
void prestop() {}

//////////////////////////////////////////////////////////////////////////////////////////////////

};


TUTORIAL_VOIDMAIN;


So where do I need to put things correctly? Great chances that I just misunderstood you though :D

betajaen

02-04-2007 22:25:28

Seems like your mismatching the "TutorialApplication" and "ExampleApplication.h" together. They aren't really designed to work together; Infact TutorialApplication isn't being run at all. Try your Robot code in start, or prestart.


If your having trouble with some of the basics with Ogre, I would suggest you spend a few days with Ogre alone. Study how the ExampleApplication works and try to implement your own. Then you can work with NxOgre. Although NxOgre is designed to be easy, it does assume that you can write a small Ogre application in your sleep. :wink:

mikeInside

03-04-2007 13:25:13

I too only recently started moving from the "editing nxogre tutorials" level to integrating NxOgre stuff with Ogre's ExampleApplication framework.

Here was my first attempt; it has both lights and the ninja showing so I've included it here in case it helps you out. :)
(I'm using 0.4RC3 by the way)





#include "NxOgre.h"
using namespace nxOgre;
#include "Ogre.h"
using namespace Ogre;


#include "ExampleApplication.h"




/////////////////
// FRAMELISTENER
/////////////////


class TutorialFrameListener : public ExampleFrameListener
{
protected:
bool mMouseDown; // Whether or not the left mouse button was down last frame
Real mToggle; // The time left until next toggle
Real mRotate; // The rotate constant
Real mMove; // The movement constant
SceneManager *mSceneMgr; // The current SceneManager
SceneNode *mCamNode; // The SceneNode the camera is currently attached to

public:
TutorialFrameListener( RenderWindow* win, Camera* cam, SceneManager *sceneMgr )
: ExampleFrameListener(win, cam, false, false)
{
// key and mouse state tracking
mMouseDown = false;
mToggle = 0.0;

// Populate the camera and scene manager containers
mCamNode = cam->getParentSceneNode( )->getParentSceneNode( );
mSceneMgr = sceneMgr;

// set the rotation and move speed
mRotate = 0.13;
mMove = 30;
}


bool frameStarted(const FrameEvent &evt)
{
//return ExampleFrameListener::frameStarted( evt );

using namespace OIS;

mMouse->capture();
mKeyboard->capture();

if( mKeyboard->isKeyDown( KC_ESCAPE ) )
return false;




if ( mToggle >= 0.0f )
mToggle -= evt.timeSinceLastFrame;

if ( ( mToggle < 0.0f ) && mKeyboard->isKeyDown( KC_1 ) )
{
mToggle = 1.0f;
mCamera->getParentSceneNode()->detachObject( mCamera );
mCamNode = mSceneMgr->getSceneNode( "CamNode1" );
mSceneMgr->getSceneNode( "PitchNode1" )->attachObject( mCamera );
}
else if ( ( mToggle < 0.0f ) && mKeyboard->isKeyDown( KC_2 ) )
{
mToggle = 1.0f;

mCamera->getParentSceneNode()->detachObject( mCamera );
mCamNode = mSceneMgr->getSceneNode( "CamNode2" );
mSceneMgr->getSceneNode( "PitchNode2" )->attachObject( mCamera );
}

Real mMoveTemp = mMove;
if ( !(mKeyboard->isKeyDown( KC_LSHIFT ) || mKeyboard->isKeyDown( KC_RSHIFT )) )
mMoveTemp /= 3;

Vector3 transVector = Vector3::ZERO;
if ( mKeyboard->isKeyDown( KC_UP ) || mKeyboard->isKeyDown( KC_W ) )
transVector.z -= mMoveTemp;
if ( mKeyboard->isKeyDown( KC_DOWN ) || mKeyboard->isKeyDown( KC_S ) )
transVector.z += mMoveTemp;
if ( mKeyboard->isKeyDown( KC_LEFT ) || mKeyboard->isKeyDown( KC_A ) )
transVector.x -= mMoveTemp;
if ( mKeyboard->isKeyDown( KC_RIGHT ) || mKeyboard->isKeyDown( KC_D ) )
transVector.x += mMoveTemp;
if ( mKeyboard->isKeyDown( KC_PGUP ) || mKeyboard->isKeyDown( KC_Q ) )
transVector.y += mMoveTemp;
if ( mKeyboard->isKeyDown( KC_PGDOWN ) || mKeyboard->isKeyDown( KC_E ) )
transVector.y -= mMoveTemp;

//mCamNode->translate( mCamNode->getOrientation() *
// transVector * evt.timeSinceLastFrame );

mCamNode->translate( mCamNode->getOrientation() *
mCamNode->getChild( 0 )->getOrientation() *
transVector * evt.timeSinceLastFrame );


bool currMouse = mMouse->getMouseState().buttonDown( MB_Left );
if ( currMouse && ! mMouseDown )
{
Light *light = mSceneMgr->getLight( "Light1" );
light->setVisible( ! light->isVisible() );
} // if
mMouseDown = currMouse;

if ( !mMouse->getMouseState().buttonDown( MB_Right ) )
{
mCamNode->yaw( Degree(-mRotate * mMouse->getMouseState().X.rel) );
mCamNode->getChild( 0 )->pitch( Degree(-mRotate * mMouse->getMouseState().Y.rel) );
}

return true;
}
};




/////////////////
// APPLICATION
/////////////////


class NxApplication : public ExampleApplication
{
public:
NxApplication()
{
}

~NxApplication()
{
}
protected:
Ogre::StaticGeometry* sg;

void createCamera(void)
{
// create camera, but leave at default position
mCamera = mSceneMgr->createCamera("PlayerCam");
mCamera->setNearClipDistance(0.1);
}

void createScene(void)
{
SceneNode *node;

/////////////////
// WORLD
/////////////////

mSceneMgr->setAmbientLight( ColourValue( 0.1, 0.1, 0.1 ) );
mSceneMgr->setShadowTechnique( SHADOWTYPE_STENCIL_ADDITIVE );
// Create a skybox
mSceneMgr->setSkyDome( true, "Examples/CloudySky", 5, 8 );

world *mWorld = new world(mRoot);
scene* mScene = mWorld->createScene("Main",mSceneMgr);
mScene->hasGravityAndFloor();

sg = mSceneMgr->createStaticGeometry("grid");
CreateEntNode("nx.floor2", Vector3(0,-0.05,0));
CreateEntNode("nx.body.axis", Vector3(0,0,0));
sg->build();



/////////////////
// LIGHTS
/////////////////

Light *light = mSceneMgr->createLight( "Light1" );
light->setType( Light::LT_POINT );
light->setPosition( Vector3(50, 30, 50) );
light->setDiffuseColour( ColourValue( 0.3, 0.4, 0.6 ) );
light->setSpecularColour( ColourValue( 0.3, 0.4, 0.6 ) );
light->setVisible(false);

light = mSceneMgr->createLight( "PointLight" );
light->setType( Light::LT_POINT );
light->setPosition( Vector3(0, 50, -50) );//250) );
light->setDiffuseColour( 0.8, 0.9, 1.0 );
light->setSpecularColour( 0.3, 0.5, 1.0 );


/////////////////
// CAMERA
/////////////////

// Create the scene node
node = mSceneMgr->getRootSceneNode()->createChildSceneNode( "CamNode1", Vector3( -20, 15, 20 ) );
// Make it look towards the box
node->yaw( Degree(-45) );
// Create the pitch node
node = node->createChildSceneNode( "PitchNode1" );
node->attachObject( mCamera );
node->pitch( Degree(-15) );
// create the second camera node/pitch node
node = mSceneMgr->getRootSceneNode()->createChildSceneNode( "CamNode2", Vector3( 0, 10, 10 ) );
node = node->createChildSceneNode( "PitchNode2" );
node->pitch( Degree(-10) );


/////////////////
// ACTION
/////////////////

// random cube
body *cube = mScene->createBody(
"myCube",
"cube.1m.mesh",
new cubeShape(1.0f),
10.0f,
Vector3(0,10,0)
);

// Top Cubiod
cube = mScene->createBody(
"CubeBottom",
"cube.1m-2m-1m.mesh",
new cubeShape(Vector3(1,2,1)),
10.0f,
Vector3(5,2,0)
);
// Make it Kinematic, so it's movable but doesn't move on it's own.
//cube->setKinematic(true);
// The bottom cubiod.
cube = mScene->createBody(
"CubeTop",
"cube.1m-2m-1m.mesh",//"cube.1m-2m-1m.mesh",
new cubeShape(Vector3(1,2,1)),//new cubeShape(Vector3(1,2,1)),
10.0f,
Vector3(5,4,0)
);
cube->setAngularDamping(0.95f);
cube->setLinearDamping(0.95f);
cube->mActor->setMaxAngularVelocity(700);
//cube->setIgnoreGravity(true);


motorisedJoint *motor; // Notice a pointer, not the class itself.
float motorTarget;

// Create the Joint
motor = mScene->createMotorisedJoint(
mScene->findBody("CubeBottom"),
mScene->findBody("CubeTop"),
Vector3(5.5,3,0),
Vector3(0,0,-1),
false//true
);

motorTarget = 2.5;
//motor->setMaxForce
motor->setVelocityTarget(motorTarget);
motor->setMaxForce(100000);
motor->setFreeSpin(false);

// Ninja!
Entity *ent = mSceneMgr->createEntity( "Ninja", "ninja.mesh" );
node = mSceneMgr->getRootSceneNode()->createChildSceneNode( "NinjaNode" );
ent->setCastShadows( true );
node->attachObject( ent );
node->yaw( Degree( 145 ) );
node->translate( Vector3(20, 0, -20) );
node->scale( Vector3(0.05,0.05,0.05) );

}

void CreateEntNode(Ogre::String _name, Ogre::Vector3 _pos)
{
Entity *_entity = mSceneMgr->createEntity(_name + ".entity", _name + ".mesh");
_entity->setCastShadows(false);
sg->addEntity(_entity, _pos);
}

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

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






#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"

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

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

return 0;
}

OgreNewbie123

04-04-2007 14:04:35

Ok thanks a lot, I really understand now how things work when I looked at your code, but when i try to build your code in Nxogre I get an Error


Error 1 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup MSVCRT.lib


I have used the windows search and I cant find the MSVCRT.lib in ogre source nor in nxogre source

mikeInside

04-04-2007 18:19:52

Error 1 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup MSVCRT.lib

If you do a search on this forum for "MSVCRT.lib" you'll find quite a few results, perhaps they will help. If they don't and you'd like me to post my project settings just ask.

CaseyB

04-04-2007 18:36:43

Are you using main() or WinMain()? Is your project set up as a console project or a windows project?

DieHard

05-04-2007 00:15:16

Please tell me you know about setting up a project and you went through all the Ogre tutorials before getting into NxOgre (advanced level)? Or, understand how Ogre pass arguments through an order of methods and classes. Oh man, are you putting different pieces of code from different places and tying it quickly together to make an application?

You have to do this step-by-step (for starters, code one small feature and compile to see).

If it's all true, you need to take a step back away from addons (NxOgre). Please go through the tutorials and learn Ogre first fully before NxOgre:
http://www.ogre3d.org/wiki/index.php/Ogre_Tutorials

Basic Ogre Help Forum:
http://www.ogre3d.org/phpBB2/viewforum.php?f=10

OgreNewbie123

05-04-2007 14:35:16

I have managed to make a new project myself in ogre (partially done by the ogre wizard, but that didnt include everything) and I went through all the tutorials on the wiki, basic and intermediate.

I didnt produce code myself yet.
Cause I wanted something with physics, and I thought that I better started with it right away. So that I can see how it is done, and that it was possible to just simply add the physics code afterwards. (to basic ogre code that is).
I see that is possible. So now I am making things and experimenting in basic ogre first.

For quick nxogre testing purposes I used a project from the nxogre tutorial example for testing the nxogre code posted above.

And I didnt get any wiser on the search results from msvcrt, but for now I will first be experimenting in basic ogre

Thanks for the advices