A lil' help on physics pls!!!

Sercher_PL
Unregistered
 
Post: #1
I'm a noobie in the area of 'game' writing Grin not more then 2 weeks ago i started reading the nehe.gamedev.net tutorial on OpernGL. i just wanted to try myself on the 3d game programing Rolleyes and i ended up like this... Mad i cannot figure out a simple (not a full engin or sth) way to include simple (as i think it is) laws of physics to my 'game' .... if anyone coud look at the 'game' and help me ? its here http://www.toony.dolsat.pl/jakkolwiek/prog.zip and my problem(s) look more or less like this http://www.toony.dolsat.pl/Arek/Untitled-1%20copy.png (the key u can use are: 'spacebar' 'e' 'r' and 'esc', dont hit the 'a' 'd' 'q' 'w' i have forgotten to disable them Rasp )
Quote this message in a reply
Moderator
Posts: 698
Joined: 2002.04
Post: #2
Greets, this is Mac development forum so not many people here will be able to run your game; that aside, you might want to post the error-causing code to your game here - OpenGL is happily cross-platform, and somebody here should be able to help...

Mark Bishop
--
Student and freelance OS X & iOS developer
Quote this message in a reply
Sercher_PL
Unregistered
 
Post: #3
Sorry didnt know that this is Mac forum :|

there is no error-causing code in my game becouse i haven't added physics yet.... the problem is as shown on http://www.toony.dolsat.pl/jakkolwiek/screen.JPG
how should i write my prog to deal with the 'stairs' ? i want them to crash becous of the gravity... they should fall rotating and stuff, like in real world. i dont know how to write a function that will check if the 'pyramid' is about to crash. must i check all of boxes when i add new one (the one that is above the white line)? from which one shoud i start, the one that's on the top, or is there other sollution??
if anyone wants to see the code (i dont recommend that, it's all messed up there Rasp ) it's here http://www.toony.dolsat.pl/jakkolwiek/JP2pyramid.zip
big THX for those who will spend a lil' while helping me Smile
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #4
OK. This would require much collision detection/response, which is really hard. Believe me, I've taken two days trying to find how to do this, and It's pretty complex.

It's not magic, it's Ruby.
Quote this message in a reply
Moderator
Posts: 698
Joined: 2002.04
Post: #5
Whilst you wait for a good natured member of the forum to enlighten you further, you might want to try a quick search of the forum (maybe starting here) and the web; without knowing you coding/maths level, it's kinda hard for people to recommend where to look Huh

Quote:Sorry didnt know that this is Mac forum :|
No problem, most people here won't rip you apart for the mistake (although a board titled General Mac Programming might have given you a clue Wink)

Mark Bishop
--
Student and freelance OS X & iOS developer
Quote this message in a reply
Sercher_PL
Unregistered
 
Post: #6
sure i'm searching the forum Smile , but maby not the web (i done that for the last week - no results) and now there i see a ligt in a tunell.... ill try to know more about the collision tests (first time i've ever heard 'bout that Rasp ) and maby 'bout torque too (that word in english i hear 1st time Grin in my life Blush ), but there is hope... i hope there is Grin Rasp
Quote this message in a reply
Sercher_PL
Unregistered
 
Post: #7
u know what's funny.. i know a bit about classical and relativistic physics i know how to use the rules the eqations and stuff but i can't handle this Sneaky
http://www.toony.dolsat.pl/jakkolwiek/klocki.png
i dont know how much of the gravitation force (red arrows Rasp ) of the yellow "box" will affect the blue and the green one (examples 1 & 2). the same is with the examles 3 and 4. on 3 i think that oll of the gravity force of yellow box will affect the blue one but im not sure "where will it hit it" i assume that it'll be on the black dot Huh correct me if im wrong. anyway if anyone knows how these work, then could he/she add some force arrows to the image and post it here, or send the img to sercherpl@poczta.onet.pl
thx in advance

P.S. i know im a pain in the ass Wow but heh i have to make it work Grin
P.S. sorry for my not scientific vocabulary, i donot use such often Grin
Quote this message in a reply
Member
Posts: 304
Joined: 2002.04
Post: #8
unless you want to write this as a learning exercise why not use a physics SDK. Check out:

http://www.tokamakphysics.com/
http://ode.org/
http://www.novodex.com/

there are others - google around
Quote this message in a reply
Sercher_PL
Unregistered
 
Post: #9
hi again Rasp
thx codemattic 4 the sites - that's what i was looking 4.... i choosed the tokamak ('couse it was first on the list :] )

