Difference between revisions of "Tutorial - Picking"
(New page: == Picking the mesh under the mouse cursor == Picking an object within the scene is a common problem. Supposing you want to select the object using a mouse the following sample will show...) |
(Updated the code to work with Beta4 and SVN trunk.) |
||
(7 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
+ | {| border="0" | ||
+ | | {{ContentBlock|width=800|color=white | ||
+ | |content={{!!}} | ||
== Picking the mesh under the mouse cursor == | == Picking the mesh under the mouse cursor == | ||
Line 24: | Line 27: | ||
// get window size for normalization | // get window size for normalization | ||
glfwGetWindowSize(&width, &height); | glfwGetWindowSize(&width, &height); | ||
− | // pick the node under the normalized | + | // pick the node under the normalized mouse position |
app->pick( x / float( width ), (height - y) / float( height ) ); | app->pick( x / float( width ), (height - y) / float( height ) ); | ||
} | } | ||
} | } | ||
+ | </source> | ||
+ | }} | ||
+ | To activate that listener we have to add the following code to the '''setupWindow''' method: | ||
+ | |||
+ | {{CppSourceCode|description=Activate mouse button listener|code=<source lang="cpp" line="1"> | ||
+ | glfwSetMouseButtonCallback( mouseButtonListener ); | ||
</source> | </source> | ||
}} | }} | ||
− | |||
− | Then in the '''app.cpp''' we implement a call to the | + | |
+ | For the use of [http://www.horde3d.org/docs/_utils.html#pickNode Horde3DUtils::pickNode] we have to normalize the window coordinates received by ''glfwGetMousePos''. That's why we need to call ''glfwGetWindowSize'' additionally. Another conversion has to be made, since GLFW has it's origin in the upper left corner while Horde3D requires the origin to be in the lower left corner. | ||
+ | |||
+ | Then in the '''app.cpp''' we implement a call to the h3dutPickNode utility function. | ||
{{CppSourceCode| | {{CppSourceCode| | ||
Line 41: | Line 52: | ||
void Application::pick( float dX, float dY ) | void Application::pick( float dX, float dY ) | ||
{ | { | ||
− | + | H3DNode node = h3dutPickNode(_cam, dX, dY); | |
} | } | ||
</source> | </source> | ||
}} | }} | ||
+ | }} | ||
+ | | valign="top" | {{Extension_Summary| | ||
+ | name = Picking Tutorial| | ||
+ | screenshot = H3DPlaceHolder.png| | ||
+ | description = This tutorial present how to pick an object in a 3D scene.| | ||
+ | version = 1.0| | ||
+ | horde3dversion = 1.0 beta| | ||
+ | released = 2008-04-15| | ||
+ | author = Volker Wiendl| | ||
+ | }} | ||
+ | |} | ||
+ | [[category: Tutorials]] |
Latest revision as of 15:19, 28 June 2010
|
|