Note that there are some explanatory texts on larger screens.

plurals
  1. POCan I draw model in another class?
    primarykey
    data
    text
    <p>I'm trying to draw model in another class. i have tried to draw the model in another class. however, my model won't get rendering at all with the codes of what i have made.</p> <p>here the code for <strong>Game1:</strong> (<strong>Note:</strong> these codes work well for Game1)</p> <pre><code>private Vector3 position = new Vector3(0, 0, 0); private Matrix world; private Matrix view; private Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), 800f / 600f, 0.1f, 100f); private Model car; SpriteBatch spriteBatch; GraphicsDeviceManager graphics; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; Vector3 transformedReference = Vector3.Transform(new Vector3(0, 5, 15), Matrix.CreateRotationY(0f)); view = Matrix.CreateLookAt(position + transformedReference, position, Vector3.Up); } protected override void Initialize() { Components.Add(new Car(this, view, projection)); world = Matrix.CreateTranslation(position); Vector3 transformedReference = Vector3.Transform(new Vector3(0, 5, 15), Matrix.CreateRotationY(0f)); view = Matrix.CreateLookAt(position + transformedReference, position, Vector3.Up); base.Initialize(); } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); car = Content.Load &lt; Model &gt; ("car\\car"); } public void DrawModel(Model model, Matrix world, Matrix view, Matrix projection) { foreach(ModelMesh mesh in model.Meshes) { foreach(BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); effect.PreferPerPixelLighting = true; effect.World = mesh.ParentBone.Transform * world; effect.View = view; effect.Projection = projection; } mesh.Draw(); } } protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); world = Matrix.CreateTranslation(position); base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); DrawModel(car, world, view, projection); base.Draw(gameTime); } </code></pre> <p>and here the codes of my <strong>another class:</strong> (<strong>Note:</strong> these codes doesn't work well or the model can't be rendered on Game1 graphic)</p> <pre><code> public class Car: DrawableGameComponent { public Model CarModel { get; set; } private Vector3 position = new Vector3(0, 0, 0); private Matrix World = Matrix.CreateTranslation(new Vector3(0, 0, 0)); public Matrix Camera { get; set; } public Matrix Projection { get; set; } public Game1 GameParent { get; set; } public Car(Game1 game, Matrix view, Matrix projection): base(game) { view = Camera; Projection = projection; Camera = view; GameParent = game; World = Matrix.CreateTranslation(position); base.Initialize(); } public static void DrawModel(Model model, Matrix world, Matrix view, Matrix projection) { foreach(ModelMesh mesh in model.Meshes) { foreach(BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); effect.PreferPerPixelLighting = true; effect.World = mesh.ParentBone.Transform * world; effect.View = view; effect.Projection = projection; } mesh.Draw(); } } protected override void LoadContent() { CarModel = GameParent.Content.Load &lt; Model &gt; ("car\\car"); base.LoadContent(); } public override void Update(GameTime gameTime) { base.Update(gameTime); } public override void Draw(GameTime gameTime) { DrawModel(CarModel, World, Camera, Projection); //DOESN'T WORK WELL!! base.Draw(gameTime); } } </code></pre> <p>OK, my point just want to drawing 3D model in another class,, </p> <p>well, What should i do to solve this?</p> <p>i hope you don't mind to help me and you can understand what i mean..</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload