bertrand.remondin Posted February 9, 2015 Share Posted February 9, 2015 Hello, I have few questions about the raycast system (intersection). 1) I saw there is WorldIntersection, GameIntersection and PhysicsIntersection; what is the difference between them? 2) I need the intersection point and the normal, do I have to launch two raycast to get them or there is another way ? 3) void fixedUpdate(PlayerActor& player, int addMode) { PhysicsIntersection intersection = new PhysicsIntersection(); PhysicsIntersectionNormal normal = new PhysicsIntersectionNormal(); vec3 start = player.getPosition(); vec3 end = start + (player.getViewDirection() * _raycastDistance); intersection = class_cast("PhysicsIntersection", engine.physics.getIntersection(start, end, 1, intersection)); normal = class_cast("PhysicsIntersectionNormal", engine.physics.getIntersection(start, end, 1, normal)); if (intersection != NULL && normal != NULL) { vec3 pt = intersection.getPoint(); vec3 nor = normal.getNormal(); log.message("%s\n", typeinfo(pt)); _ghost.fixedUpdate(pt, nor, getCellSize(), getSelectedToolSize()); } } In this test, the intersection seems to work because when i don't look at something near me, i don't have debug. But when i have debug, i get something like -1.XXXe+026 2.XXe-042 0.000XX which is totally aberrant. The object which is raycasted is a MeshObjectStatic. Thanks Link to comment
unclebob Posted February 9, 2015 Share Posted February 9, 2015 Bertrand, First things first, we have a bunch of different "getIntersection" functions: 1) engine.game.getIntersection will only look for intersection with pathfinding nodes like obstacles; The function will return Obstacle node and fill GameIntersection data if there was an intersection. GameIntersection only contains intersection point and that's it. 2) engine.world.getIntersection will look for intersection with node surfaces; The function will return Object node and fill WorldIntersection* data if there was an intersection. WorldIntersection contains surface number, triangle number and intersection point. WorldIntersectionNormal contains all of the WorldIntersection data plus normal. WorldIntersectionTexCoord contains all of the WorldIntersectionNormal data plus texcoords. 3) engine.physics.getIntersection will look for intersection with body shape or node surfaces if there's no body on the node. The function will return Object node and fill PhysicsIntersection* data if there was an intersection. PhysicsIntersection contains surface number, intersection shape and intersection point. PhysicsIntersectionNormal contains all of the PhysicsIntersection data plus normal. -- So by knowing that, I'm going to answer rest of your questions: 2) You don't have to do a raycast twice, just pick PhysicsIntersectionNormal and you'll get both contact point and normal; 3) First of all, make sure you're not intersecting with the player itself (which I think is the case in your sample), then make sure you have set 'intersection' flag at least on one of your ObjectMeshStatic surfaces. Also, it's better to set different intersection mask just to be sure you're intersecting with the right thing. Link to comment
Recommended Posts