Hello Wolrd

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Sparks
Posts: 19
Joined: Thu Oct 21, 2004 1:30 am
Location: Montreal

Hello Wolrd

Post by Sparks »

Hi guys,

Well i'm new, so i tough i would give a shout out to everyone. I'm a french Canadian Software engineering student, I mostly programme with JAVA, but it feels good to Play around with C++ and Irrlicht.

I've started playing around with Irrlicht, and i'm very impressed. So I started writting a little game. I dont have much done just a few classes.

I seem to have lots of questions, A.I., Physics, and the generals mechanics of Irrlicht that I cant seem to find answer for on the site. References are welcome.

My main question is, how does Irrlicht handles time? I dont know if you understand the question :) let'S say, I do a while device->run and a drawall, but let's say i want to put gravity (-9.81 meters2/second), i need an acceleration wich is (speed variation) / Time.

any help is welcome. I will probably have plenty more of question.

For those interested my project game, is a sport game. i'm currently working on the team, player, field and ball classes. I dont have any models so i cant really show screenshots :(
XL Game Development
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

for that you'll need to integrate a physics engine like newton, ode or tokamak. Irrlicht only includes basic collision detection, no gravity alternatives.


there r some tuts on using an external physics engine with irrlicht in the tutorials page.
Image
Ronin
Posts: 116
Joined: Wed Mar 03, 2004 6:23 pm
Location: Germany

Post by Ronin »

You can get time in milliseconds by calling IrrlichtDevice::getTimer()::getTime(), then you can multiply acceleration by the time that passed since last frame got rendered.

What sport will your game be about?
Guest

Post by Guest »

ok, " IrrlichtDevice::getTimer()::getTime()" that's good. i did not know that.
now the question is how do i get to know how much time passed since the last render, since according to me the rendering is done in the while device->run.... maybe there is a method to find out the time of the rendering.

Most of my questions for now mostly go around understanding the rendering, how does it work, when is it performed, i'm guessing the rendering is done with the draw all methods... anyway, again answers or references to site are more than welcome

Thanks
Ronin
Posts: 116
Joined: Wed Mar 03, 2004 6:23 pm
Location: Germany

Post by Ronin »

Rendering is done between BeginScene() and EndScene(), as you mentioned, by calling ISceneManager::drawAll() for rendering 3D Objects and IGUIEnvironment::drawAll() for your 2D GUI Objects.

To get the time when last frame was rendered, you have to save the value you got from the timer and compare it to the time of next frame. The difference between them is the time of one frame.
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

Or for a quick hack ( no telling exactly how accurate it is ) divide 1 by the frames per second, I can't remember if the FPS gives a float value or literally counts the number of frames that pass in a second, if it's the latter then there isn't much point doing what I said as it won't be accurate enough, if it is the former then you will have an accurate reading.
Sparks
Posts: 19
Joined: Thu Oct 21, 2004 1:30 am
Location: Montreal

Post by Sparks »

Well, I have decided to post in the beginner section, because I have the programming skills but little knowledge of the API.

Anyway, I started with some hardcore stuff mouvement and colision detection. answers are pretty rare, maybe it's because i'm talking about stuff that's very easy for some. But for a starter it's hard :)

Go check out the thread in the beginner section on mouvement and collision detection help is always welcome.

The Idea for mouvment is to code a small physics engine working on the good old F=MA. Dont know if F=MA exist in english I guess so... maybe with other letters I dont know..

The next problem to solve is generating event for collision detection. but there is a method that use a line so i'm thinking of making a line simulating the mouvement and trying to generate the collision before it happens....
XL Game Development
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

You can't detect collision before it actualy happen. What you normaly do is to store position of your object, make your move, check for collision, if it happened place your object back at old position. Thats the most simple method. It for example don't alowe you to slide.

As for time of one loop, here is class I made for my project to asure I get time passed between loops:

Code: Select all

/*-----------------------------------------------------------------------------*
| headerfile MTimer.h                                                          |
|                                                                              |
| version 1.1                                                                  |
| date: (23.10.2004)                                                           |
|                                                                              |
| author:  Michal Švantner                                                     |
|                                                                              |
| contain class for geting time and calculating looptime                       |
| require Irrlicht v.0.7.1 engine                                              |
*-----------------------------------------------------------------------------*/

//--- GUARDIAN OF INCLUSION ----------------------------------------------------
#ifndef MTimer_H
#define MTimer_H

//--- INCLUDED FILES -----------------------------------------------------------
#include <irrlicht.h>

class MTimer
{
public:
    //--- CONSTRUCTOR ---
    MTimer(irr::IrrlichtDevice *device)
    {
        timer = device->getTimer(); //get timer from Irrlicht
        time = timer->getTime();
        oldtime = time;
        looptime = 1;
        loopnum = 1;
    }
    
    //--- DESTRUCTOR ---
    ~MTimer(){}
    
    //--- CONTROL, should be called each loop ---
    void control()
    {
        time = timer->getTime();
        
        irr::u32 diference = time - oldtime;
        
        if(diference == 0)
        {
            loopnum += 1;
        }
        else
        {
            looptime = ((irr::f32)diference) / loopnum;
            loopnum = 1;
            oldtime = time;
        }
    }
    
    //--- GET TIME OF ONE LOOP IN MILISECONDS ---
    irr::f32 getLoopTimeMil()
    {
        return looptime;
    }
    
    //--- GET TIME OF ONE LOOP IN SECONDS ---
    irr::f32 getLoopTimeSec()
    {
        return looptime / 1000;
    }
    
    //--- GET CURRENT TIME IN MILISECONDS ---
    irr::u32 getTimeMil()
    {
        return time;
    }
    
    //--- GET CURRENT TIME IN SECONDS ---
    irr::u32 getTimeSec()
    {
        return time / 1000;
    }
    
protected:
    irr::ITimer *timer; //pointer to Irrlicht timer
    irr::u32 time;
    irr::u32 oldtime;
    irr::f32 looptime;
    irr::u32 loopnum;
};

//--- GUARDIAN OF INCLUSION ----------------------------------------------------
#endif

//--- END OF FILE MTimer.h -----------------------------------------------------
Sparks
Posts: 19
Joined: Thu Oct 21, 2004 1:30 am
Location: Montreal

Post by Sparks »

Hi all,

Thanks arras for you code sample it very appreciated! I have written my classes for moving objects with position, velocity and acceleration. Every thing seems good. I took some time to write because my C++ is pretty rusty and my Java reflexes are always kicking in.

Next up on my list is collision detection! So I will try to explain my detection prediction idea. I’m pretty sure it’s nothing new. The idea is with my movement classes to generate the next movement and use something like getCollisionPoint() and assign a core::line3d my predicted position.

The important thing to remember about this type of Collision Detection is that I will have many objects that call all collide with one another and I would like an event or something so I can generate the new direction of each object involved in the collision.

It’s just too bad that the tutorial does not cover what I want to do. But I can’t probably pull it off or find a function to help me out a bit.

As always comments, ideas, suggestions are always welcomed 
XL Game Development
Sparks
Posts: 19
Joined: Thu Oct 21, 2004 1:30 am
Location: Montreal

Post by Sparks »

So after more research I come to another question. I was wondering what algorithm is best to use with IrrLicht for Object to Object collision detection?
XL Game Development
Post Reply