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 am trying to create a simple board game, but the 3d part of this is really killing me.

From what I can gather I have created a plane, but it never moves even though I turn the camara, but that partially makes sense as I only turn the camara with a 3d model, but in my head that makes 0 sense, in my head if I turn the camara it should affect ALL my models? But with this code the camara only "cares" about the 3d cylinder, the plane is just completely still

private void OnDraw(object sender, GameTimerEventArgs e)
    {
        SharedGraphicsDeviceManager.Current.GraphicsDevice.Clear(Color.CornflowerBlue);

        foreach (ModelMesh mesh in cylinderModel.Meshes)
        {
            foreach (BasicEffect effect in mesh.Effects)
            {
                //effect.World = Matrix.CreateRotationX((float)e.TotalTime.TotalSeconds * 2);
                effect.View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
                effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f);

                effect.EnableDefaultLighting();
            }

            mesh.Draw();
        }

        //cameraPosition.Z -= 5.0f;
        _effect.World = Matrix.CreateRotationZ((MathHelper.ToRadians(((float)e.TotalTime.Milliseconds / 2) % 360)));
        foreach (EffectPass pass in _effect.CurrentTechnique.Passes)
        {
            pass.Apply();

            SharedGraphicsDeviceManager.Current.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, _vertices, 0, 1, VertexPositionColor.VertexDeclaration);
        }
    }

Is there a way to get the camara to affect all models?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

A camera is not an object in the game that once you add it it affect everything. You need to apply the camera to the things you want to draw in reference to the camera.

So just like the Cylinder is being drawn you set the effect.View, you need to do the same for the _effect.View.

    //Add this line
    _effect.View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
    _effect.World = Matrix.CreateRotationZ((MathHelper.ToRadians(((float)e.TotalTime.Milliseconds / 2) % 360)));
    foreach (EffectPass pass in _effect.CurrentTechnique.Passes)
    {
        pass.Apply();

        SharedGraphicsDeviceManager.Current.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, _vertices, 0, 1, VertexPositionColor.VertexDeclaration);
    }
share|improve this answer

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.