and now i have problems.... Rasp compiler doesn't show any errors but the app isnt working and it tell me that sth is wrong with GetBoxSize() function :/ can anyone look through those several lines of code, and tell me what is wrong? (it may occure that everything is Grin )

Code:
------ part of _interface.h -----------
class C_interface  
{
public:
    //Methods:
    void AddRigidBody(C_klocek & box);
        .....
        bool InitPhysics(void);
    void KillPhysics(void);
    //Tokamak variables:
    neSimulator *gSim;
    neRigidBody **gCubes;
    neAnimatedBody *gFloor;
        .....
}
----------------------------


bool C_interface::InitPhysics(void)
{
    neGeometry *geom;    // A Geometry object which used to define the shape/size of each cube
    neV3 boxSize1;        // A variable to store the length, width and height of the cube
    neV3 gravity;        // A vector to store the direction and intensity of gravity
    neV3 pos;            // The position of a cube
    neSimulatorSizeInfo sizeInfo;    // Stores data about how many objects we are going to model
    int i;
    float mass;

    sizeInfo.rigidBodiesCount = this->max;
    sizeInfo.animatedBodiesCount = 1;
    s32 totalBody = sizeInfo.rigidBodiesCount + sizeInfo.animatedBodiesCount;
    sizeInfo.geometriesCount = totalBody;
    sizeInfo.overlappedPairsCount = totalBody * (totalBody - 1) / 2;
    sizeInfo.rigidParticleCount = 0;
    sizeInfo.constraintsCount = 0;
    sizeInfo.terrainNodesStartCount = 0;
    gravity.Set(0.0f, -10.0f, 0.0f);
    this->gSim = neSimulator::CreateSimulator(sizeInfo, NULL, &gravity);
    this->gFloor = this->gSim->CreateAnimatedBody();
    geom = gFloor->AddGeometry();
    boxSize1.Set(40.0f , 0.2f, 40.0f);
    geom->SetBoxSize(boxSize1[0],boxSize1[1],boxSize1[2]);
    gFloor->UpdateBoundingInfo();
    pos.Set(0.0f, -3.5f, -10.0f);
    gFloor->SetPos(pos);

    for (i=0;i<this->max;i++)
    {
        gCubes[i] = gSim->CreateRigidBody();
        geom = gCubes[i]->AddGeometry();
        boxSize1.Set(1.0f, 1.0f, 1.0f);
        geom->SetBoxSize(boxSize1[0], boxSize1[1], boxSize1[2]);
        gCubes[i]->UpdateBoundingInfo();
        mass = 1.0f;
        gCubes[i]->SetInertiaTensor(neBoxInertiaTensor(boxSize1[0], boxSize1[1], boxSize1[2], mass));
        gCubes[i]->SetMass(mass);
        pos.Set(0.0f, -30.0f-i*3.0f, 0.0f);
        gCubes[i]->SetPos(pos);
    }
    return true;
}

void C_interface::KillPhysics(void)
{
    if (this->gSim)
    {
        neSimulator :: DestroySimulator(this->gSim);
        this->gSim = NULL;
    }
}

