4 Replies - 1665 Views - Last Post: 25 February 2013 - 01:57 PM Rate Topic: -----

#1 frostraver  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 93
  • Joined: 11-September 12

DirectX: Selecting objects in a scene

Posted 25 February 2013 - 04:05 AM

Hi everyone,

I'm making agame based on SimCity and something I'm working on right now is selection a tile on the map.
So, I've managed to create a tilemap in DirectX (and it's drawn in my scene and everything) but I can't figure
out how to select a polygon. (Every tile is drawn separately by the way)
How would I go over this problem? I've tried some tutorial which I found on the internet and in books (also the example from DirectX SDK).

Thanks in advance,
Dries

Is This A Good Question/Topic? 0
  • +

Replies To: DirectX: Selecting objects in a scene

#2 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1009
  • View blog
  • Posts: 4,197
  • Joined: 14-February 08

Re: DirectX: Selecting objects in a scene

Posted 25 February 2013 - 04:18 AM

Is this 2D or 3D?
Was This Post Helpful? 0
  • +
  • -

#3 frostraver  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 93
  • Joined: 11-September 12

Re: DirectX: Selecting objects in a scene

Posted 25 February 2013 - 04:32 AM

It's in 3D. (I'm going to use an orthographic camera)
I should've mentioned that.
Was This Post Helpful? 0
  • +
  • -

#4 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1009
  • View blog
  • Posts: 4,197
  • Joined: 14-February 08

Re: DirectX: Selecting objects in a scene

Posted 25 February 2013 - 01:50 PM

Ok, well if you are going to treat the scene like a 2D scene then you can apply the same methods to grabbing te correct tile based on mouse coordinates.

For example, lets say you have a tile map in your scene, your scene viewport is 640x480, your tiles are 32x32 so that's 20 by 15 tiles, how would you know which tile you are on? First you get the mouse position x = 400 y = 200 (for example). You could find out which x tile you are on by dividing the current position by the width of the tiles, and to get the y tile you divide by the height of the tiles.

As long as you are sticking to a fixed scaled then this would work, if you are not then you will have to take into account the scale of your tiles. Hope that makes sense :)
Was This Post Helpful? 0
  • +
  • -

#5 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: DirectX: Selecting objects in a scene

Posted 25 February 2013 - 01:57 PM

Sounds like you're looking for an established technique called 'picking'.

http://schabby.de/pi...gl-ray-tracing/

I know that you're using DirectX instead of OpenGL, but it should be easy enough to apply the same theory.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1