Viewpoint Developer Central    Viewpoint Forums    Viewpoint Forums  Hop To Forum Categories  SDK Support    Mouse to screen.
Go
New
Find
Notify
Tools
Reply
  
-star Rating Rate It!  Login/Join 
<nerz>
Posted
Hey everyone. I got a question regarding mouse tracking in a kind of bizarre way.

I need to track the mouse on a object.
Let me explain. What I am trying to do is make it possible for the user to click and identify a position on the 3D object, as though it where a 2D image. This mens I have to (1) find which objct was clicked (this is easy using the pick() functions), then (2) find where on the object the user clicked as a 3D point.

How would I do this? Can I do this? Or how do I project the mouse so I can calculate the intersection of the object with the line from the mouse to the object. i.e. how do i convert the mouse XY coordinates to their projection on the near and/or far z plane.
 
Reply With QuoteEdit or Delete MessageReport This Post
<nerz>
Posted
Never mind I figured this out on my own.
 
Reply With QuoteEdit or Delete MessageReport This Post
Member
Posted Hide Post
hi nerz
i also in need to find out the 3d point of the object,when i click on the object.
if u got any solution please share with me.

Smile
 
Posts: 9 | Location: India | Registered: April 03, 2004Reply With QuoteEdit or Delete MessageReport This Post
Member
Picture of Sundar
Posted Hide Post
Hi Smile !!
I found one intersting solution in the forum it self. Here is it for your reference.
For your purpose you can use the WorldPoint event. WorldPoint is a 3D point which of course has it's children WorldPoint.x, WorldPoint.y, and WorldPoint.z. So this will return the point in space where an objects surface has been clicked, so you can copy that point to the location of another object, or send the coordinates to a javascript function as in the below example:


<MTSScene Version="313">
<MTSSceneParms RenderMode="LightTexture" BlendShadow="1" EdgeBias="1"/>
<MTSCamera OrbitDist="5">
<ViewLocation x="0" y="0" z="4"/>
<Rotate x="23" y="45" z="0"/>
</MTSCamera>
<MTSInstance Name="Simple_0" PassClick="1">
<Transform>
<Scale x="0.201" y="0.201" z="0.201"/>
</Transform>
<MTSGeometry Name="MTSSimple_0" Type="MTSSphere"/>
</MTSInstance>
<MTSInstance Name="Simple_1">
<Transform>
<Scale x="2" y="2" z="2"/>
</Transform>
<MTSGeometry Name="MTSSimple_1" Type="MTSCube"/>
<MTSHandle Event="MouseLeftDown" Action="MTSCopyProperty" Src="MTSEvent.WorldPoint" Dest="Simple_0.loc_"/>
<!-- example of sending coords to a javascript function (requires there be a function in the page to receive the coords)
<MTSHandle Event="MouseLeftDown" Action="MTSJavaScript" Target="showCoords(MTSEvent.WorldPoint.x,MTSEvent.WorldPoint.y,MTSEvent.WorldPoint.z)"/>
-->
</MTSInstance>
</MTSScene>
 
Posts: 21 | Location: Chennai,India, Asia. | Registered: April 05, 2004Reply With QuoteEdit or Delete MessageReport This Post
<Niko>
Posted
you need to use the context (IPB_Context3d) directly (instead of the scene)
then call
IPB_Context3d::SZID* pick = context->GetPickArray();

it returns the informations about the last pick.
(you will need to pick first)

the 32 higher bits of the is can be casted to IMTS_Instance3d* ((IMTS_Instance3d*)(uint64(pick[i].id)>>32))

the low 32 bits are the face index in the geometry of this instance.

having the pick.z the face which has been clicked, the world matrix of the instance anbd the 2d coordinates of the pick, you compute (projecting this face on the screen) where you clicked on this face... so where you clicked in the world....

note that to compute the Z coordinate of the click, you will need to convert pick.z in scene coordinate. to do it apply the following code:
mreal Z = PB_ConvertFromZElem(pick[i].z-context->GetZTranslation());
Z = context->GetNearPlane()/Z;
 
Reply With QuoteEdit or Delete MessageReport This Post
Member
Picture of Sundar
Posted Hide Post
Hi Niko !!

Can you explain the thing little bit deeper?
 
Posts: 21 | Location: Chennai,India, Asia. | Registered: April 05, 2004Reply With QuoteEdit or Delete MessageReport This Post
  Powered by Eve Community  
 

Viewpoint Developer Central    Viewpoint Forums    Viewpoint Forums  Hop To Forum Categories  SDK Support    Mouse to screen.