void C_interface::AddRigidBody(C_klocek & box)
{
    neGeometry *geom;    // A Geometry object which used to define the shape/size of each cube
    C_pozycja klocek = this->obecny->retpar();
    neV3 boxSize1;        // A variable to store the length, width and height of the cube
    f32 mass;            // The mass of our cubes
    neV3 pos;            // The position of a cube

    float tmpwys;
    if ((int)klocek.rotz%180)
    {
        tmpwys=klocek.wys;
        klocek.wys=klocek.sze;
        klocek.sze=tmpwys;
    }


    if (this->ilosc<this->max)
    {
        geom = this->gCubes[this->ilosc]->GetNextGeometry();
        boxSize1.Set(klocek.sze, klocek.wys, klocek.gl);
        geom->SetBoxSize(boxSize1[0], boxSize1[1], boxSize1[2]);
        this->gCubes[this->ilosc]->UpdateBoundingInfo();
        mass = klocek.sze*klocek.wys*klocek.gl;
        this->gCubes[this->ilosc]->SetInertiaTensor(neBoxInertiaTensor(boxSize1[0], boxSize1[1], boxSize1[2], mass));
        this->gCubes[this->ilosc]->SetMass(mass);
        pos.Set(klocek.x, klocek.y, klocek.z);
        gCubes[ilosc]->SetPos(pos);
        this->ilosc++;
    }
}


