Zhou.Alone Posted July 24, 2013 Share Posted July 24, 2013 Hello I have searched the doc, found the function Object engine.world.getIntersection(vec3 p0,vec3 p1,int mask,int ret[]): Arguments vec3 p0 - Source point. vec3 p1 - Destination point. int mask - Intersection mask. int ret[] - Return array, its components are: ret[0]: intersection point (vec3), in the world coordinates. ret[1]: normal of the intersection point (vec3). ret[2]: texture coordinates of the intersection point (vec4, where vec4.xy is for UV channel 0, vec4.zw is for UV channel 1). ret[3]: surface number. I want to get the intersection point(ret[0]), but I don't understand it. Here is what I have tried: Vec3 p0, p1,; Unigine::getPlayerMouseDirection(p0, p1); int ret[4]; engine.world.getIntersection(p0, p1, ~0, ret); Vec3 intersectionPoint = ret[0]; But I get a error: UserArray::get() bad array index 0, So, how to define this parameter and how to use it? Or is there another way to get the intersection point by mouse click? Thanks! Link to comment
ivan.cuevas Posted July 25, 2013 Share Posted July 25, 2013 You have a sample about intersection: samples/systems/selection_00. The problem I see in your code is that you are not checking the value returned by engine.world.getIntersection(), so in the case of there is no intersection, the array is empty. Link to comment
Zhou.Alone Posted July 25, 2013 Author Share Posted July 25, 2013 You have a sample about intersection: samples/systems/selection_00. The problem I see in your code is that you are not checking the value returned by engine.world.getIntersection(), so in the case of there is no intersection, the array is empty. Thank you, It works now after I and a checking. Vec3 p0, p1,; Unigine::getPlayerMouseDirection(p0, p1); int ret[4]; Object o = engine.world.getIntersection(p0, p1, ~0, ret); if(o != NULL) Vec3 intersectionPoint = ret[0]; But, could you tell me why ret type changed from int to Vec3? Thanks Link to comment
ivan.cuevas Posted July 25, 2013 Share Posted July 25, 2013 Does this answer your question? Link to comment
Zhou.Alone Posted July 25, 2013 Author Share Posted July 25, 2013 Does this answer your question? ivan, I see. Thank you very much! Link to comment
Recommended Posts