Forum
Contact





DirectX using C#
DirectX using C++
DirectX using Visual Basic



Latest Forum posts

 Tutorial 3 for Windows Phone 7
  Posted by: Anonymous
  When: 20/05/2013 at 02:30:13

 No download link for 2d series: shooter
  Posted by: zaboleq
  When: 07/05/2013 at 15:46:28

 Collision Class?
  Posted by: Anonymous
  When: 05/05/2013 at 19:03:59

 stack overflow
  Posted by: cityguy
  When: 07/04/2013 at 01:58:38

 Meshes looks strange.
  Posted by: ab_saratov
  When: 01/04/2013 at 04:31:08

 Lamppost Not loaded
  Posted by: Anonymous
  When: 22/03/2013 at 06:43:52

 Collision Class?
  Posted by: Da_Boom
  When: 21/03/2013 at 01:23:09

 Math boggles me
  Posted by: cityguy
  When: 17/03/2013 at 03:44:48

 Collision Class?
  Posted by: Da_Boom
  When: 16/03/2013 at 03:44:42

 Tree update
  Posted by: Anonymous
  When: 15/03/2013 at 21:11:22

 XNA 4.0
  Posted by: Anonymous
  When: 15/03/2013 at 19:43:57

 Error when I try to run.
  Posted by: Anonymous
  When: 15/03/2013 at 19:21:06

 Error With the Effect File
  Posted by: Anonymous
  When: 15/03/2013 at 18:21:01

 Can only get shadowmap
  Posted by: Anonymous
  When: 15/03/2013 at 15:48:52

 Vertex and Pixel Shader Versions?
  Posted by: Anonymous
  When: 15/03/2013 at 15:07:16

 Unsupported properties
  Posted by: Anonymous
  When: 15/03/2013 at 14:23:00

 Problem Loading Skybox
  Posted by: Rana
  When: 15/03/2013 at 10:34:45

 Black Screen Of Death - Help!
  Posted by: Anonymous
  When: 15/03/2013 at 03:43:43

 2.0 anyone?
  Posted by: Anonymous
  When: 15/03/2013 at 02:19:48

 Defitinition of tha rotation axis
  Posted by: Anonymous
  When: 15/03/2013 at 00:55:14




Topic: Camera Moving around an Object



  
Goto parent category
  
Create a new user account


   Camera Moving around an Object
 Poster : h0schi
 Posts: 6
 Country : Germany
 City: Dortmund

  
Posted by h0schi on 09/01/2008 at 14:02:57
Hi there,

can anyone post me in the direction of creating a camera moving around an object ?.

let me say. i got an ocean and a ship on it. i want the camera move around the ship. so you can see from all sides.

i tryed rotating Camera with Quaternion but cant make it work.

Any hints or Links would be very nice.

Thx guys.

And by the way, this tuts are great!.
 Poster : tweety
 Posts: 23
 Country : Austria
 City: Hallein

  
Posted by tweety on 09/01/2008 at 15:21:01
Hi there!

I´ve made a short Windows Game for you.
Additionally you will need
a .x file (I think you will use your ship)
a texture file (I use the clouds.jpg) and
the "Series4Effects.fx" file.

You can get all these items from the Project4 download.

The solution for problem is to move the camera in a circle around your ship. Then set the "LookAt" at your ship....DONE!


try this code:


#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion

namespace WindowsGame7
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        ContentManager content;
        private GraphicsDevice device;
        private Effect effect;

        Model FirstCube = new Model();
        
        private Matrix viewMatrix;
        private Matrix projectionMatrix;
        private int degrees;

        private Texture2D CubeTexture;
        Vector3 center = new Vector3(0, 0, 0);

        private Model FillModelFromFile(string asset)
        {
            Model mod = content.Load<Model>(asset);
            foreach (ModelMesh modmesh in mod.Meshes)
                foreach (ModelMeshPart modmeshpart in modmesh.MeshParts)
                    modmeshpart.Effect = effect.Clone(device);
            return mod;
        }


        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            content = new ContentManager(Services);
        }

        protected override void Initialize()
        {
            SetUpXNADevice();
            FirstCube = FillModelFromFile("Cube");
            CubeTexture = content.Load<Texture2D>("clouds");

            base.Initialize();
        }


        private void SetUpXNADevice()
        {
            device = graphics.GraphicsDevice;

            graphics.PreferredBackBufferWidth = 750;
            graphics.PreferredBackBufferHeight = 750;
            graphics.IsFullScreen = false;
            graphics.ApplyChanges();
            //Window.Title = "";

            effect = content.Load<Effect>("Series4Effects");

        }

        protected override void UnloadGraphicsContent(bool unloadAllContent)
        {
            if (unloadAllContent)
            {
                content.Unload();
            }
        }

        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            UpdateCamera();


            base.Update(gameTime);
        }
      
        
        private void UpdateCamera()
        {
            //let the camera look at the center (also the position of the cube)
            center = new Vector3(0, 0, 0);
            float radius = 300;
            float altitude = 50;
            
            //calculate campos by using the 2d formula: x=r*cos(degrees)    y=r*sin(degrees)
            Vector3 campos = new Vector3((float)(radius * Math.Cos((Math.PI/180)*degrees)), (float)(radius * Math.Sin((Math.PI/180)*degrees)), altitude);

            //add 1 degree per frame
            degrees++;
            
            Vector3 camup = new Vector3(0, 0, 1);

            viewMatrix = Matrix.CreateLookAt(campos, center, camup);
            projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, ((float)this.Window.ClientBounds.Width) / ((float)this.Window.ClientBounds.Height), 1.0f, 1000.0f);
        }

        private void DrawFirstCube()
        {
            
            Matrix worldMatrix = Matrix.CreateScale(0.1f) * Matrix.CreateTranslation(center);

            foreach (ModelMesh modmesh in FirstCube.Meshes)
            {
                foreach (Effect currenteffect in modmesh.Effects)
                {

                    currenteffect.Parameters["xEnableLighting"].SetValue(true);
                    currenteffect.Parameters["xLightDirection"].SetValue(new Vector3(100, 0, 0));
                    currenteffect.Parameters["xAmbient"].SetValue(0.8f);
                    currenteffect.CurrentTechnique = currenteffect.Techniques["Textured"];
                    currenteffect.Parameters["xWorld"].SetValue(worldMatrix);
                    currenteffect.Parameters["xView"].SetValue(viewMatrix);
                    currenteffect.Parameters["xProjection"].SetValue(projectionMatrix);
                    currenteffect.Parameters["xTexture"].SetValue(CubeTexture);

                }
                modmesh.Draw();
            }
        }

      

        protected override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.Clear(Color.Black);

            DrawFirstCube();
            base.Draw(gameTime);
        }
    }
}