------------ from the globals
int DrawGLScene(C_interface & _gra,int max,GLuint * tex)         // Here's where we do all the drawing
{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    // Clear screen and depth buffer
    glLoadIdentity();       // Reset the current modelview matrix
    
    _gra.controls(tex);

    if (!_gra.lsb && !game)
    {
        _gra.objmovement();
    }

    GetETime(time1,fElapsed);

    if (fLastElapsed != 0)
    {
        if (fElapsed > fLastElapsed * 1.2f) fElapsed = fLastElapsed * 1.2f;
        if (fElapsed < fLastElapsed * 0.8f) fElapsed = fLastElapsed * 0.8f;
    }
    if (fElapsed > 1.0f / 45.0f) fElapsed = 1.0f / 45.0f;
    fLastElapsed = fElapsed;

    _gra.gSim->Advance(fElapsed);

    neT3 t;           

    glPushMatrix();      

    t = _gra.gFloor->GetTransform();    

    float mat[16] =
        {
        t.rot[0][0], t.rot[0][1], t.rot[0][2], 0.0f,
        t.rot[1][0], t.rot[1][1], t.rot[1][2], 0.0f,
        t.rot[2][0], t.rot[2][1], t.rot[2][2], 0.0f,
        t.pos[0],    t.pos[1],    t.pos[2],    1.0f
        };

    glMultMatrixf (mat);

    neGeometry * geom;
    neV3 boxsize,pos;

    geom= _gra.gFloor->GetNextGeometry();
    geom->GetBoxSize(boxsize);
    pos = _gra.gFloor->GetPos();

    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texture[2]);
    glBegin(GL_QUADS);                    //
        //sciana frontowa                //
          glVertex3f(-boxsize[0]/2.0f,-boxsize[1]/2.0f, boxsize[2]/2.0f);    //
        glVertex3f(-boxsize[0]/2.0f, boxsize[1]/2.0f, boxsize[2]/2.0f);    //
        glVertex3f( boxsize[0]/2.0f, boxsize[1]/2.0f, boxsize[2]/2.0f);    //
        glVertex3f( boxsize[0]/2.0f,-boxsize[1]/2.0f, boxsize[2]/2.0f);    //
        //sciana gorna                //
          glTexCoord2f(0.0f, 0.0f); glVertex3f(-boxsize[0]/2.0f, boxsize[1]/2.0f, boxsize[2]/2.0f);    //
        glTexCoord2f(0.0f, 1.0f); glVertex3f(-boxsize[0]/2.0f, boxsize[1]/2.0f,-boxsize[2]/2.0f);    //
        glTexCoord2f(1.0f, 1.0f); glVertex3f( boxsize[0]/2.0f, boxsize[1]/2.0f,-boxsize[2]/2.0f);    //
        glTexCoord2f(1.0f, 0.0f); glVertex3f( boxsize[0]/2.0f, boxsize[1]/2.0f, boxsize[2]/2.0f);    //
        //sciana dolna                //
          glVertex3f(-boxsize[0]/2.0f,-boxsize[1]/2.0f, boxsize[2]/2.0f);    //
        glVertex3f( boxsize[0]/2.0f,-boxsize[1]/2.0f, boxsize[2]/2.0f);    //
        glVertex3f( boxsize[0]/2.0f,-boxsize[1]/2.0f,-boxsize[2]/2.0f);    //
        glVertex3f(-boxsize[0]/2.0f,-boxsize[1]/2.0f,-boxsize[2]/2.0f);    //
        //sciana lewa                //
          glVertex3f(-boxsize[0]/2.0f, boxsize[1]/2.0f, boxsize[2]/2.0f);    //
        glVertex3f(-boxsize[0]/2.0f,-boxsize[1]/2.0f, boxsize[2]/2.0f);    //
        glVertex3f(-boxsize[0]/2.0f,-boxsize[1]/2.0f,-boxsize[2]/2.0f);    //
        glVertex3f(-boxsize[0]/2.0f, boxsize[1]/2.0f,-boxsize[2]/2.0f);    //
        //sciana prawa                //
          glVertex3f( boxsize[0]/2.0f,-boxsize[1]/2.0f, boxsize[2]/2.0f);    //
        glVertex3f( boxsize[0]/2.0f, boxsize[1]/2.0f, boxsize[2]/2.0f);    //
        glVertex3f( boxsize[0]/2.0f, boxsize[1]/2.0f,-boxsize[2]/2.0f);    //
        glVertex3f( boxsize[0]/2.0f,-boxsize[1]/2.0f,-boxsize[2]/2.0f);    //
        //sciana tylna                //
          glVertex3f(-boxsize[0]/2.0f,-boxsize[1]/2.0f,-boxsize[2]/2.0f);    //
        glVertex3f( boxsize[0]/2.0f,-boxsize[1]/2.0f,-boxsize[2]/2.0f);    //
        glVertex3f( boxsize[0]/2.0f, boxsize[1]/2.0f,-boxsize[2]/2.0f);    //
        glVertex3f(-boxsize[0]/2.0f, boxsize[1]/2.0f,-boxsize[2]/2.0f);    //
    glEnd();
            
    for (int j=0; j<_gra.ilosc;j++)
    {
        geom=_gra.gCubes[j]->GetNextGeometry();
        geom->GetBoxSize(boxsize);
        
        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, texture[0]);
        glBegin(GL_QUADS);                    //
            //sciana frontowa
            glNormal3f( 0.0f, 0.0f, 1.0f);                    // Normal Pointing Towards Viewer
            glTexCoord2f(0.0f, 0.0f); glVertex3f(-boxsize[0]/2,-boxsize[1]/2,boxsize[2]/2);                        
            glTexCoord2f(0.0f, 1.0f); glVertex3f(-boxsize[0]/2,boxsize[1]/2,boxsize[2]/2);
            glTexCoord2f(1.0f, 1.0f); glVertex3f(boxsize[0]/2,boxsize[1]/2,boxsize[2]/2);
            glTexCoord2f(1.0f, 0.0f); glVertex3f(boxsize[0]/2,-boxsize[1]/2,boxsize[2]/2);
            //sciana lewa
            glNormal3f(-1.0f, 0.0f, 0.0f);                    // Normal Pointing Left
            glTexCoord2f(0.0f, 0.0f); glVertex3f(-boxsize[0]/2,-boxsize[1]/2,boxsize[2]/2);
            glTexCoord2f(0.0f, 1.0f); glVertex3f(-boxsize[0]/2,-boxsize[1]/2,-boxsize[2]/2);
            glTexCoord2f(1.0f, 1.0f); glVertex3f(-boxsize[0]/2,boxsize[1]/2,-boxsize[2]/2);
            glTexCoord2f(1.0f, 0.0f); glVertex3f(-boxsize[0]/2,boxsize[1]/2,boxsize[2]/2);
            //sciana gorna
            glNormal3f( 0.0f, 1.0f, 0.0f);                    // Normal Pointing Up
            glTexCoord2f(1.0f, 0.0f); glVertex3f(-boxsize[0]/2,boxsize[1]/2,boxsize[2]/2);
            glTexCoord2f(1.0f, 1.0f); glVertex3f(-boxsize[0]/2,boxsize[1]/2,-boxsize[2]/2);
            glTexCoord2f(0.0f, 1.0f); glVertex3f(boxsize[0]/2,boxsize[1]/2,-boxsize[2]/2);
            glTexCoord2f(0.0f, 0.0f); glVertex3f(boxsize[0]/2,boxsize[1]/2,boxsize[2]/2);
            //sciana prawa
            glNormal3f( 1.0f, 0.0f, 0.0f);                    // Normal Pointing Right
            glTexCoord2f(0.0f, 0.0f); glVertex3f(boxsize[0]/2,boxsize[1]/2,boxsize[2]/2);
            glTexCoord2f(0.0f, 1.0f); glVertex3f(boxsize[0]/2,boxsize[1]/2,-boxsize[2]/2);
            glTexCoord2f(1.0f, 1.0f); glVertex3f(boxsize[0]/2,-boxsize[1]/2,-boxsize[2]/2);
            glTexCoord2f(1.0f, 0.0f); glVertex3f(boxsize[0]/2,-boxsize[1]/2,boxsize[2]/2);
            //sciana dolna
            glNormal3f( 0.0f,-1.0f, 0.0f);                    // Normal Pointing Down
            glTexCoord2f(1.0f, 0.0f); glVertex3f(boxsize[0]/2,-boxsize[1]/2,boxsize[2]/2);
            glTexCoord2f(1.0f, 1.0f); glVertex3f(boxsize[0]/2,-boxsize[1]/2,-boxsize[2]/2);
            glTexCoord2f(0.0f, 1.0f); glVertex3f(-boxsize[0]/2,-boxsize[1]/2,-boxsize[2]/2);
            glTexCoord2f(0.0f, 0.0f); glVertex3f(-boxsize[0]/2,-boxsize[1]/2,boxsize[2]/2);
            //sciana tylnia
            glNormal3f( 0.0f, 0.0f,-1.0f);                    // Normal Pointing Away From Viewer
            glTexCoord2f(1.0f, 0.0f); glVertex3f(-boxsize[0]/2,-boxsize[1]/2,-boxsize[2]/2);
            glTexCoord2f(1.0f, 1.0f); glVertex3f(boxsize[0]/2,-boxsize[1]/2,-boxsize[2]/2);
            glTexCoord2f(0.0f, 1.0f); glVertex3f(boxsize[0]/2,boxsize[1]/2,-boxsize[2]/2);
            glTexCoord2f(0.0f, 0.0f); glVertex3f(-boxsize[0]/2,boxsize[1]/2,-boxsize[2]/2);
        glEnd();
    }
    glPopMatrix();
    
    
    //----------------- scy ------------------//
    glEnable(GL_TEXTURE_2D);                    //
    glLoadIdentity();                            //
    glBindTexture(GL_TEXTURE_2D, texture[1]);    //
    glTranslatef(0.0f,-3.4f,-10.0f);            //
    glRotatef(90.0f,1.0f,0.0f,0.0f);            //
    glRotatef(rots,0.0f,0.0f,1.0f);                //
    gluSphere(quadratic,20.0f,32,32);            //
    //------------------------------------------//

    if (game)
    {
        glDisable(GL_TEXTURE_2D);
        glLoadIdentity();
        glTranslatef(0.0f,0.0f,-1.0f);                
        glColor3f(0.0f,0.0f,1.0f);
        glRasterPos2f(-0.2f,0.0f);
        glPrint("Game Over");
        glLoadIdentity();
        glTranslatef(0.0f,0.0f,-1.0f);
        glRasterPos2f(-0.17f,-0.08f);
        glPrint("Boxes %d",_gra.ilosc);
    }

    rots+=0.05f;
    return true;                            // Done drawing the quad
}


