Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have written a program to record the x,y,z coordinated of the Hand joint and I want to animate my models 2D or 3D according to these coordinates. . .However the output of the x,y,z coordinates are fluctuating from -0 to 1 but not more than that..

So i assume I will need to multiply them back with the screen width and height, however it still doesnt seem to animate according to the original x,y,z points

Any transformations I might be missing out?

        protected override void Update(GameTime gameTime)
        {

            position += spriteSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;

            //// TODO: Add your update logic here
            using (StreamReader r = new StreamReader(f))
            {
                string line;
                Viewport view = graphics.GraphicsDevice.Viewport;
                int maxWidth = view.Width;
                int maxHeight = view.Height;

            //    int i = 0;
                while ((line = r.ReadLine()) != null)
                {


                    string[] temp = line.Split(',');

                int x = (int) Math.Floor((float.Parse(temp[0]) * 0.5f) + 0.5f) maxWidth);
              int y = (int) Math.Floor((float.Parse(temp[1]) * -0.5f) + 0.5f) * maxHeight);



                    motion.Add(new Point(x, y));
            //        Console.WriteLine(temp[0] + "," + temp[1] + "," + motion[i].X+ "," + motion[i].Y);
            //        i++;

                }

            }


//            foreach (Point s in motion)
            {

                position.X = motion[i].X;
                position.Y = motion[i].Y;

            }

  //


            i++;

            a_butterfly_up.Update(gameTime);

            a_butterfly_side.Update(gameTime);

            G_vidPlayer.Play(mossV);

            base.Update(gameTime);
        }
share|improve this question

2 Answers 2

This seems to work well for now . .however I dont understand the Why need to multiply or add 0.5f to the maxWidth or maxheight. . .

    using (StreamReader r = new StreamReader(f))
    {
        string line;
        Viewport view = graphics.GraphicsDevice.Viewport;
        int maxWidth = view.Width;
        int maxHeight = view.Height;

        while ((line = r.ReadLine()) != null)
        {


            string[] temp = line.Split(',');

            int x = (int) Math.Floor(((float.Parse(temp[0]) * 0.5f) + 0.5f) * maxWidth);
            int y = (int) Math.Floor(((float.Parse(temp[1]) * -0.5f) + 0.5f) *maxHeight);


          motion.Add(new Point(x, y));

        }

    }

        position.X = motion_2[i].X;
        position.Y = motion_2[i].Y;
        i++;
share|improve this answer
    
I dont think you need to do this. It will stretch your movements in a wrong way. Tryo to multiply y with -1 and keep the 0.5 out of the calculation –  floAr Sep 24 '12 at 7:54
    
I'll try this .. but what about the Z values ? ? Do i need any transformations for that too –  Sweta Dwivedi Sep 24 '12 at 12:55
    
I just tried it out . . What happens is the if i remove the 0.5f . . the smiley (sprite) just goes out of the screen . . –  Sweta Dwivedi Sep 24 '12 at 13:15
    
int x = (int) Math.Floor(((float.Parse(temp[0])*1f) * maxWidth); int y = (int) Math.Floor(((float.Parse(temp[1]) * -1f) *maxHeight); this doesn´t work ? –  floAr Sep 25 '12 at 7:45
    
I'm sorry to reply after really long . . but 1f doesnt work apparent 0.5f is more accurate somehow . . which doesnt even make sense to me :-/ –  Sweta Dwivedi Sep 28 '12 at 21:05

It may be 0 most of the time, as you cast to int before you multiply (btw. your brackets are somehow messed up anyway). Maybe try this code instead:

   int x = (int) (float.Parse(temp[0])* maxWidth);
   int y = (int) (float.Parse(temp[1]) * maxHeight);

Regards!

EDIT:

Your code looks a bit messed up: At the beginning you use position += spriteSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; which make not really sense to me as you overwrite position later on. I am not able to test much on my current machine, so I will give you a pseudo code snippet of how I would address this problem:

int your objects add: Vector2D position; Vector2D target;

public void Update(GameTime gameTime)
{
     if position!= target
        position+=target-position*gameTime*speed;
}

In the main loop do the following:

protected override void Update(GameTime gameTime)
{
    Get the target location from your stream
    Set the target of the desired object to the retrieved point
    Update every object
    base.Update(gameTime);
}

This is full pseudo code but might give you a headstart to implement the movement.

Regards!

share|improve this answer
    
I had tried this before but its not correct! Yes i'm sorry for the brackets its supposed to be one less –  Sweta Dwivedi Sep 21 '12 at 11:39
    
Have you tried debugging the values you receive for x and y? Just to make sure the error happens here and not in the animation itself –  floAr Sep 21 '12 at 11:43
    
yes i have added a breakpoint and the values are fine. . .im guessing there is smth more i have to do before i can get the actually x,y,z values –  Sweta Dwivedi Sep 21 '12 at 11:53
    
Maybe add the animation logic to the topic. If your values are fine, then the error is clearly not rooted in the above snippet –  floAr Sep 21 '12 at 11:55
    
I have added the logic above. . just changed the x,y param –  Sweta Dwivedi Sep 21 '12 at 12:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.