Page 5 of 29
Posted: Tue Jan 16, 2007 10:56 am
by kohaar
Hi. camera_body->setRotationGeometry(core::vector3df(0,0,0)); worked great, thanks!!!
I still don't understand why yours is framerate independent and mine isn't. It doesn't seem to matter if I use update() or update(deltaTime).
435 fps - Camera falls very fast, mouse moves camera very slowly (delTatime: 0.002)
104 fps - Camera falls at normal speed, moves moves at normal speed (deltaTime: (delTatime: 0.009)
I know that the timer isn't very precise, but I should still not see that big difference, and there shoud be a difference between using update() and update(deltaTime)?
Code: Select all
ITimer* tmr = device->getTimer();
double lastTime = tmr->getTime();
while(device->run()) {
if (device->isWindowActive()){
//camera control
core::vector3df velocity;
if(up) velocity+=camera_body->getDirectionPositionXY(core::vector3df(0,0,camera_speed));
if(down) velocity+=camera_body->getDirectionPositionXY(core::vector3df(0,0,-camera_speed));
if(left) velocity+=camera_body->getDirectionPositionXY(core::vector3df(-camera_speed,0,0));
if(right) velocity+=camera_body->getDirectionPositionXY(core::vector3df(camera_speed,0,0));
camera_body->setVelocity(velocity);
// start changed code
double time = tmr->getTime();
float deltaTime = (( (float)time - (float)lastTime ) / 1000.0f);
printf("deltaTime %f\n", deltaTime);
lastTime = time;
p_world->update();
// end changed code
driver->beginScene(true, true, 0 );
smgr->drawAll();
if(debug_info)
p_world->drawAllDebugInfos();
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps) {
core::stringw str = L"Terrain Renderer - Irrlicht Engine [";
str += driver->getName();
str += "] FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}//is window active
}
Posted: Tue Jan 16, 2007 3:38 pm
by white tiger
strange. try to invert deltaTime (1.0f/deltaTime)
-update() calculates elapsed time (delta time) internally
-update(irr::s32) receives your elapsed time as argument
Posted: Tue Jan 16, 2007 3:52 pm
by white tiger
IrrNewt 0.2 source code has been released (platform indipendent)

Posted: Tue Jan 16, 2007 5:33 pm
by kohaar
I am clueless. I have no idea what the problem is. I also tried to implement a high resolution timer (QueryPerformanceCounter), but it didn't make a difference.
I have tried using 1.0f/deltaTime and deltaTime/1.0f (which should be the correct way for inversing deltaTime), but no matter what, there is a noticeable difference in gravity from 100 to 400 fps.
Normally I would blame it on my coding skills, but as you have seen, I use your example, with the timer being the only difference.
:S
Posted: Tue Jan 16, 2007 9:22 pm
by benny53
Thanks man:) I like learning as much newton as I can:)
Posted: Mon Jan 22, 2007 5:05 pm
by DavidR
Normally I would blame it on my coding skills, but as you have seen, I use your example, with the timer being the only difference.
Beware: I've found previously, that the Irrlicht timer can return 'duff' values under some circumstances. Try a different timing method if possible and see if your problem is corrected
Posted: Mon Jan 22, 2007 5:41 pm
by DavidR
EDIT: Ignore what I said here. It was a glitch in my own code not IrrNewt. Sorry for double post
Posted: Mon Jan 22, 2007 6:02 pm
by kohaar
DavidR wrote:Beware: I've found previously, that the Irrlicht timer can return 'duff' values under some circumstances. Try a different timing method if possible and see if your problem is corrected
kohaar wrote:I also tried to implement a high resolution timer (QueryPerformanceCounter), but it didn't make a difference.
Posted: Mon Jan 22, 2007 7:14 pm
by white tiger
@kohaar: in order to solve the "fps dependent" problem, can you try to compile your code with these modifications, please? the modifications would be applied to the last source code wich you upload(
http://harme.dk/main.cpp)
-before void main(), write:
Code: Select all
#define PHYSICS_UPDATE_FPS 300.0f
#define PHYSICS_THREAD_SLEEPTIME (1000.0f / PHYSICS_UPDATE_FPS)
-before game loop change "double lastTime = 0.0;" to "float lastTime = device->getTimer()->getRealTime();"
-write "float accumulated_time=0.0f" before game loop
-then, in game loop, change:
Code: Select all
// start changed code
double time = tmr->getTime();
float deltaTime = (( (float)time - (float)lastTime ) / 1000.0f);
lastTime = time;
p_world->update(deltaTime);
// end changed code
to:
Code: Select all
// start changed code
float milliseconds=device->getTimer()->getRealTime()-lastTime;
lastTime=device->getTimer()->getRealTime();
accumulated_time += milliseconds;
while (accumulated_time > PHYSICS_THREAD_SLEEPTIME)
{
p_world->update((PHYSICS_THREAD_SLEEPTIME / 1000.0f));
accumulated_time -= PHYSICS_THREAD_SLEEPTIME;
}
// end changed code
Please try it at differents FPS, if you can. The code would be frame rate indipendent now. Thanks for the time that you spent for this project

Posted: Mon Jan 29, 2007 5:03 am
by Eugenik
Greetings to all:)
I am very glad that exists IrrNewt as he very much simplifies job with physics
Newton. For it to the developer separate thanks! My problem: I do an arcade and shooting at me is carried out by a method getCollisionPoints () sometimes there is a following: when the player shoots a point of collision sometimes stops on the first bot and sometimes flies by through him and stops on the following, that that is further. Thus it turns out that the player sometimes shoots through enemies. Somebody knows as it to correct or even than it can be called?
P.S. If that is important bots and the player move at me with the help setVelocity
And in a role such as a body it is used EBT_PRIMITIVE_BOX
It is thankful in advance! Also excuse for my awful English, I from Russia.
Posted: Mon Jan 29, 2007 11:05 am
by kohaar
I'm so sorry for the late reply. I totally forgot to look in this post :S
I tried your modification, and the gravity seems to be the same at any framerate. Really nice!
I just inserted your code, and didn't play around with it much, so I haven't tried to find any solutions to this my self, but not the mouse and keyboard movement seem to be even more effected by framerate than before? When I run the new example at a very low framerate (100) I can't even move, where I can move a little at 400fps
I'll try and look into it.
Sorry for the late reply and thanks for the fix!
Posted: Mon Jan 29, 2007 12:07 pm
by white tiger
and the gravity seems to be the same at any framerate. Really nice!
also on my computer. This fix will be in the next release