-------------- finito


big SORRY for spamming my code here but i don't know what is wrong.... if enyone if familiar to Tokamak and OpenGL enought to help me i would be more than grateful Grin
Quote this message in a reply
Sercher_PL
Unregistered
 
Post: #10
nvm my prev. post.... Grin i was sitting infront of my screen from 5 pm. to like now 4 am reading countless number of codes, forum posts and tutorials ... and i'm close to finish this exercise of mine Grin the openGL code's working (need little corrects Rasp) physics working (the Tokamak). it was hard due to low number of any tutorials wrote for Tokamak on OpenGL (not glut) Sad thats iritating Rasp but somehow i menaged to figure out how it works Grin ... thx to anyone who helped me, and those who wanted to, but haven't had enough luck to visit this thread Rasp ... i'll notice u when i'll finish the code Grin and it will be "bug free" Rasp, then u will be able to take a glance at a poore work of mine Rasp (ofcourse most of u will have to buy a PC and instal WinDors...ows Rasp ) have a good night to me ... at last Grin
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #11
Sercher_PL Wrote:nvm my prev. post.... Grin i was sitting infront of my screen from 5 pm. to like now 4 am reading countless number of codes, forum posts and tutorials ... and i'm close to finish this exercise of mine Grin the openGL code's working (need little corrects Rasp) physics working (the Tokamak). it was hard due to low number of any tutorials wrote for Tokamak on OpenGL (not glut) Sad thats iritating Rasp but somehow i menaged to figure out how it works Grin ... thx to anyone who helped me, and those who wanted to, but haven't had enough luck to visit this thread Rasp ... i'll notice u when i'll finish the code Grin and it will be "bug free" Rasp, then u will be able to take a glance at a poore work of mine Rasp (ofcourse most of u will have to buy a PC and instal WinDors...ows Rasp ) have a good night to me ... at last Grin
This is completely off topic, but I'm only going to say this once: Please try to write like you are older than 12 years old. It'll SERIOUSLY help people understand you
Quote this message in a reply
Member
Posts: 304
Joined: 2002.04
Post: #12
glad you got up and running. Post links if possible to what you create for those of us with PCs - and links to screenshots for those of us without.

