OgreNewt - Newton makes friends with Ogre

Share with us how are you using the powerrrr of the force

Moderator: Alain

Postby kjelle69 » Sat Aug 13, 2005 6:38 am

Yes, the loop thing is the doing-fast-and-simple things in basic that still is occupying a lot of space in my brain :roll:

Well, I would really appreciate to see how you construct a body iterator in ON. I have played around with your conveyor app , and I would like to either know when the spheres are too low (Or hitting the ground) if that is the case I want to 'kill' them or move them up to the starting position to increase the load of the conveyor.

Image
User avatar
kjelle69
 
Posts: 60
Joined: Fri Aug 27, 2004 9:08 am
Location: Koskullskulle, Sweden

Postby walaber » Sat Aug 13, 2005 10:31 am

to make a body iterator, make a function that accepts a single argument of a n OgreNewt::Body* , and then use my BodyIterator class to call it. something like this:

(imagine you added this code to your application frame listener (make sure it is a "static" function)
Code: Select all
void OgreNewtFrameListener::myIterator( OgreNewt::Body* body )
{
     // do something on the body here
}


then, you can apply it like this:
Code: Select all
OgreNewt::BodyIterator::getSingleton().init( mWorld );
OgreNewt::BodyIterator::getSingleton().go( OgreNewtFrameListener::myIterator );


that will cause the function to be called for every rigid body in the world. in your case you would want to check if the mass > 0, and then do a position check.


alternatively, you could create your own Transform callback for the balls (where the Ogre SceneNode gets placed according to the newton data, and run the check inside there, and possibly reset the object there).

another option would be to make a callback for collision between the balls and the ground body material, and reset the bodies when they hit the ground.
Independent game developer of (mostly) physics-based games. Creator of "JellyCar" and lead designer of "Where's My Water?"
User avatar
walaber
Moderator
Moderator
 
Posts: 393
Joined: Wed Mar 17, 2004 3:40 am
Location: California, USA

Postby kjelle69 » Sat Aug 13, 2005 11:05 am

I am really lacking some basic c++ knowledge here:

error C2039: 'myIterator' : is not a member of 'OgreNewtonFrameListener'

I Put this code in the OgreNewtonFrameListener.cpp

Code: Select all
static void OgreNewtonFrameListener::myIterator( OgreNewt::Body* body )
{
   Ogre::Quaternion bodorient;
    Ogre::Vector3 bodpos;
    body->getPositionOrientation( bodorient, bodpos );
    if (bodpos.y < -4.0f)
    {
        body->setPositionOrientation( Ogre::Quaternion(Ogre::Quaternion::IDENTITY), Ogre::Vector3(-3,3.5,0) );   
    }
 
}


and those in the bool OgreNewtonFrameListener::frameStarted(const FrameEvent &evt) function:

Code: Select all
OgreNewt::BodyIterator::getSingleton().init( mWorld );
   OgreNewt::BodyIterator::getSingleton().go( OgreNewtonFrameListener::myIterator );


error C2039: 'init' : is not a member of 'OgreNewt::BodyIterator'
error C2065: 'mWorld' : undeclared identifier


I understand the basics you describe, to each time I call the Bodyiterator which you have as a function in ON it cycles through every body in the newton world, if the specific body has mass and is below a certain point I execute some kind of action on it. eg. move it or something.

I have to try some more, everything is not so straight forward with c++ it seems, for example I made a check to disable the debug info on the screen, it works regardless if I use the OO description of KC_F eg. Ogre::KC_F or as stated in the following code, so I guess that problems are solvable in a lot of different ways with c++... hope I dont bore out you experts with silly questions... :P

Code: Select all
if (mInputDevice->isKeyDown(KC_F) && mTimeUntilNextToggle <= 0)
        {
            mStatsOn = !mStatsOn;
            showDebugOverlay(mStatsOn);

            mTimeUntilNextToggle = 1;
        }



I also see that you have a headerfile which name is BodyIterator.h but you dont have and cpp file with that name in your package. Maybe not needed ?
User avatar
kjelle69
 
Posts: 60
Joined: Fri Aug 27, 2004 9:08 am
Location: Koskullskulle, Sweden

Postby walaber » Sat Aug 13, 2005 3:14 pm

make sure you declare the myIterator() function in the FrameListener header (.h) file. also, the "OgreNewtonFrameListener" part should be replaced with the name of your particular Ogre frame listener class.

have to try some more, everything is not so straight forward with c++ it seems, for example I made a check to disable the debug info on the screen, it works regardless if I use the OO description of KC_F eg. Ogre::KC_F or as stated in the following code, so I guess that problems are solvable in a lot of different ways with c++... hope I dont bore out you experts with silly questions...


you only need the "Ogre::" if there is apossibility that another class or namespace in your project also has something named "KC_F". if there is no others, the compiler will find it inside "Ogre", and assume you want it.
Independent game developer of (mostly) physics-based games. Creator of "JellyCar" and lead designer of "Where's My Water?"
User avatar
walaber
Moderator
Moderator
 
Posts: 393
Joined: Wed Mar 17, 2004 3:40 am
Location: California, USA

Postby kjelle69 » Sun Aug 14, 2005 1:29 pm

Almost there, i think. I get two errors with this code:

Code: Select all
OgreNewt::BodyIterator::getSingleton().init( m_World );
   OgreNewt::BodyIterator::getSingleton().go( OgreNewtonFrameListener::myIterator );


error C2039: 'init' : is not a member of 'OgreNewt::BodyIterator'

error C2664: 'OgreNewt::BodyIterator::go' : cannot convert parameter 1 from 'void (OgreNewt::Body *)' to 'OgreNewt::BodyIterator::IteratorCallback'
Is the Bodyiterator.cpp missing from the ON package?

I have declared the function like this in the newtonframelistener.h

Code: Select all
public:
   OgreNewtonFrameListener(RenderWindow* win, Camera* cam, SceneManager* mgr, OgreNewt::World* W, SceneNode* ncam);
   ~OgreNewtonFrameListener(void);

   bool frameStarted(const FrameEvent &evt);
   void myIterator(OgreNewt::Body* body );
Last edited by kjelle69 on Sun Aug 14, 2005 1:38 pm, edited 3 times in total.
User avatar
kjelle69
 
Posts: 60
Joined: Fri Aug 27, 2004 9:08 am
Location: Koskullskulle, Sweden

Postby kjelle69 » Sun Aug 14, 2005 1:30 pm

Ok, one error left. init should be Init (Capital I)

Also something that seems abnormously wierd for me is that you declare the OgreNewtonApplication with a 'not' ? Is it a not-class ?

Code: Select all
OgreNewtonApplication(void);
~OgreNewtonApplication(void);
User avatar
kjelle69
 
Posts: 60
Joined: Fri Aug 27, 2004 9:08 am
Location: Koskullskulle, Sweden

Postby walaber » Sun Aug 14, 2005 3:50 pm

the linking error is because you need to make your body iterator a "static" function. in your header file, change the definition from:
Code: Select all
void myIterator(OgreNewt::Body* body );

to:
Code: Select all
static void myIterator(OgreNewt::Body* body );

this means that no matter how many copies of the class you make, only 1 copy of this function will ever exist. this is a requirement for the function pointers that are used.

also I'm not sure I understand your question here:
Also something that seems abnormously wierd for me is that you declare the OgreNewtonApplication with a 'not' ? Is it a not-class ?

from the code you posted I think you mean the "constructor" and "destructor". these are 2 special functions that will be called when an object of that class is created. for example, say you had a class like this:
Code: Select all
Class MyClass
{
public:
   void doSomething();
private:
   int myVariable;
};

and you want to initialize the "myVariable" to "3" anytime you use a "MyClass". you would add a "constructor" like this:
header file
Code: Select all
class MyClass
{
public:
   MyClass();
   void doSomething();
private:
   int myVariable;
};

source file
Code: Select all
#include "MyClass.h"

MyClass::MyClass()
{
   myVariable = 3;
}

then, in your game or whatever, if you do this:
Code: Select all
MyClass test;
test.doSomething();

on that first line, the object of type "MyClass" is created, and the "constructor" is called, where the internal variables are setup, or anything else you want to do.
similar to the "constructor" is the "Destructor", which is called when the object is destroyed, and is defined with a "~", like in the code above.
if you want to learn more C++, I HIGHLY recommend the book below, it's entirely free over the internet, and is really well written.

Thinking in C++ (volume 1 and 2)
http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html
or in PDF format here:
http://www.planetpdf.com/developer/article.asp?ContentID=6634
Independent game developer of (mostly) physics-based games. Creator of "JellyCar" and lead designer of "Where's My Water?"
User avatar
walaber
Moderator
Moderator
 
Posts: 393
Joined: Wed Mar 17, 2004 3:40 am
Location: California, USA

Postby kjelle69 » Thu Aug 18, 2005 9:33 am

Yes ! At last, got it to work as I wanted !

( I have downloaded the books too) :P Must dig deeper in the Polymorphic thinking !


Image
User avatar
kjelle69
 
Posts: 60
Joined: Fri Aug 27, 2004 9:08 am
Location: Koskullskulle, Sweden

Postby kjelle69 » Sat Aug 27, 2005 12:19 pm

I think I have understood the code, I have played around a bit with the code and added some functionality with the help Of Walaber. Thanks !
The Executables can be downloaded at
http://mtec.hostname.nu/projects.htm
User avatar
kjelle69
 
Posts: 60
Joined: Fri Aug 27, 2004 9:08 am
Location: Koskullskulle, Sweden

Postby Julio Jerez » Sun Aug 28, 2005 7:13 am

wow this is very impresive. I went to your website and I checked out the video of the Mill, very impresive stuff. How fast that thing runs? and how many balls are you melting?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Postby kjelle69 » Sun Aug 28, 2005 7:51 am

I have 501 balls in that simulation, it took about 10 minutes to render on a pentium 2.8. I can run it with a lot of more balls but then the risk for crashes increases as the probability for more then 500 collisions occur. It will be very interesting to try it with 1.35 with the increased stack !

:D
User avatar
kjelle69
 
Posts: 60
Joined: Fri Aug 27, 2004 9:08 am
Location: Koskullskulle, Sweden

Postby walaber » Tue Jan 10, 2006 4:03 am

NEW VERSION RELEASED

A new version of OgreNewt that works with version 1.5 of Newton has been released, which also sees full documentation for the library, and many more improvement. DL is on my homepage!
Independent game developer of (mostly) physics-based games. Creator of "JellyCar" and lead designer of "Where's My Water?"
User avatar
walaber
Moderator
Moderator
 
Posts: 393
Joined: Wed Mar 17, 2004 3:40 am
Location: California, USA

Postby Antoxa2 » Tue Aug 08, 2006 2:39 pm

Please Help! Pleas any body, send on my mail Arhive with OgreNewt.
becouse a can't open walaber.com! - i think site is broken.

toxainchrist@bk.ru

sorry for my bad english. Anton.
Antoxa2
 
Posts: 1
Joined: Tue Aug 08, 2006 2:27 pm

Previous

Return to User Gallery

Who is online

Users browsing this forum: No registered users and 5 guests

cron