Skip to content

Commit

Permalink
Added example with getting normal
Browse files Browse the repository at this point in the history
  • Loading branch information
drojdjou committed Apr 14, 2011
1 parent 5c55a4f commit 5b5a248
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions examples/webgl_collisions_normal.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

<script type="text/javascript">

var scene, camera, renderer, info, mouse2d, sun, loader, stats;
var scene, camera, renderer, info, mouse2d, sun, loader, stats, line;
var meshes = [];

var theta = 0;
Expand Down Expand Up @@ -85,6 +85,15 @@
scene.addLight( sun );

loadCube();

var lineMat = new THREE.LineBasicMaterial( { color: 0xff0000, opacity: 1, linewidth: 3 } );

var geom = new THREE.Geometry();
geom.vertices.push( new THREE.Vertex( new THREE.Vector3(-100, 0, 0) ) );
geom.vertices.push( new THREE.Vertex( new THREE.Vector3( 100, 0, 0) ) );

line = new THREE.Line(geom, lineMat);
scene.addObject( line );

stats = new Stats();
stats.domElement.style.position = 'absolute';
Expand All @@ -109,7 +118,7 @@
};


loader.load( { model: "obj/suzanne/suzanne.js", callback: onGeometry } );
loader.load( { model: "obj/suzanne/suzanneHi.js", callback: onGeometry } );
}

function addCube( p, g) {
Expand Down Expand Up @@ -150,6 +159,9 @@
ray.direction.copy( ray.origin );
ray.direction.subSelf( camera.position );

//var ray2 = new THREE.Ray();
//ray2.origin = ray.origin.clone();

if( meshes.length == 0 ) return;

var i, l = meshes.length;
Expand All @@ -166,6 +178,13 @@
if( c ) {

info.innerHTML += "Found @ normal " + vts(c.normal);

var poi = ray.origin.clone().addSelf( ray.direction.clone().multiplyScalar(c.distance) );
line.geometry.vertices[0].position = poi;
line.geometry.vertices[1].position = poi.clone().addSelf(c.normal.multiplyScalar(100));
line.geometry.__dirtyVertices = true;
line.geometry.__dirtyElements = true;

c.mesh.materials[ 0 ].color.setHex( 0xbb0000 );

} else {
Expand Down

0 comments on commit 5b5a248

Please sign in to comment.