SoftPixel Forum

Official community of the SoftPixel Engine and the SoftPixel Sandbox (REGISTRATION only with consultation with the Admin)
It is currently Fri May 25, 2018 11:11 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Tue Dec 09, 2014 2:02 pm 
Offline

Joined: Tue Dec 09, 2014 1:57 pm
Posts: 3
Hi,

Is there any way to find object (mesh or something) by 2d (screen coords) position?
I would like to select an object by mouse click.

Thanks


Top
 Profile  
 
PostPosted: Tue Dec 09, 2014 4:44 pm 
Offline

Joined: Tue Jan 07, 2014 6:38 pm
Posts: 90
Location: Germany
My suggestion is to raytest all meshes in the scene.
But I guess there is a easier solution.

Maybe a shader...


Top
 Profile  
 
PostPosted: Tue Dec 09, 2014 8:19 pm 
Offline

Joined: Tue Dec 09, 2014 1:57 pm
Posts: 3
I think it's not a fast solution. However... do you have an example for raytest?


Top
 Profile  
 
PostPosted: Tue Dec 09, 2014 9:15 pm 
Offline
Site Admin
User avatar

Joined: Sat Jul 07, 2012 5:58 pm
Posts: 540
Location: Germany
Picking (or selecting) 3D models via 2D coordinates is commonly done with intersection tests or rather ray casts.
Take a look at the scene::CollisionGraph::findIntersections function in the API Docu.

Here is a code example:
Code:
// Create collision graph
scene::CollisionGraph* collisionGraph = engineDevice->createCollisionGraph();

// Create a collision material (actually only used for collision detection/resolving)
CollisionMaterial* collisionMaterial = spCollGraph->createMaterial();

// Create collision node (for 'scene::Mesh' named "meshObject")
CollisionMesh* collisionMesh = collisionGraph->createMesh(collisionMaterial, meshObject);

// Get cursor position
dim::point2di cursorPosition = inputController->getCursorPosition();

// Construct picking ray from camera (of type 'scene::Camera')
dim::line3df pickingLine = cameraNode->getPickingLine(cursorPosition);

// Find intersections for the picking line
std::list<scene::SIntersectionContact> contactList;
collisionGraph->findIntersections(pickingLine, contactList);

// Now "contactList" contains all picking contacts ...

_________________
My latest project:
- The XièXiè Programming Language

My hardware:
- GIGABYTE GeForce GTX 670
- Intel Core i7 (Ivy-Bridge)
- 16 GB DDR3


Top
 Profile  
 
PostPosted: Wed Dec 10, 2014 8:49 am 
Offline

Joined: Tue Dec 09, 2014 1:57 pm
Posts: 3
Great, thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group