I am building a menu system using a textured plane. I am using raycasting to determine if a laser pointer is intersecting the plane. the plane could potentially appear anywhere in the world in any orientation. I would like to be able to convert the result.point provided by the raycasting function into coordinates on the plane surface.
Anybody done anything like that and could give me a steer?
Hi Max,
It’s not a screen point as such but more a case of where a laser comming from a vive controller intersects a plane in terms of the local plane coordinates. I have managed to get this far
var self = this;
this.app.systems.rigidbody.raycastFirst(start, end, function (result) {
var pickedEntity = result.entity;
//console.log(pickedEntity);
if (pickedEntity.getName() == "Menu"){
menu.sound.play('menu');
console.log('clicked menu at');
var localOffset = new pc.Vec3();
var mat = pickedEntity.getWorldTransform().clone();
mat.invert();
mat.transformPoint(result.point, localOffset);
console.log(localOffset.x);
console.log(localOffset.y);
console.log(localOffset.z);
}
});
which is the beginning of a solution and I think the next bit is fairly trivial since you only need to take into account the origin is at the centre of the texture.
BUT thinking about it further I am considering abandoning this approach in favor of simply building the UI as an object and simply turning it on and off which I think will be simpler and more flexible in the long run.I am thinking of a simple script that I can attach to any object which has ID and Text attributes which simply apply to any entity which subscribe to a laserclick event.