update
This commit is contained in:
BIN
raycast_objects/Raycast_Objects.blend
Normal file
BIN
raycast_objects/Raycast_Objects.blend
Normal file
Binary file not shown.
45
raycast_objects/Sources/lnx/MyTraitRaycastObjects.hx
Normal file
45
raycast_objects/Sources/lnx/MyTraitRaycastObjects.hx
Normal file
@ -0,0 +1,45 @@
|
||||
package lnx;
|
||||
|
||||
import iron.system.Input;
|
||||
import iron.math.Vec4;
|
||||
import iron.math.RayCaster;
|
||||
import iron.object.Object;
|
||||
import iron.object.CameraObject;
|
||||
|
||||
class MyTraitRaycastObjects extends iron.Trait {
|
||||
|
||||
var v = new Vec4();
|
||||
var mouse = Input.getMouse();
|
||||
var objects: Array<Object>;
|
||||
var o: Object;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
|
||||
notifyOnInit(function() {
|
||||
|
||||
objects = [object, iron.Scene.active.getChild('Sphere'), iron.Scene.active.getChild('Suzanne')];
|
||||
|
||||
});
|
||||
|
||||
notifyOnUpdate(function() {
|
||||
|
||||
|
||||
if(mouse.started('left')){
|
||||
v = RayCaster.boxIntersectObject(object, mouse.x, mouse.y, iron.Scene.active.camera);
|
||||
if(v != null)
|
||||
trace('Raycast object at position: '+v);
|
||||
|
||||
o = RayCaster.closestBoxIntersectObject(objects, mouse.x, mouse.y, iron.Scene.active.camera);
|
||||
if (o != null){
|
||||
v = RayCaster.boxIntersectObject(o, mouse.x, mouse.y, iron.Scene.active.camera);
|
||||
trace('Raycast object: '+o.name+' at position: '+v);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// notifyOnRemove(function() {
|
||||
// });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user