Documentation

Classes

Class CopperLicht

The main class of the CopperLicht engine, representing the 3D engine itself.

Class Overview
CopperLicht(elementIdOfCanvas, showInfoTexts, fps)
The main class of the CopperLicht 3D engine. You can create an instance of this class using for example startCopperLichtFromFile, but using code like this will work of course as well:
var engine = new CopperLicht('yourCanvasID'); 
engine.load('somefile.ccbjs');
Parameters:
elementIdOfCanvas
id of the canvas element embedded in the html, used to draw 3d graphics.
showInfoTexts
if set to true, this shows loading indicators and error texts. If set to false no text is shown and you have to do this yourself.
fps
{Number} frames per second to draw. Uses a default of 60 if set to null.

Field Summary
Field Attributes Field Name and Description
 
Event handler called after the scene has been completely drawn.
 
Event handler called before animating the scene.
 
Event handler called before the scene will be completely drawn.
 
Event handler called after the scene description file has been loaded sucessfully (see CopperLicht.load().
Method Summary
Method Attributes Method Name and Description
 
addScene(scene)
Adds a new scene
 
Draws and animates the 3d scene.
 
Returns the 2D pixel position on the screen from a 3D position.
 
Returns a 3D point from a 2D pixel coordinate on the screen.
 
Returns the last X coordinate where the mouse was pressed over the canvas.
 
Returns the last Y coordinate where the mouse was pressed over the canvas.
 
Returns the last X coordinate in pixels of the cursor over the canvas, relative to the canvas.
 
Returns the last Y coordinate in pixels of the cursor over the canvas, relative to the canvas.
 
return a reference to the currently used Renderer.
 
return a reference to the currently active Scene.
 
Returns all available scenes.
 
Returns the TextureManager used to load textures.
 
gotoScene(scene)
Switches the current scene to a new scene.
 
gotoSceneByName(scene, ignorecase)
Switches the current scene to a new scene by scene name.
 
When CopperLicht is created, it will register the document.onkeydown event with this function.
 
handleKeyUp(event)
When CopperLicht is created, it will register the document.onkeyup event with this function.
 
When CopperLicht is created, it will register the onmousedown event of the canvas with this function.
 
When CopperLicht is created, it will register the onmousemove event of the canvas with this function.
 
When CopperLicht is created, it will register the onmouseup event of the canvas with this function.
 
Initializes the renderer, you need to call this if you create the engine yourself without using one of the startup functions like startCopperLichtFromFile.
 
isLoading(filecontent, filename)
Returns true of CopperLicht is currently loading a scene file
 
Returns if the mouse is currently pressed over the canvas.
 
load(filetoload)
Loads a the scene from a CopperCube file and displays it.
Field Detail
OnAfterDrawAll
Event handler called after the scene has been completely drawn. You can use this to draw some additional stuff like 2d overlays or similar. Use it for example like here:
var engine = startCopperLichtFromFile('3darea', 'test.ccbjs');
	
engine.OnAfterDrawAll = function() 
{
  var renderer = engine.getRenderer();
  if (renderer)
  {
    // TODO: draw something additionally here
  }
};

OnAnimate
Event handler called before animating the scene. You can use this to manipulate the 3d scene every frame. An example how to use it looks like this:
var engine = startCopperLichtFromFile('3darea', 'test.ccbjs');
	
engine.OnAnimate = function() 
{
  var scene = engine.getScene();
  if (scene)
  {
    // TODO: do your game logic here
  }
};

OnBeforeDrawAll
Event handler called before the scene will be completely drawn. You can use this to draw some additional stuff like weapons or similar. Use it for example like here:
var engine = startCopperLichtFromFile('3darea', 'test.ccbjs');
	
engine.OnBeforeDrawAll = function() 
{
  var renderer = engine.getRenderer();
  if (renderer)
  {
    // TODO: draw something here
  }
};

OnLoadingComplete
Event handler called after the scene description file has been loaded sucessfully (see CopperLicht.load(). Can be used to hide a loading screen after loading of the file has been finished. Use it for example like here:
var engine = startCopperLichtFromFile('3darea', 'test.ccbjs');
	
engine.OnLoadingComplete = function() 
{
  // Do something here
};
Method Detail
addScene(scene)
Adds a new scene
Parameters:
scene

draw3dScene()
Draws and animates the 3d scene. To be called if you are using your own rendering loop, usually this has not to be called at all. This will also call OnAnimate() before starting to draw anything, and call OnAfterDrawAll() after everything has been drawn.

{Vect2d} get2DPositionFrom3DPosition(pos3d)
Returns the 2D pixel position on the screen from a 3D position. Uses the current projection and view matrices stored in the renderer, so the 3d scene should have been rendered at least once before to return a correct result.
Parameters:
pos3d
{Vect3d} 3d position as Vect3d.
Returns:
{Vect2d} returns a 2d position as Vect2d if a 2d pixel position can be found, and null if not (if the pixel would be behind the screen, for example).

{Vect3d} get3DPositionFrom2DPosition(x, y)
Returns a 3D point from a 2D pixel coordinate on the screen. Note: A 2D position on the screen does not represent one single 3D point, but a actually a 3d line. So in order to get this line, use the 3d point returned by this function and the position of the current camera to form this line.
Parameters:
x
{Number} x coordinate on the canvas. You can use CopperLicht.getMouseX for the current mouse cursor position.
y
{Number} y coordinate on the canvas. You can use CopperLicht.getMouseY for the current mouse cursor position.
Returns:
{Vect3d} returns a 3d vector as described above, or null if not possible to do this calculation (for example if the browser does not support WebGL).

getMouseDownX()
Returns the last X coordinate where the mouse was pressed over the canvas.

getMouseDownY()
Returns the last Y coordinate where the mouse was pressed over the canvas.

getMouseX()
Returns the last X coordinate in pixels of the cursor over the canvas, relative to the canvas.

getMouseY()
Returns the last Y coordinate in pixels of the cursor over the canvas, relative to the canvas.

getRenderer()
return a reference to the currently used Renderer.

getScene()
return a reference to the currently active Scene.

getScenes()
Returns all available scenes. Returns an array containing all Scenes.

{TextureManager} getTextureManager()
Returns the TextureManager used to load textures.
Returns:
{TextureManager} returns the reference to the used texture manager.

gotoScene(scene)
Switches the current scene to a new scene.
Parameters:
scene
{Scene} The new scene to be activated.

gotoSceneByName(scene, ignorecase)
Switches the current scene to a new scene by scene name.
Parameters:
scene
{String} The name of the new scene to be activated.
ignorecase
{Boolean} set to true to ignore the case of the name

handleKeyDown(event)
When CopperLicht is created, it will register the document.onkeydown event with this function. If you need to handle it yourself, you should call this function with the event parameter so that all animators still work correctly.
Parameters:
event

handleKeyUp(event)
When CopperLicht is created, it will register the document.onkeyup event with this function. If you need to handle it yourself, you should call this function with the event parameter so that all animators still work correctly.
Parameters:
event

handleMouseDown(event)
When CopperLicht is created, it will register the onmousedown event of the canvas with this function. If you need to handle it yourself, you should call this function with the event parameter so that all animators still work correctly.
Parameters:
event

handleMouseMove(event)
When CopperLicht is created, it will register the onmousemove event of the canvas with this function. If you need to handle it yourself, you should call this function with the event parameter so that all animators still work correctly.
Parameters:
event

handleMouseUp(event)
When CopperLicht is created, it will register the onmouseup event of the canvas with this function. If you need to handle it yourself, you should call this function with the event parameter so that all animators still work correctly.
Parameters:
event

initRenderer()
Initializes the renderer, you need to call this if you create the engine yourself without using one of the startup functions like startCopperLichtFromFile.
Returns:
returns true if successful and false if not (if the browser does not support webgl, for example).

isLoading(filecontent, filename)
Returns true of CopperLicht is currently loading a scene file
Parameters:
filecontent
filename

isMouseDown()
Returns if the mouse is currently pressed over the canvas.

load(filetoload)
Loads a the scene from a CopperCube file and displays it. This will also initialize the renderer if this has not been done before. You can also use the event handler CopperLicht.OnLoadingComplete to check if the loading of the file has completed.
Parameters:
filetoload
a filename such as 'test.ccbjs' which will be loaded, displayed and animated by the 3d engine. .ccbjs files can be created using the CopperCube editor, it is free to use for 14 days.

© 2010 N.Gebhardt, Ambiera
Documentation generated by JsDoc Toolkit