Mouse imput in camera view

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 27/03/2009 at 15:16, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   11 
Platform:      
Language(s) :     C++  ;

---------
Hello all,
here my new Beginner question 😉
i am writing a tooldata plugin, and in my study i am trying to rebuild a kind a create polygon tool ( draw a polygon in viewport point by point, all point must have Y=0).
the problem is this if i work in ortho view no problme ( with SW conversion) but in camera i have some problem to place points in correct position.
can anyone explame me somthing about it or beter give me a way to find some documetation to lern it ?
thanks and i know maybe is a very stupid question, but any help is welcome.
best
Franz

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 27/03/2009 at 15:48, xxxxxxxx wrote:

You want to do a ray-plane intersection test which returns the point of intersection. The plane is, of course, the plane with Y=0 (the ground plane) and normal equals the world Y-axis. The ray is the line from the mouse coordinates (converted to world coordinates) into the screen. This can be calculated in the MouseInput() method of the ToolData class.

There should be examples here and maybe even some information in the cinema4dsdk examples.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 27/03/2009 at 18:37, xxxxxxxx wrote:

As Robert pointed out you have to calculate the intersection point of the camera ray and the Y-plane. This is all vector math and trigonometry. Have a look at the attached picture.

I is the camera ray and N the normal of the Y-plane. Knowing these to vectors you can calculate the angle Phi between these two vectors with the dotproduct or Cinema's VectorAngle() function. The rest is pure trigonometry. You know the length of N (the Y position of the ray) and you know the angle. With these you can calculate the other sides of the triangle.

cheers,
Matthias

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 28/03/2009 at 02:07, xxxxxxxx wrote:

Wow Frinds,
Thank You very Mutch, i am on it with this help 🙂
Best Regards
Franz

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 29/03/2009 at 10:35, xxxxxxxx wrote:

sorry,
but have some basic problem :
Where i get Camera Ray ?
and how to calculate N vector?
the only things i have are:

Real mx = msg.GetReal(BFM_INPUT_X);
Real my = msg.GetReal(BFM_INPUT_Y);

is cameraray this : bd->SW(Vector(mx,my,0)) ?

sorry i am a beginner on this 🙂

Franz

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 31/03/2009 at 06:35, xxxxxxxx wrote:

It's a bit difficult to explain so here some code that should do what you want. See the comments for an explaination of the calculation.

> \> Bool LiquidToolData::MouseInput(BaseDocument \*doc, BaseContainer &data;, BaseDraw \*bd,EditorWindow \*win, const BaseContainer &msg;) \> { \>      Real mx = msg.GetReal(BFM_INPUT_X); \>      Real my = msg.GetReal(BFM_INPUT_Y); \>      LONG button; \> \>      switch (msg.GetLong(BFM_INPUT_CHANNEL)) \>      { \>           case BFM_INPUT_MOUSELEFT : button=KEY_MLEFT; break; \>           case BFM_INPUT_MOUSERIGHT: button=KEY_MRIGHT; break; \>           default: return TRUE; \>      } \> \>      Real dx,dy; \> \>      BaseContainer device; \>      win->MouseDragStart(button,mx,my,MOUSEDRAG_DONTHIDEMOUSE|MOUSEDRAG_NOMOVE); \>      while (win->MouseDrag(&dx;,&dy;,&device;)==MOUSEDRAG_CONTINUE) \>      { \>           if (dx==0.0 && dy==0.0) continue; \> \>           mx+=dx; \>           my+=dy; \> \>           Vector ray = !(bd->SW(Vector(mx,my,500.0)) - bd->GetMg().off); // calculate the camera ray \> \>           Real alpha = VectorAngle(ray,Vector(0,-1,0)); // calculate angle between camera ray and the normal of the y-plane \>           Real camlevel = bd->GetMg().off.y; // y-position of the camera \>           Real camdist = camlevel/Cos(alpha); // calculate the distance from the camera to be on the y-plane \> \>           Matrix m = HPBToMatrix(VectorToHPB(ray),ROT_HPB); // create a global matrix for the camera ray \>           m.off = bd->GetMg().off; \> \>           Vector pos = m\*Vector(0,0,camdist); // bring position into global space \> \>           BaseObject \*null = NULL; \>           null = BaseObject::Alloc(Onull); \>           if(!null) return FALSE; \> \>           null->SetPos(pos); \> \>           doc->InsertObject(null,NULL,NULL,FALSE); \> \>           DrawViews(DA_ONLY_ACTIVE_VIEW|DA_NO_THREAD|DA_NO_ANIMATION); \>      } \> \>      return TRUE; \> } \>

cheers,
Matthias

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 01/04/2009 at 00:42, xxxxxxxx wrote:

thanks Matthias,
This is very helpful for me.
Only one thing for how read this post :

this line :

Matrix m = HPBToMatrix(VectorToHPB(ray),ROT_HPB); // create a global matrix for the camera ray
don't work

correct syntax is :
Matrix m = HPBToMatrix(VectorToHPB(ray)); // create a global matrix for the camera ray

Thanks Again
Franz

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 01/04/2009 at 01:31, xxxxxxxx wrote:

With which Cinema 4D version are you compiling?

The additional parameter for HPBToMatrix() got introduced with Cinema 4D R10.5.

cheers,
Matthias

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 01/04/2009 at 01:35, xxxxxxxx wrote:

Hello Matthias,
i am developing now on 10.5
Franz