Thanks for testing
but not the mouse and keyboard movement seem to be even more effected by framerate than before?
The 4 functions getDirection(Absolute)Position(XY) multiplied the value for the fps before return. With the fix this cause problems (and without the fix this is ineffective

). Simply substitute all getDirectionPositionXY with FRIgetDirectionPositionXY. Now camera movement would be frame rate indipendet. For mouse rotateFromMouse does the same (multiplied the result by the frame rate). For this wait the next release or open "source\body_controller.cpp" and in rotateFromMouse function change
Code: Select all
last_rotation.X+=(((point.Y-0.5f)*mouse_sensitive)*this->world->getTimeElapsed());
last_rotation.Y+=(((point.X-0.5f)*mouse_sensitive)*this->world->getTimeElapsed());
to
Code: Select all
last_rotation.X+=(((point.Y-0.5f)*mouse_sensitive));
last_rotation.Y+=(((point.X-0.5f)*mouse_sensitive));
and the mouse would be now frame rate indipendent
@Eugenik: ICollisionManager::getCollisionPoints() takes a line and return an array of SIntersectionPoint. This array contain all points that the line intersect with all bodies in the scene. So if the line intersect 3 bodies the array will contain 3 elements, the first is the nearer body and the third is the farther body. Try to use getCollisionFirstPoint() wich returns the collision point with the first body.
News: i have added some functions (support for FPS camera directly without too lines of code), integrate IrrNewt in my game and fix some bugs (for example in the current release body-scene node scale offset don't work. However position and rotation offset work)
Posted: Tue Jan 30, 2007 5:52 pm
by DavidR
Hmm, I have a cylindrical body, and I seem to unable to adjust its size - it's much too big for the object it contains
I have no idea how to resize the hull, since setScale on the body seems to crash my app.
How can I adjust the body size before the body is actually created? (as in, not after it has been created)
Posted: Tue Jan 30, 2007 7:02 pm
by white tiger
Hmm, I have a cylindrical body , and I seem to unable to adjust its size - it's much too big for the object it contains
as I saw previously current release of IrrNewt support position and rotation offset for primitive collision (EBT_PRIMITIVE_CYLINDER) but no scale. In fact if you try to call
bodyData.BodyOffsetFromSceneNode.setScale(your_scale_offset)
you will get unpredicable results. However this is already fix in the IrrNewt version of my computer. If you can't wait for the next release i will upload a IrrNewt 0.3 beta version (beta means that only the implemented recently feature may not work, like new ICollisionManager methods)
As you can see to apply offset you need to create your body with the new method wich takes a SBody structure (see the example), if you use the 0.1 version method
Posted: Tue Jan 30, 2007 7:19 pm
by white tiger
for IBody::setScale().
Newton doesn't support realtime body scaling (only position and rotation trasformations are accepted), as it doesn't support body scaling offset (in fact this will be done by a trick).
setScale would be destroy the body, scale the node and re-create the body (this scale node and body, but you need to scale only the body, not the node, so IBody::setScale is not your function, you need scale offset).
I will check why setScale crash, but if you destroy manually your body and recreate it (if you need realtime scaling, after (not before) creating the body) change nothing