Welcome! Log In Create A New Profile

Advanced

Shotter: How to calcuate coordinates and vector of the pad pointer

Posted by Paipum 
Shotter: How to calcuate coordinates and vector of the pad pointer
September 06, 2012 09:59PM
Dear friends,

I want to develop a method to calculate position and vector of the pad pointer in a 3D world.
For this 3D world I am using the GX library.
In this 3D world the user is able to move in any direction (translation and rotation).
I already know the position and direction of user. But I do not know how to get the pad pointer position.


What I want to do is a shooter. This is the reason why I need to know the vector of pad pointer.
Being in this way, I will know wether I aim my enemy or not.

Thank you very much for your help.
Re: Shotter: How to calcuate coordinates and vector of the pad pointer
September 08, 2012 12:39PM
Assuming you have the 2D position of the Wiimote, you can get the 3D world position like this:
(code snippet from Wire3D)

Vector3F Camera::ScreenToWorldPoint(const Vector2F& rScreenPoint) const
{
    Vector4F worldPoint = (GetProjectionMatrix() * GetViewMatrix()).Inverse() * Vector4F(rScreenPoint.X(), rScreenPoint.Y(), 0, 1);
    return Vector3F(worldPoint.X(), worldPoint.Y(), worldPoint.Z());
}

For deciding whether you hit an enemy or not, you can do a ray casting.

Check out 'Game' in Wire3D's SVN repository, it does exactly what you want to do (moving around in 3D space using Wiimote+Nunchuck and shooting an enemy object. Here's a video of an older version without the enemy object. It's still work in progress, but you should be able to extract all the info from the source code to resolve your question.
Re: Shotter: How to calcuate coordinates and vector of the pad pointer
September 09, 2012 09:23PM
A simple hack would be to create a normalized vector from the pointer coordinates and use that to modify the direction vector.

Something like this;

(guVector){ -((button_pointer_x/screen_center_x)-1) , 0, -((button_pointer_y/screen_center_y)-1) }
	
Re: Shotter: How to calcuate coordinates and vector of the pad pointer
September 10, 2012 10:49AM
Owen,

your hack always results in the same coordinates no matter how the projection (GX_SetProjection()) or the model view (GX_LoadPosMtxImm()) is set up. Thus it cannot be used to unproject the screen point to the 3D position in a 3D world (assuming that's what he wants, it's not totally clear to me from the original post :) ).



Edited 1 time(s). Last edit at 09/10/2012 03:08PM by antibyte.
Re: Shotter: How to calcuate coordinates and vector of the pad pointer
September 10, 2012 03:21PM
Maybe I should clarify my post a bit more:

First, calculate two Vector3 values that differ only by their Z value. For instance, assume that the cursor location is currently (100, 100). Therefore, the first vector (located at the near clip plane) becomes e.g. (100, 100, 0.01) and the second (located at the far clip plane) becomes e.g. (100, 100, 500).

Unproject each point as described above, and store the result. For example, 'minPointSource' stores the result of unprojecting (100, 100, 0.01), and 'maxPointSource' stores the result of unprojecting (100, 100, 500). Determine the direction vector by subtracting 'maxPointSource' from 'minPointSource'.

Finally, you can use the direction vector and 'minPointSource' as a ray for ray casting to determine if you hit an object in your 3D world.
Re: Shotter: How to calcuate coordinates and vector of the pad pointer
September 10, 2012 05:42PM
As I said it was pretty much a hack. I was trying to keep my explanation simple because english does not appear to be the first language of the poster. I really do not know the proper way to do it.
Re: Shotter: How to calcuate coordinates and vector of the pad pointer
September 10, 2012 06:22PM
Ok, I just could not see how that could be used to determine wheter an enemy object is hit or not in 3D space.
So I guessed that there's more to it than you posted. Never mind. :)
Re: Shotter: How to calcuate coordinates and vector of the pad pointer
September 10, 2012 10:47PM
Oh I was basically adjusting the direction vector. Since he already has a position and a direction vector, I was using the pointer values to make small adjustments to the direction vector. It could be used for crude aiming ( not hit detection ) such as what i use in [www.youtube.com]

direction_vector = direction_vector + pointer_normal
Re: Shotter: How to calcuate coordinates and vector of the pad pointer
September 11, 2012 09:30AM
Thanks Owen, I get the idea now. As you only tilt the view in Newo Shooter, your approach perfectly fits its purpose.
Sorry, only registered users may post in this forum.

Click here to login