i have 2 models in my game loaded. where one of the models is a gokart and camera follows it from behind. the second model is the track. when i controll the kart the kart moves but the track model stays still. how do i overcome this.
this is the code for drawing the track model.(just the track model not the kart)
private void DrawModel(Model m){
Matrix[] transforms = new Matrix[m.Bones.Count]; float aspectRatio = graphics.GraphicsDevice.Viewport.Width / graphics.GraphicsDevice.Viewport.Height;m.CopyAbsoluteBoneTransformsTo(transforms);
Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f); Matrix view = Matrix.CreateLookAt(new Vector3(0.0f, 50.0f, 2050.0f), Vector3.Zero, Vector3.Up); foreach (ModelMesh mesh in m.Meshes){
foreach (BasicEffect effect in mesh.Effects){
effect.EnableDefaultLighting();
effect.View = view;
effect.Projection = projection;
}
mesh.Draw();
}
}
thanks in advance
peter(im new)

3d multiple model help
morgan_
i did what you suggested but now the track model moves like the kart model.
i just want the track to stay still but beable to move the kart around the track.
btw the "track" model is just reference for the kart so that i can properly adjust the kart's controls etc.
thanks
peter
ms citizen
Sorry then, I'm not following what the issue is. Maybe if you could describe in more detail
Bill
Mohammad Mir mostafa
Also, in your original post you stated that the track stays still, I think you meant it does not stay still and you want it to. You might want to rephrase that so people can better understand your problem.
Paras Dhawan
ershad
I belive you have to do a world transformation.
effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(objectRotation) *
Matrix.CreateTranslation(objectPosition);
Rattlerr
bill
i already have the camera setup to follow it. its just that when i controll the kart the other object moves as well, when its supposed to stay still.
peter.
NeederOfVBHelp
anf600
yeah i do mean the track has to stay still.
now whats this matrix.identity, what does it do and how would i go implementing it into my code.
this is the code i have for the track and after it is the kart(drawing methods)
private void DrawModel(Model m){
Matrix[] transforms = new Matrix[m.Bones.Count]; float aspectRatio = graphics.GraphicsDevice.Viewport.Width / graphics.GraphicsDevice.Viewport.Height;m.CopyAbsoluteBoneTransformsTo(transforms);
Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f); Matrix view = Matrix.CreateLookAt(new Vector3(0.0f, 75.0f, 2050.0f), Vector3.Zero, Vector3.Up); foreach (ModelMesh mesh in m.Meshes){
foreach (BasicEffect effect in mesh.Effects){
effect.EnableDefaultLighting();
effect.View = view;
effect.Projection = projection;
effect.World = transforms[mesh.ParentBone.Index] *
Matrix.CreateRotationY(modelRotation) * Matrix.CreateTranslation(modelPosition);}
mesh.Draw();
}
}
now the kart
protected
override void Draw(GameTime gameTime){
graphics.GraphicsDevice.Clear(
Color.CornflowerBlue);DrawModel(Track);
//Copy any parent transforms Matrix[] transforms = new Matrix[kartmodel.Bones.Count];kartmodel.CopyAbsoluteBoneTransformsTo(transforms);
//Draw the model, a model can have multiple meshes, so loop foreach (ModelMesh mesh in kartmodel.Meshes){
//This is where the mesh orientation is set, as well as our camera and projection foreach (BasicEffect effect in mesh.Effects){
effect.EnableDefaultLighting();
effect.World = transforms[mesh.ParentBone.Index] *
Matrix.CreateRotationY(modelRotation)*
Matrix.CreateTranslation(modelPosition);effect.View =
Matrix.CreateLookAt(cameraPosition,modelPosition, Vector3.Up);effect.Projection =
Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),aspectRatio, 1.0f, 10000.0f);
}
//Draw the mesh, will use the effects set above.mesh.Draw();
}
}
thanks
peter