topical media & game development
mobile-query-three-plugins-objectcoord-tquery.object3d.coordinate.js / js
get screen position
parameter: {THREE.Camera|undefined} tCamera the camera used to render
returns: {THREE.Vector3} the screen position
tQuery.Object3D.registerInstance('screenPosition', function(tCamera){
tCamera = tCamera || tQuery.world.tCamera();
var position = this.worldPosition();
return tQuery.convertWorldToScreenSpace(position, tCamera);
});
get the world position
returns: {THREE.Vector3} the world position
tQuery.Object3D.registerInstance('worldPosition', function(){
var tObject3D = this.get(0);
tObject3D.updateMatrixWorld();
var worldMat = tObject3D.matrixWorld;
var worldPos = tQuery.createVector3().getPositionFromMatrix(worldMat);
return worldPos;
});
tQuery.Object3D.registerInstance('cssPosition', function(tRenderer, tCamera){
tRenderer = tRenderer || tQuery.world.tRenderer();
tCamera = tCamera || tQuery.world.tCamera();
var position = this.screenPosition(tCamera);
position.x = ( (position.x/2 + 0.5)) * tRenderer.domElement.width;
position.y = (1-(position.y/2 + 0.5)) * tRenderer.domElement.height;
return position;
});
convert world position to screen space
parameter: {THREE.Vector3} worldPosition the world position
parameter: {THREE.Camera} tCamera the camera used to render
returns: {THREE.Vector3} the screen space position [-1, +1]
tQuery.registerStatic('convertWorldToScreenSpace', function(worldPosition, tCamera){
var projector = tQuery.convertWorldToScreenSpace.projector || new THREE.Projector();
var screenPos = projector.projectVector(worldPosition.clone(), tCamera );
return screenPos;
});
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.