check mouse collision and rendering in 2D game with 3D view

Started by MpPozor, December 26, 2012, 18:25:13

Previous topic - Next topic


Hello everyone.
I'm programmer and I need help with rendering and collision of mouse.

I need help how to create object's image (for example tree) always rotated to get best image from camera (camera can rotate up, down, left, right and zoom).

When I have object (from preceding paragraph named Render, for example tree) and one in front of this (for example player). I need to check, when I clicked to player and when I clicked to tree. All images are PNG images and I need check click only on visible (colored) pixels (when I click to invisible pixel I need check next object for same collision).

I will be glad for all helps. Please, help me too. ;(

Sorry for my bad English. It's not my primary language.


In answer to you problem with rendering: do you mean you want 2d images to be displayed always facing the camera (as in perpendicular to it)? If so then I believe the technique is called "billboarding." The method I use involves getting the "up" and "left" camera directions from the viewing matrix, these are then also the up and left orientations of the images. For a square centre C(cx, cy, cz), size S, left direction L(lx, ly, lz) and up direction U(ux, uy, uz): the for corners are:
(C + 1/2(L) + 1/2(U) ),
(C - 1/2(L) + 1/2(U) ),
(C - 1/2(L) - 1/2(U) ),
(C + 1/2(L) - 1/2(U) )
I will not go into the maths of getting up and left directions from a viewing matrix but it is simple, typing "viewing matrix" into google and the first result gives the answer: The viewing matrix can be got in opengl using glGetFloat with GL_MODELVIEW_MATRIX.

As for mouse collision, opengl has support for a technique called selection or picking. The red book goes into it here: Essentially it involves clipping everything but a very small area around the mouse, drawing the geometry and recording what is not clipped.

If your still unsure after reading these articles, drop another question.