On 22/02/2017 at 04:41, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R18
Platform: Windows ;
Language(s) : C++ ;
---------
Hello.
I have a tooldata plugin. I need to click on any object, get the normal vector from the polygon I clicked and create in a position based on the direction of the normal.
Here is what I do:
- In ToolData MouseInput, I use ViewportSelect::PickObject to get the clicked object.
- Then I use ViewportSelect::Init and ViewportSelect::GetNearestPolygon to get the clicked polygon from that object.
- I use polygon_object->CreatePhongNormals() to get the vertex normals, which I use to generate a polygon normal (I average its vertex normals).
I need to find the clicked position in World space.
I feel that GeRayCollider's Intersect is the way to go, but it requires position and direction of the ray.
Here is how I get screen-to-world position (is it correct ?) :
Vector cam_pos = base_draw->GetSceneCamera(doc)->GetAbsPos();
Vector world_pos = base_draw->SW(Vector(mouse_x, mouse_x, cam_pos.z));
How do I find the direction to the clicked point ?
Thank you.