Please inform me if this was helpful!

Grüße aus Österreich
Tweety
 Poster : h0schi
 Posts: 6
 Country : Germany
 City: Dortmund

  
Posted by h0schi on 10/01/2008 at 04:15:16
Thx, iam at work now, but give it a try later.

Schönen Gruß nach Österreich.
 Poster : h0schi
 Posts: 6
 Country : Germany
 City: Dortmund

  
Posted by h0schi on 10/01/2008 at 05:43:37
Andere Frage, muss ich die Projectionsmatrix jedesmal neu setzen ? Normal reicht doch einmal oder ?

Danke
 Poster : h0schi
 Posts: 6
 Country : Germany
 City: Dortmund

  
Posted by h0schi on 10/01/2008 at 05:44:24
Andere Frage, muss ich die Projectionsmatrix jedesmal neu setzen ? Normal reicht doch einmal oder ?

Danke
 Poster : tweety
 Posts: 23
 Country : Austria
 City: Hallein

  
Posted by tweety on 10/01/2008 at 10:40:15
Hi!

Natürlich reicht es die Projektionsmatrix nur einmal zu setzen...gut beobachtet! =)

------------------------------------------------
You´re right. You do not need to reset the ProjectionMatrix during the Update method... god job!

Tweety
 Poster : h0schi
 Posts: 6
 Country : Germany
 City: Dortmund

  
Posted by h0schi on 10/01/2008 at 12:00:25
Hi,

ich schreib mal in englisch damit die anderen es auch verstehen hier.

I tried the example but the camera moves around and the object also is rotation.

Example.


A ship move from right to left..

<------->   Ship

i dont want that the ship itself rotates. like this. I mean the view to that ship. ship of course stays at his world coordinates. but the look is wrong.

<
\
  \
   \
    >

It stays the same all time. moving from left to right.

The camera should then be able to move around that ship, but ship stays straight <------>.

so i can see the front. the other side of ship. back etc...

Many thx again for helping.

 Poster : tweety
 Posts: 23
 Country : Austria
 City: Hallein

  
Posted by tweety on 10/01/2008 at 12:42:32
I´m sorry...but I can´t get the problem properly...

ship....shouldn´d move
camera...should move around the ship (cirle?, ellipse?)
or did I get this wrong...


In fact in this example the cube/model isn´t moving at all... the camera is rotating around a Vector/Point(0,0,0) called "center". It only seem that the cube is rotating...

Try to replace this vector with the shipcenter:

e.g. center = shipcenter; (use the correct
Vector3 of course)
instead of center = new Vector3(0,0,0);


if you still have problems let me know...

you also can mail me your project to:

dirty_fighting<at>gmx<dot>at

I´ll have a look at it if you want

greetz
tweety






  
Post a new reply
 





Google
 
Web www.riemers.net
If you appreciate the amount of time I spend creating and updating
these pages, feel free to donate -- any amount is welcome !
- Website design & DirectX code : Riemer Grootjans -
©2006 Riemer Grootjans


News
Home
Forum
XNA 2.0 Recipes Book (8)
XNA 3.0 Recipes Book (8)
Downloads
Extra Reading (3)
Matrices: geometrical
Matrix Mathematics
Homogenous matrices
Community Projects (1)
Tutorials (160)
XNA 4.0 using C# (89)
DirectX using C# (54)
Series 1:Terrain (14)
Opening a window
Linking to the Device
Drawing a triangle
Camera
Rotation - Translation
Indices
Terrain creation
Terrain from file
DirectInput
Importing bmp files
Colored vertices
DirectX Light basics
Mesh creation
Mesh lighting
Series 2: Flightsim (19)
Series 3: HLSL (19)
Short Tuts (2)
Resizing problem
Checking Device caps
DirectX using C++ (15)
DirectX using VB (2)