Re: [Vrmlengine-main] Question on Moving the Camera Around for a Set Interval
Game engine supporting many 3D/2D formats and graphic effects
Brought to you by:
kambi
From: Michalis K. <mic...@gm...> - 2009-03-25 05:05:08
|
Shawn Hunt wrote: > Hi, > > I am trying to modify the View3DScene code to add a new menu pic that > allows me to move the camera position around for a set interval and take > a screen shot along the way, like a controlled walking movement. I want > to be able to automatically collect data from various VRML models and > use them for analysis later. > > I created a new procedure "GenerateScreenshots" and in it I have the > increment CameraPos[0], [1], and [2] and then I am trying to do: > > SceneAnimation.Scenes[0].ViewerChanged(CameraPos, CameraDir, CameraUp); > Glw.EventResize; > Glw.PostRedisplay; > > thinking that it would change the camera's position but it isn't. I am > getting the screenshots but the camera doesn't move. Am I mssing a call > to a procedure that updates the screen? > > I'm sorry to ask but I have been fiddling around with this for a while > now and I didn't see any examples that showed me how to do this. > 1. ViewerChanged let's the Scene know the new camera configuration, but it doesn't change the actual camera settings known by view3dscene. If you want to set camera position to something computed by the code, you should rather call SetViewpointCore(CameraPos, CameraDir, CameraUp, GravityUp); This will update the Navigator positions, also making an automatic call to ...Scene[0].ViewerChanged. So you don't call ViewerChanged directly. 2. Also, to force redrawing, note that Glw.PostRedisplay may be not enough. PostRedisplay just schedules redraw at the next loop. To actually force the redraw to happen, you can follow Glw.PostRedisplay call with Glw.FlushRedisplay. Or even call Draw(Glw) + glFlush directly, that's how it's implemented in MakeAllScreenShots function (this allows to draw images to the back buffer, without wasting time on flashing them on the screen). 3. Also, Glw.EventResize call should not be needed if your projection doesn't change. So what you want in the end is something like for each camera position do begin SetViewpointCore(CameraPos, CameraDir, CameraUp, GravityUp); Draw(Glw); glFlush(); SaveScreen_NoFlush(filename for this frame, GL_BACK); end; Didn't actually test it, but should work. Unless you *want* to see the captured images, in which case you rather want for each camera position do begin SetViewpointCore(CameraPos, CameraDir, CameraUp, GravityUp); Glw.PostRedisplay; Glw.SaveScreen(filename for this frame); end; 4. Note that what you want is actually possible without modifying view3dscene source code: you can move your camera around the scene by animating your viewpoint (PositionInterpolator changing Viewpoint.position), and catch a series of images by view3dscene filename.wrl --screenshot-range TIME-BEGIN TIME-STEP FRAMES-COUNT "%d.png" Details how --screenshot-range are on http://vrmlengine.sourceforge.net/view3dscene.php#section_screenshot Actually, that's what MakeAllScreenShots function in view3dscene source code implements. Unless you have good reason to compute camera positions in source code (as opposed to designing VRML PositionInterpolator that animates the camera), using --screenshot-range may be simpler. Michalis |