CommonCtrl.Canvas3D

A 3D canvas container for displaying picture, 3D scene

Title A 3D canvas container for displaying picture, 3D scene
Author(s) LiXizhi
Date 2007/3/27
File script/ide/Canvas3D.lua

Description

A 3D canvas container for displaying picture, 3D scene, etc. Basic picture and scene manipulation is implemented, such as zooming, panning pictures, and mouse control of 3d scenes. Note one can create as many instances of this class as they like, but one must create as few miniscene graph name as possible, as each new mini scene graph will consume some memory and processing time.

Member Functions

Canvas3D:new

 common control library
NPL.load("(gl)script/ide/common_control.lua");

 define a new control in the common control libary

 default member attributes
local Canvas3D = {
   -- the top level control name
   name = "Canvas3D1",
   -- default background image path. 
   background = nil, 
   -- normal window size
   alignment = "_lt",
   left = 0,
   top = 0,
   width = 512,
   height = 290, 
   parent = nil,
   -- attributes
   --how many degrees per pixel movement
   rotSpeed = 0.004,
   -- how many degrees (in radian) to rotate around the Y axis per second. if nil or 0 it will not rotate. common values are 0.12
   autoRotateSpeed = nil,
   -- how many percentage of maxZoomDist to pan for each mouse pixel movement
   panSpeed = 0.001,
   -- camera lift up angle range in 3D mode. 
   maxLiftupAngle = 1.3,
   minLiftupAngle = 0.1,
   -- how many meters to zoom in and out in 3D mode. 
   maxZoomDist = 20,
   minZoomDist = 0.01,
   -- must be power of 2, like 128, 256. This is only used in ShowModel. 
   -- However, one can use the set size function miniscenegraph to specify both height and width.
   RenderTargetSize=256,
   -- whether it will receive and responds to mouse event
   IsInteractive = true,
   -- private: 
   -- 1. resourceType==nil means miniscenegraph, 
   -- 2. resource == 0 means image or swf or avi
   resourceType = nil,
   resourceName = nil,
   -- the miniscenegraph name to use if no one is specified. self.name is used. 
   miniscenegraphname,
   -- whether miniscene graph uses active rendering. default to false.
   IsActiveRendering = false,
}
Canvas3D = Canvas3D;

constructor

syntax

function Canvas3D:new (o)

parameters

o  

Canvas3D:Destroy

Destroy the UI control

syntax

function Canvas3D:Destroy ()

Canvas3D:Show

  • param bShow : boolean to show or hide. if nil, it will toggle current setting.

syntax

function Canvas3D:Show(bShow)

parameters

bShow boolean to show or hide. if nil, it will toggle current setting.

Canvas3D.OnClose

close the given control

syntax

function Canvas3D.OnClose(sCtrlName)

parameters

sCtrlName  

Canvas3D:ShowImage


public methods

public: bind the canvas to an image.

  • param filename : the image file path or the image asset object.

syntax

function Canvas3D:ShowImage(filename)

parameters

filename the image file path or the image asset object.

Canvas3D:SetEnabled

set enabled

syntax

function Canvas3D:SetEnabled(bEnabled)

parameters

bEnabled  

Canvas3D:SetRenderTargetSize

auto set render target size,input are rounded to power of 2. it is only used in ShowModel();

syntax

function Canvas3D:SetRenderTargetSize(width, height)

parameters

width  
height  

Canvas3D:ShowModel

public: bind the canvas to a given 3d model or character. it will reset the scene before adding the new model. it will use the currently bind miniscene graph to display it. if no miniscene graph is bind, it will create a default one named "Canvas3D", which is 128*128 in size.

  • param obj : a newly created ParaObject or it can be objParams. Note: it can NOT be an object from the main scene or an attached object.

syntax

function Canvas3D:ShowModel(obj)

parameters

obj a newly created ParaObject or it can be objParams. Note: it can NOT be an object from the main scene or an attached object.

Canvas3D:Draw

manually draw the miniscene graph, in case active rendering is disabled.

syntax

function Canvas3D:Draw(deltaTime)

parameters

deltaTime  

Canvas3D:ShowMiniscene

public: bind the canvas to a miniscenegraph.

  • param name : mini scene graph name.

syntax

function Canvas3D:ShowMiniscene(name)

parameters

name mini scene graph name.

Canvas3D:SaveToFile

public: save the canvas content to file

  • param filename : sFileName a texture file path to save the file to. we support ".dds", ".jpg", ".png" files. If the file extension is not recognized, ".png" file is used.
  • param nImageSize : if this is zero, the original size is used. If it is dds, all mip map levels are saved.

syntax

function Canvas3D:SaveToFile(filename, imageSize)

parameters

| filename | sFileName a texture file path to save the file to. we support ".dds", ".jpg", ".png" files. If the file extension is not recognized, ".png" file is used. |

imageSize  

Canvas3D:CameraSetEyePosByAngle

directly set the camera with engine api calls

syntax

function Canvas3D:CameraSetEyePosByAngle(fRotY, fLiftupAngle, fCameraObjectDist)

parameters

fRotY  
fLiftupAngle  
fCameraObjectDist  

Canvas3D.OnMouseDown

mouse down position Canvas3D.lastMouseDown = {x = 0, y=0} Canvas3D.lastMousePos = {x = 0, y=0} whether any mouse button is down IsMouseDown = false; whether middle mouse button is down IsMidMouseDown = false;

syntax

function Canvas3D.OnMouseDown(sCtrlName)

parameters

sCtrlName  
Topic revision: r1 - 2008-02-29 - LiXizhi
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback