Page 1 of 1

Very beginner help needed.

Posted: Fri Jun 21, 2013 7:28 pm
by cayongrayoo
Hi Fellas :)
Completely new to using a physics engine and creating proper hardcore stuff.
I've followed the basic tutorial( adding a few boxes and ground) but I cannot see the boxes. When I try and add textures to them(using an entitymodel class) i get and error. The error is caused bu the fact that i copied the entitymodel class in the basicsetupdemo demo and requires a separate camera class. As i don't want to complicate things anymore I'm holding of on implementing a camera.

How do I just plain and simply make these boxes visible? cause at the moment I can only see the color blue everywhere, even though the boxes have been added.
These are the lines i'm having trouble with, in my entitymodel class.

Code: Select all

 {
            Matrix worldMatrix = Transform * entity.WorldTransform;
            model.CopyAbsoluteBoneTransformsTo(boneTransforms);
           foreach (ModelMesh mesh in model.Meshes)
            {
               foreach (BasicEffect effect in mesh.Effects)
                {
                  effect.World = boneTransforms[mesh.ParentBone.Index] * worldMatrix;
                   effect.View = (Game as Game1).Camera.ViewMatrix;
                   effect.Projection = (Game as Game1).Camera.ProjectionMatrix;        
                }
                mesh.Draw();
            }
            base.Draw(gameTime);
        };
Also, i'm not sure whether it's going to "color in" my boxes. I can't see anywhere where the entity model references the boxes :/ should it?

Thanks in advance and sorry for sucking :)

Re: Very beginner help needed.

Posted: Fri Jun 21, 2013 8:13 pm
by Norbo
Conceptually, it's good to remember that the physics engine is completely and totally separate from any visual representation of the physics. The engine has no concept of graphics, it just simulates things.

So, visualizing the simulation can be done pretty much however you want. In this case, the EntityModel just takes some loaded mesh data, positions it according to an entity's transform, and draws it with a BasicEffect. The BasicEffect requires information about a camera to function. That information includes the camera's location, rotation, and 'lens'.

The inverted location and rotation is stored in the View transform; this allows objects in world space to 'pulled' into the local space of the camera by multiplying by the transform.

The Projection transform contains the transform that maps objects in this 'camera space' to the screen (or more correctly, clip space), somewhat like a lens of a real camera. Usually, a standard perspective transform is used for the Projection.
I can't see anywhere where the entity model references the boxes :/ should it?
This line grabs all the information needed from the physical entity:

Code: Select all

Matrix worldMatrix = Transform * entity.WorldTransform;
That grabs the world transform (the position and orientation) of the entity. That tells the drawer where to draw the graphical model. The rest of the information- like the shape of the box- is just loaded mesh data, separate from the physics.

Since this is a strictly graphical matter, you could find a lot of helpful resources on the XNA site and elsewhere.

Re: Very beginner help needed.

Posted: Fri Jun 21, 2013 8:25 pm
by cayongrayoo
Right Okay, thanks.
So how would I implement a camera?

Re: Very beginner help needed.

Posted: Sat Jun 22, 2013 6:04 pm
by Norbo
I would recommend checking out some resources on the XNA site or other general game development sites. Cameras are a fairly common topic; there should be quite a few examples and tutorials available.