1. Dashboard
  2. Forum
    1. Unerledigte Themen
  3. Mitglieder
    1. Letzte Aktivitäten
    2. Benutzer online
    3. Team-Mitglieder
    4. Trophäen
    5. Mitgliedersuche
  4. Tutorial Bereich
  • Anmelden
  • Registrieren
  • Suche
Alles
  • Alles
  • Seiten
  • Forum
  • Lexikon
  • Erweiterte Suche
  1. Informatik Forum
  2. Mitglieder
  3. Pasi

Beiträge von Pasi

  • Hand mit Kamera mitdrehen (mit XNA-Game-studio)

    • Pasi
    • 25. Oktober 2009 um 10:57

    Hallo!
    Ich hoffe ihr könnt mir helfen. Ich habe mit XNA-game-studio(Windows Game) mir bisher eine Kamera die sich der Maus nachbewegt gebastelt und ich kann Objekte darstellen. Nun möchte ich eine Hand haben die sich der Kamera nachbewegt(so dass man sie im Bild sieht) aber irgendwie habe ich keine Ahnung wie ich das realisieren kann, vielleicht kann mir ja jemand helfen.Mit dem Gameobject "neu" hätte ich schon experimentiert aber bin nicht weiter gekommen.
    Danke!

    Game1.cs:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Audio;
    using Microsoft.Xna.Framework.Content;
    using Microsoft.Xna.Framework.GamerServices;
    using Microsoft.Xna.Framework.Graphics;
    using Microsoft.Xna.Framework.Input;
    using Microsoft.Xna.Framework.Media;
    using Microsoft.Xna.Framework.Net;
    using Microsoft.Xna.Framework.Storage;

    namespace Destiny
    {
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;

    Vector3 cameraPosition;
    Vector3 cameraTarget;
    Vector3 cameraReference;

    float aspectRatio;
    float nearPlane;
    float farPlane;
    float fieldOfView;


    Matrix Projection;

    float cameraYaw;
    float cameraPitch;

    MouseState mStateCashe;
    Gameobject neu;


    public Game1()
    {
    graphics = new GraphicsDeviceManager(this);
    Content.RootDirectory = "Content";
    }

    /// <summary>
    /// Allows the game to perform any initialization it needs to before starting to run.
    /// This is where it can query for any required services and load any non-graphic
    /// related content. Calling base.Initialize will enumerate through any components
    /// and initialize them as well.
    /// </summary>
    protected override void Initialize()
    {
    // TODO: Add your initialization logic here
    nearPlane = 0.1f;
    farPlane = 1000.0f;
    fieldOfView = 45.0f;

    cameraPosition = new Vector3(0.0f, 0.0f, 0.0f);
    cameraReference = new Vector3(0.0f, 0.0f, 1.0f);
    cameraTarget = cameraReference + cameraPosition;

    cameraYaw = 0.0f;
    cameraPitch = 0.0f;

    aspectRatio = (float)graphics.GraphicsDevice.Viewport.Width / (float)graphics.GraphicsDevice.Viewport.Height;
    Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(fieldOfView), aspectRatio, nearPlane, farPlane);

    Mouse.SetPosition(graphics.GraphicsDevice.Viewport.Width / 2, graphics.GraphicsDevice.Viewport.Height / 2);
    mStateCashe = Mouse.GetState();
    neu = new Gameobject();

    neu.model = Content.Load<Model>("Models\\handnew");
    neu.scale = 0.01f;
    neu.position = new Vector3(0.5f, 0.5f, 0.5f);

    base.Initialize();
    }

    /// <summary>
    /// LoadContent will be called once per game and is the place to load
    /// all of your content.
    /// </summary>
    protected override void LoadContent()
    {
    // Create a new SpriteBatch, which can be used to draw textures.
    spriteBatch = new SpriteBatch(GraphicsDevice);

    // TODO: use this.Content to load your game content here
    }

    /// <summary>
    /// UnloadContent will be called once per game and is the place to unload
    /// all content.
    /// </summary>
    protected override void UnloadContent()
    {
    // TODO: Unload any non ContentManager content here
    }


    /// <summary>
    /// Allows the game to run logic such as updating the world,
    /// checking for collisions, gathering input, and playing audio.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Update(GameTime gameTime)
    {
    // Allows the game to exit
    if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
    this.Exit();

    // TODO: Add your update logic here
    UpdateCamera(gameTime);
    UpdateObject();

    base.Update(gameTime);
    }
    public void UpdateCamera(GameTime gameTime)
    {
    KeyboardState kState = Keyboard.GetState();
    MouseState mState = Mouse.GetState();

    float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

    Vector3 moveVector = Vector3.Zero;

    if (kState.IsKeyDown(Keys.W))
    {
    moveVector.Z += 3.0f * deltaTime;
    }
    if (kState.IsKeyDown(Keys.S))
    {
    moveVector.Z -= 3.0f * deltaTime;
    }
    if (kState.IsKeyDown(Keys.A))
    {
    moveVector.X += 3.0f * deltaTime;
    }
    if (kState.IsKeyDown(Keys.D))
    {
    moveVector.X -= 3.0f * deltaTime;
    }
    if (kState.IsKeyDown(Keys.Escape))
    {
    this.Exit();
    }

    float mouseX = mState.X - mStateCashe.X;
    float mouseY = mState.Y - mStateCashe.Y;

    cameraPitch += (mouseY * 0.4f) * deltaTime;
    cameraYaw -= (mouseX * 0.4f) * deltaTime;

    cameraPitch = MathHelper.Clamp(cameraPitch, MathHelper.ToRadians(-89.9f), MathHelper.ToRadians(89.9f));

    Mouse.SetPosition(graphics.GraphicsDevice.Viewport.Width / 2, graphics.GraphicsDevice.Viewport.Height / 2);

    Matrix cameraViewRotationMatrix = Matrix.CreateRotationX(cameraPitch) * Matrix.CreateRotationY(cameraYaw);
    Matrix cameraMoveRotationMatrix = Matrix.CreateRotationY(cameraYaw);
    Vector3 transformedCameraReference = Vector3.Transform(cameraReference, cameraViewRotationMatrix);
    cameraPosition += Vector3.Transform(moveVector, cameraMoveRotationMatrix);
    cameraTarget = transformedCameraReference + cameraPosition;
    base.Update(gameTime);

    }
    public void UpdateObject()
    {
    neu.position = cameraPosition + new Vector3(0.1f, -0.05f, 0.2f);
    neu.rotation.Y=-1.2f;//-1.2f
    neu.rotation.X=0.0f;//0.0f
    neu.rotation.Z = 1.4f;//1.4f

    neu.scale = 0.0004f;


    }

    /// <summary>
    /// This is called when the game should draw itself.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Draw(GameTime gameTime)
    {
    GraphicsDevice.Clear(Color.CornflowerBlue);
    DrawGameObject(neu);


    // TODO: Add your drawing code here

    base.Draw(gameTime);
    }
    void DrawGameObject(Gameobject gameobject)
    {
    foreach (ModelMesh mesh in gameobject.model.Meshes)
    {
    foreach (BasicEffect effect in mesh.Effects)
    {
    effect.EnableDefaultLighting();
    effect.PreferPerPixelLighting = true;

    effect.World =
    Matrix.CreateFromYawPitchRoll(gameobject.rotation.Y,
    gameobject.rotation.X,
    gameobject.rotation.Z) * Matrix.CreateScale(gameobject.scale) *
    Matrix.CreateTranslation(gameobject.position);
    effect.Projection = Projection;
    effect.View = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up);

    }
    mesh.Draw();
    }
    }
    }
    }
    Gameobject.cs:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Audio;
    using Microsoft.Xna.Framework.Content;
    using Microsoft.Xna.Framework.GamerServices;
    using Microsoft.Xna.Framework.Graphics;
    using Microsoft.Xna.Framework.Input;
    using Microsoft.Xna.Framework.Media;
    using Microsoft.Xna.Framework.Net;
    using Microsoft.Xna.Framework.Storage;

    namespace Destiny
    {
    class Gameobject
    {
    public Model model = null;
    public Vector3 position = Vector3.Zero;
    public Vector3 rotation = Vector3.Zero;
    public float scale = 1.0f;
    }
    }
    Program.cs:
    using System;

    namespace Destiny
    {
    static class Program
    {
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    static void Main(string[] args)
    {
    using (Game1 game = new Game1())
    {
    game.Run();
    }
    }
    }
    }

  • Internettseitensperre

    • Pasi
    • 14. Mai 2009 um 17:09

    thx

  • Internettseitensperre

    • Pasi
    • 13. Mai 2009 um 14:41

    Hi!
    Wenn ich von der Schule ins Internett gehe sind einige Seiten gesperrt.
    Wie kann ich diese Sperre umgehen? Gibt es Programme dafür?
    mfG

  • Online IDs

    • Pasi
    • 7. Mai 2009 um 11:06

    Meine id: pasi-aut
    meine spiele: bad company, cod4 ....

  • Berechnung

    • Pasi
    • 26. April 2009 um 20:26

    So danke für die mühe .
    Hab es schon geschafft.

    Code
    ypos -= std::cos(winkel * (pi / 180)) * -50 * timestep;

    So hätte es sein müssen , und ich hab pi nicht richtig deklariert.

  • Berechnung

    • Pasi
    • 25. April 2009 um 21:00

    Nein tut es leider nicht .
    Die Formel gibt mir die falschen Koordinaten aus.
    Dadurch hab ich dann falsche x- und y- Koordinaten .

    Wie würdest du die Koordinaten berechen , wenn du zum Beispiel eine Figur hast die sich dreht (also dann den Winkel hat)
    und wenn du dann "Vorwärts" drückst die Figur vorbewegt.

  • Berechnung

    • Pasi
    • 25. April 2009 um 16:22

    hmm ich weiß nicht genau was ich jetz postn soll...

    Zitat


    Als erster mal der Ausschnitt aus der cpp datei
    //
    // Aufgabe: Bewegung des Spielers
    //
    void CPlayer::ProcessMoving ()
    {
    // Nach links?
    if (g_pFramework->KeyDown (SDLK_LEFT))
    {
    // Spieler nach links drehen
    m_fPlayerRot -= 50.0f * g_pTimer->GetElapsed ();
    if (m_fPlayerRot < 0.0)
    {
    m_fPlayerRot = 355.0;
    }
    // Animieren
    //m_fAnimPhase -= 20.0f * g_pTimer->GetElapsed ();
    }
    // Nach rechts?
    else if (g_pFramework->KeyDown (SDLK_RIGHT))
    {
    // Spieler nach rechts drehen
    m_fPlayerRot += 50.0f * g_pTimer->GetElapsed ();
    if (m_fPlayerRot > 355.0)
    {
    m_fPlayerRot = 0.0;
    }

    // Animieren
    // m_fAnimPhase += 20.0f * g_pTimer->GetElapsed ();
    }
    // Nach oben?
    else if (g_pFramework->KeyDown (SDLK_UP))
    {
    m_fXPos += float(sin(double(m_fPlayerRot*(PI/180)))) *50.0f* g_pTimer->GetElapsed ();
    m_fYPos += float(cos(double(m_fPlayerRot*(PI/180)))) *(-50.0f)* g_pTimer->GetElapsed ();
    }

    //
    // Spieler wurde nicht bewegt
    else
    {
    // Animation zurück zum Ausgangspunkt
    if (m_fAnimPhase > 5.0f)
    m_fAnimPhase -= 20.0f * g_pTimer->GetElapsed ();
    if (m_fAnimPhase < 5.0f)
    m_fAnimPhase += 20.0f * g_pTimer->GetElapsed ();
    }
    }
    ´

    dann die hpp datei dazu

    #ifndef PLAYER_HPP
    #define PLAYER_HPP
    #include <list>
    #include "Sprite.hpp"
    class CPlayer
    {
    public:
    CPlayer ();
    void Init ();
    void Quit ();
    void Render ();
    void Update ();
    void Reset ();
    private:
    void ProcessMoving ();
    void CheckPosition ();
    CSprite *m_pSpritePlayer; // Sprite für Spieler
    float m_fXPos; // X-Position des Spielers
    float m_fYPos; // Y-Position des Spielers
    float m_fAnimPhase; // Aktuelle Animationsphase
    float m_fPlayerRot;
    };
    #endif

    und die Zeilen für die Zeit:

    #include "Timer.hpp"
    // Konstruktor
    //
    // Aufgabe: Initialisierung
    //
    CTimer::CTimer ()
    {
    // Initialisierung
    m_fCurTime = 0.0f;
    m_fLastTime = SDL_GetTicks() / 1000.0f;
    m_fElapsed = 0.0f;
    } // Konstruktor

    // Update
    //
    // Aufgabe: Timer updaten
    //
    void CTimer::Update ()
    {
    // Vergangene Zeit seit dem letzten Frame berechnen
    m_fCurTime = SDL_GetTicks() / 1000.0f;
    m_fElapsed = m_fCurTime - m_fLastTime;
    m_fLastTime = m_fCurTime;
    } // Update

    und dessen hpp datei:
    #ifndef TIMER_HPP
    #define TIMER_HPP
    #include <SDL.h>
    #include "singleton.hpp"
    #define g_pTimer CTimer::Get ()
    class CTimer : public TSingleton<CTimer>
    {
    public:
    CTimer ();
    void Update ();
    float GetElapsed () {return m_fElapsed;}
    private:
    float m_fElapsed; // Vergangene Zeit seit dem letzten Frame
    float m_fCurTime; // Aktuelle Zeit
    float m_fLastTime; // Zeit des letzten Frames
    };
    #endif



    Alles anzeigen



    ich hoffe das reicht

  • Berechnung

    • Pasi
    • 25. April 2009 um 14:43

    Ich hoffe ihr könnt mir weiterhelfen ..
    Ich habe die derzeitigen Koordinaten und den Winkel des Spielers gegeben und will ihn sich fortbewegen lassen.
    2Dimensional

    Dazu hätte ich die folgende Formeln genommen
    m_fXPOS += sin(winkel*(3,14159 / 180))*50* elapsedTime
    m_fYPOS += cos(winkel*(3,14159 / 180))*-50* elapsedTime

    Was ist hier falsch?
    danke im voraus

Rechtliches

Impressum

Datenschutzerklärung