3D-Special
The 3D-Special view can be controlled by LUA using some rudimentary commands. This can, for instance, be used to visually check the results at the end of the script, or even for simple camera travels.
- Functions
cna.tikandcna.tok:tikstarts a timer andtokstops it and return the elapsed time in milliseconds. glStart()starts the OpenGL view for the entire limitsglQuit()close the OpenGL viewglRedraw()redraws the 3D view after the camera position has been changed withglSetCameraPosition(x,y,z). The function returns the time required for drawing in milliseconds. Note: This function does not update objects/DTM. For this,glQuit()andglStart()must be executed.glGetCameraPosition()returns the current camera position as 3-tupleglSetCameraPosition(x,y,z)moves the camera to the absolute position (x, y, z)glMoveCameraPosition(x,y,z)moves the camera relative to the current positionglGetCameraLookAt()returns the point on which the camera is looking at as a 3-tupleglSetCameraLookAt(x,y,z)moves the point the camera is looking at.Caution: Must not be identical to the camera position and both must not differ only in height (z coordinate).glRotateCameraRight(d)rotates the camera by the specified angle in degrees to the right (negative = to the left); only valid for small angular changes!glRotateCameraUp(d)rotates the camera upwards by the specified angle in degrees (negative = downwards); only valid for small angular changes and the accumulated angle must be in the range [-85; 85].glReset3dAppearance()resets the camera to the default valueglSavePreset(d)saves the current camera position and direction in the given preset, valid values are in the range [1; 10]glLoadPreset(d)loads the specified preset which must be presentglScreenshot(p,w,h)saves the current image using path p (optional: with width w and height h in pixels).- allowed file formats with option BMP: all common image formats
- allowed file format without option BMP: BMP only
Note
The resulting image always corresponds to the current camera configuration and does not have to match the image displayed on the screen!
- In order to cause a stable frame rate, use the
cna.wait(x)function, which waits x milliseconds before the next function is executed.Example:
-- inside any loop
local frameRenderTime = cna.glRedraw()
local minRenderTime = 1/60
if(frameRenderTime < 1/60) then
cna.wait(minRenderTime - frameRenderTime)
end
Note
The camera position and orientation should always be set together. Afterwards glRedraw() must be called before the change becomes visible.