XNA Game Development Forums
2012/05/18 06:18:19 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Calendar Login Register  
Pages: [1]
  Print  
Author Topic: Moving the models aroung  (Read 2477 times)
Squeezle42
Newbie
*
Offline Offline

Posts: 5


View Profile
« on: 2007/03/05 13:56:59 »

Just a comment to start, excellent tutorials   Cool

They have given me so far an understanding not only of C# after using .c for so long that I thought would never happen. Still a bit hazy on a few points though.

You use the controls in the demo class:
 game.Input.OnUpdate += new UpdateMethod(CameraControls);

Where I am used to
 KeyboardState keys = Keyboard.GetState();
            if (keys.IsKeyDown(Keys.Up))
{
//Do stuff
}

Basically what I am trying to do is add some movement controls to the models and I keep getting stuck on use of unsigned local variables whenever I try to change the model position. Eg,
landShark.Position = new Vector3(0, xPosition, 0);

or landShark.Position.Y += 0.1f;

As you can probably tell I am also new to using so many different classes and after putting in a few Interfaces I am still not 100% on their purpose or use either.

Any insight on what is usually a simple misplaced period would be greatly appreciated.
Logged
EclipsE
Full Member
***
Offline Offline

Posts: 111


View Profile
« Reply #1 on: 2007/03/05 15:39:46 »

Is your problem that you can't move a model?

That is happening to me too...

EDIT:

I'm so stupid... I forgot to set the correct world matrix in the shader...
btw, why do my models rotate strangely?

EDIT:

I figured it out... Smiley
« Last Edit: 2007/03/05 16:02:19 by EclipsE » Logged
Squeezle42
Newbie
*
Offline Offline

Posts: 5


View Profile
« Reply #2 on: 2007/03/07 01:37:49 »

Still having problems figuring out how to get my models to move at all.

Not really sure were to put in any input that can constantly update the position of the model.

tried
public float test3;
protected override void Update(GameTime gameTime)
        {
           
            test3 += 0.1f;
            Window.Title = test3.ToString();
            base.Update(gameTime);
        }

in the HMDemo.cs
and I can't even get a simple float to count up, let alone change my models position on the fly. Racking my brain trying to find the right class to edit where I can advance a float and then apply it to the models position.

I added:

  public void MoveForward(float forwardDistance)
        {
            myPosition.X = forwardDistance;
        }
to the HMObject.cs

but how or where in HMDemo.cs can I do something like

randomObject.MoveForward(aNumberThatActuallyChanges);

hit a wall here and can't seem to find the right entrys for what I'm looking for, thanks in advance Smiley
Logged
Nemo Krad
Global Moderator
Hero Member
*****
Offline Offline

Posts: 512


I have seen the fnords


View Profile WWW
« Reply #3 on: 2007/03/07 01:56:57 »

I just stole the translate and rotate methods from the camera class, modified them a bit and it all works fine.
Logged
Squeezle42
Newbie
*
Offline Offline

Posts: 5


View Profile
« Reply #4 on: 2007/03/07 13:50:22 »

I just stole the translate and rotate methods from the camera class, modified them a bit and it all works fine.

Tried that, I don't think it's the changing of the models position that I'm having a problem with, it's more the fact that the call to change the position only gets called once.

I can't figure out how to use non static variables in my demo class and I'm not sure how to access the objects I create in the demo class from outside the demo class.
although with the translate method I put in HMObject.cs it does have myPosition += etc. so I'm not sure why it doesn't add the changed position to the previous one every time it runs through
public static void Main()

I'm sure there's something I'm missing here, but usually If I want to add any changed variables I would go through the Main() wouldn't I?
Thanks again for your input Smiley
Logged
Nemo Krad
Global Moderator
Hero Member
*****
Offline Offline

Posts: 512


I have seen the fnords


View Profile WWW
« Reply #5 on: 2007/03/07 14:12:41 »

I wired an event to the engines Update and manipulate the objects there.
You can either create your objects as globals and manipulate the globals or add a method to the Scene object so you can pull them out by name, to do this I added a Name property to my objects so they could be referenced like that.
Logged
Squeezle42
Newbie
*
Offline Offline

Posts: 5


View Profile
« Reply #6 on: 2007/03/07 14:40:48 »

\o/ Finally got it Smiley Thanks for all your help nemo!

I put
public static HMTexturedQuad quad = new HMTexturedQuad(@"Content/Textures/logo");

before Main() so it was global instead of in Main then added

  game.Input.OnUpdate += new UpdateMethod(MoveForward);

to Main()

then

public static void MoveForward()
        {
            if (game.Input.Keys.Contains(Keys.Up))
            {
                quad.Translate(Vector3.Forward);
            }
        }

and low and behold it moved Cheesy

I think it was when you said Global that tipped me off to what I was missing Wink

And I am using the Octree for everything instead of the scene now so I should be able to do the same for everything I add now
Logged
Pages: [1]
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Moving to DX 2.0 dll Hazy Mind 3D Engine mikeschuld 9 3206 Last post 2006/08/19 23:01:30
by Chr0n1x
Tutorial 4 :: Moving Cameras and a Simple Input Component Tutorial Discussion « 1 2 » mikeschuld 21 8457 Last post 2008/12/11 10:42:13
by mikeschuld
Shaders and rotating models.... General Discussion Nemo Krad 3 2827 Last post 2007/03/03 17:42:12
by Nemo Krad
Nice models and free models, new site! General Discussion 3d4ya 2 3054 Last post 2010/08/03 03:05:01
by ThackeG67
Texturing Models Hazy Mind XNA Engine Peregrinati 4 2106 Last post 2008/12/15 12:14:41
by Peregrinati
xsi models not displaying correctly Hazy Mind XNA Engine crazyhor77 2 1474 Last post 2009/09/21 22:48:16
by crazyhor77
Powered by MySQL Powered by PHP Powered by SMF 1.1.12 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.923 seconds with 19 queries.