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