|
|
|
* Javascript/Canvas Textured 3D Renderer v0.3 |
|
* Copyright (c) 2008 Jacob Seidelin, [email protected] |
|
* This software is free to use for non-commercial purposes. For anything else, please contact the author. |
|
* This is a version modified by Stefano Gioffre'. |
|
*/ |
|
|
|
var __iLightIDCounter = 0; |
|
|
|
Canvas3D.Light = function() { |
|
this._oPosition = new Canvas3D.Vec3(0,0,0); |
|
this._oColor = {r:255,g:255,b:255}; |
|
this._fIntensity = 1.0; |
|
|
|
this._iLightID = ++__iLightIDCounter; |
|
}; |
|
|
|
var proto = Canvas3D.Light.prototype; |
|
|
|
proto.setPosition = function(oPos) { |
|
this._oPosition = oPos; |
|
this._bDirty = true; |
|
} |
|
|
|
proto.getPosition = function() { |
|
return this._oPosition; |
|
} |
|
|
|
proto.setColor = function(oColor) { |
|
this._oColor = oColor; |
|
this._bDirty = true; |
|
} |
|
|
|
proto.getColor = function() { |
|
return this._oColor; |
|
} |
|
|
|
proto.setIntensity = function(fIntensity) { |
|
this._fIntensity = fIntensity; |
|
this._bDirty = true; |
|
} |
|
|
|
proto.getIntensity = function(fIntensity) { |
|
return this._fIntensity; |
|
} |
|
|
|
proto.setScene = function(oScene) { |
|
if (this._oScene != oScene) { |
|
this._oScene = oScene; |
|
this._bDirty = true; |
|
} |
|
} |
|
|
|
proto.draw = function(oContext, iOffsetX, iOffsetY) { |
|
var oScene = this._oScene; |
|
var oCam = oScene.getActiveCamera(); |
|
|
|
var oPos2D = oCam.transform2D(oCam.transformPoint(this._oPosition)); |
|
|
|
var iRadius = 3; |
|
|
|
oContext.beginPath(); |
|
oContext.moveTo(oPos2D.x + iOffsetX + iRadius, oPos2D.y + iOffsetY); |
|
oContext.arc(oPos2D.x + iOffsetX, oPos2D.y + iOffsetY, iRadius, 0, 360, false); |
|
oContext.fillStyle = "rgb(255,255,0)"; |
|
oContext.fill(); |
|
} |
|
|
|
proto.getDirty = function() { |
|
return this._bDirty; |
|
} |
|
|
|
proto.setDirty = function(bDirty) { |
|
this._bDirty = bDirty; |
|
} |
|
|