I'm currently stuck on something that just seems extremely odd. I'm creating a game with kinect, and when the player performs an action I want to place a texture onto the screen where their hand is.
I currently have that code implemented. I have something like:
var myVector = Skeleton[JointType.RightHand].Position;
When I get the vector coordinates I store them in an array and that allows me to reference it later if/when I need to. That is the HitVectors array.
The numbers that are recorded into the array are the actual coordinates of the [RightHand] in relation to it's pixel coords on the screen. So for instance your hand is at 100X and 400Y. the array gets a new Vector2(100f, 400f), and so on...
public override void Draw(GameTime gameTime)
{
// This game has a blue background. Why? Because!
ScreenManager.GraphicsDevice.Clear(ClearOptions.Target,
Color.CornflowerBlue, 0, 0);
SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
spriteBatch.Begin();
spriteBatch.Draw(targetTexture, hostileOne.CollisionBox, Color.White);
if (hostileOne != null && hostileOne.HitVectors.Count > 0)
{
foreach (var pos in hostileOne.HitVectors)
{
//trying to get the textures to not draw in a diagonal line
//spriteBatch.Draw(impactTexture, pos, Color.White);
spriteBatch.Draw(impactTexture, new Rectangle((int)(pos.X), (int)(pos.Y), 256, 256), Color.White);
}
}
spriteBatch.End();
}
but the texture isn't drawn to those coordinates on the screen. Instead they are essentially only drawing on a diagonal line, at a 45 degree angle. It seems like the oddest thing to me. I've double checked to make sure that the position coords being passed into the sprite batch are correct, and they are. I've checked to make sure that the coordinates of the hand joint that i'm tracking is at the correct X and Y coordinates when I record its position. So to me, everything seems good until the spritebatch.Draw() method is executed.
For extra info, my texture is a 256x256 png file, the spriteBatch being used is from the GameStateManagement example. It's in the ScreenManager class.
photo of issue: http://i1366.photobucket.com/albums/r770/csmhowitzer/debugdiag_zps4239d261.png
How I convert my Kinect joint position in 3D space to 2D:
protected Vector2 CalculatePointPosition(SkeletonPoint point)
{
var pointx = point.X;
var pointy = point.Y;
var pointz = point.Z;
var pointnormx = pointx / pointz;
var pointnormy = pointx / pointz;
return new Vector2((pointnormx + 0.5f) * (int)screenSize.X, (pointnormy + 0.5f) * (int)screenSize.Y);
}
If you need any more info let me know.
Thanks in advance everyone
var pointnormx = pointx / pointz;
var pointnormy = pointx / pointz;
should've been:var pointnormx = pointx / pointz;
var pointnormy = pointy / pointz;
\$\endgroup\$