FYI - there is a tokamak specific forum at http://www.tokamakphysics.com/guideline.htm where you may find people more helpful with the physics questions. And an email list by sending to tokamak-forum-subscribe@tokamakphysics.com.

Quote:thx codemattic 4 the sites - that's what i was looking 4.... i choosed the tokamak ('couse it was first on the list :] )
yeah - well - not the *greatest* way to choose between SDKs... but it looks like you are doing ok with it!
Quote this message in a reply
Sercher_PL
Unregistered
 
Post: #13
codemattic Wrote:Post links if possible to what you create for those of us with PCs - and links to screenshots for those of us without.
Sure. I'll do that immediately after the work is done Grin

codemattic Wrote:...there is a tokamak specific forum...
i know Rolleyes

codemattic Wrote:yeah - well - not the *greatest* way to choose between SDKs... but it looks like you are doing ok with it!
I liked the name *Tokamak* too!! Rasp

And the last thing:

skyhawk Wrote:This is completely off topic, but I'm only going to say this once: Please try to write like you are older than 12 years old. It'll SERIOUSLY help people understand you
This is completly off topic, but I'm only going to say this once: I'll be writing whatever and in any way i want. If U dont like it, keep it to yourself and don't post here. This topic is over. Ninja
Quote this message in a reply
Moderator
Posts: 698
Joined: 2002.04
Post: #14
Sercher_PL, I'd suggest you read points 11, 4, and 9 (in that order) of this; it would reflect well on you to keep the the 'signal - noise' ratio of your posts high - people on this forum typically frown on post-whoring.

Mark Bishop
--
Student and freelance OS X & iOS developer
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #15
Quote:This is completly off topic, but I'm only going to say this once: I'll be writing whatever and in any way i want. If U dont like it, keep it to yourself and don't post here. This topic is over.
Actually, this forum doesn't belong to you. We're very picky about writing. Wink That said, Skyhawk could've worded it a bit better, but in essence, he's right. Smile I realize that English isn't your first language, but you proved you can do it good.

In essence, we're really, really bitchy here, but it's a nice forum and we like to keep it that way.

Back onto topic, glad you fixed it. We're waiting for those screenshots. Wink
Quote this message in a reply
Post Reply