sync: OnPreRender/OnPostRender, lights, camera, action!

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
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

sync: OnPreRender/OnPostRender, lights, camera, action!

Post by bitplane »

Okay guys, I've been struggling with this for ages... could use some help here please :)
this post is huge so I split it in to chapters and even added an image

background
The game is like a classic side scrolling shooter but with the camera behind the player's ship ('star fox' rip off). I'm using subclasses of scene nodes. example class hiarachy goes like this-
ISceneNode -> CGameSceneNode -> CPlayerShipSceneNode

I'm doing movement in CGameSceneNode::OnPostRender like so:
PlayerShip.setPosition(PlayerShip.getPosition + velocity * timepassed);

My camera is a child node of a GameSceneNode which follows my PlayerShip. Inside CamHolder::OnPostRender I make the camera look at its target (around 0,0,Z), and set the position of CamHolder (definatly lazy, probably bad, don't think it's the problem)

My player ship gamenode has children, here's the relevant ones:

Code: Select all

ShipNode (gamenode)
  -ShipMesh (animatedmeshscenenode)
    -ShipsBoosters (customscenenode)
    -BoosterLight (lightscenenode) *problem here*
oh, and I'm using irrlicht 0.10, (so I can use my clouds :))

the problem:

when the frame rate slows down (i force it), as you can see...
Image
the light moves forwards in to the ship. (pls ignore the particles, I messed the timing up)

Because of the style of the game I can botch it by making the light a child of the gamenode instead of the animated mesh node.

the question part
is this a bug? (lights two or more nodes deep go out of sync perhaps?)
have i got it all wrong?
anyone else struggled with this and have tips/suggestions?

bonus!
all helpful posters get a cookie!
if this thread leads me to enlightenment I'll write a custom scene node timing tutorial for the wiki :D
Last edited by bitplane on Thu Aug 18, 2005 7:21 pm, edited 1 time in total.
T101
Posts: 44
Joined: Thu Jul 29, 2004 4:41 pm

Post by T101 »

Inside LightHolder::OnPostRender I make the camera look at its target (around 0,0,Z), and set the position of LightHolder (definatly lazy, probably bad, don't think it's the problem)
Read that again. You say you update the camera rotation and the light's position AFTER rendering the scene. Presumably the ship position gets updated after that and before the next time the scene is rendered.

If you update the ship's position from its postrender method, I'm not sure if it will be done before the trailing nodes. It might work that way, but I'm not sure that it's defined to work that way, so it might break in the future.

W.r.t. the light moving into the ship: no way of telling why that happens unless you post the code where the new light position is calculated.
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

whoops!

I meant CamHolder::OnPostRender, not LightHolder (I'll edit my post)

The light is a child of the ship's mesh, but I don't move it or do anything else with it. I don't set the camera's or the lights position, I only move game scene nodes (I rotate the ships mesh though, and i set the camera's target)

got me thinking though... I should move the camera's holder inside the ship's OnPostRender, that makes sense. (I originally did that before I made the light holder). thanks :)

I'll post any progress
Post Reply