Announcement

Collapse
No announcement yet.

Mouse Camera

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mouse Camera

    I am trying to write a simple script for rotating the camera with the mouse without any buttons, Can anybody help me? Better solution or fixing my script.
    It works but the direction is acting weird. Also can you help me with the Y axes as well please!

    [SCRIPT]
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using WaveEngine.Common.Math;
    using WaveEngine.Framework;
    using WaveEngine.Framework.Graphics;
    using System.Windows.Forms;
    using WaveEngine.Framework.Services;
    using WaveEngine.Components.Transitions;


    namespace RELOCATIONProject.Behaviors
    {
    class InputBehavior : Behavior
    {
    [RequiredComponent]
    public Camera3D Camera;
    Vector3 camDir;
    double dir;
    float turnSpeed;

    public InputBehavior(float CamSpeed)
    {
    turnSpeed = CamSpeed;
    }

    protected override void Update(TimeSpan gameTime)
    {
    if (camDir == null)
    {
    camDir = new Vector3();
    camDir = Camera.LookAt;
    dir = 0;
    }

    if (WaveServices.Input.MouseState.X < 510)
    {
    dir-= turnSpeed;
    }else
    if (WaveServices.Input.MouseState.X > 514)
    {
    dir += turnSpeed;
    }
    else
    {
    dir = 0;
    }

    if (dir > 360)
    {
    dir -= 360;
    }
    if (dir < 0)
    {
    dir+= 360;
    }

    System.Drawing.Point P = new System.Drawing.Point();
    P.X = 512;
    P.Y = 384;
    Cursor.Position = P;

    float X = camDir.X;
    float Y = camDir.Y;
    float Z = camDir.Z;

    X = LengthDirX(dir, 500, Z, Camera.Position);
    Z = LengthDirZ(dir, 500, Z, Camera.Position);

    camDir.X = X;
    camDir.Z = Z;

    Camera.LookAt = camDir;

    }

    public float LengthDirX(double Direction, float x, float y, Vector3 Position){
    float _x = x;
    float _y = y;

    x = Position.X + (float)(_x * System.Math.Cos(Direction) - _y * System.Math.Sin(Direction));
    y = Position.Z + (float)(_x * System.Math.Sin(Direction) + _y * System.Math.Cos(Direction));

    return x;
    }

    public float LengthDirZ(double Direction, float x, float y, Vector3 Position)
    {
    float _x = x;
    float _y = y;

    x = Position.X + (float)(_x * System.Math.Cos(Direction) - _y * System.Math.Sin(Direction));
    y = Position.Z + (float)(_x * System.Math.Sin(Direction) + _y * System.Math.Cos(Direction));

    return y;
    }
    }
    }

    [/SCRIPT]

  • #2

    Hi ScifiDynamic,

    I can't understand what behavior you're trying to achieve with this component. Could you please elaborate a little bit more your "is acting weird" issue?

    Regards,
    VĂ­ctor Ferrer

    Comment


    • #3
      I am trying to make the camera rotate like a fps with the mouse, by moving the mouse left the camera rotates left, if the mouse moves right the camera turns right etc... Now it looks weird(so my formula does not work)

      Comment


      • #4
        Hi,

        OK, we understand you're looking for a similar behavior to the existing FreeCamera (same as a FPS).

        Since every Wave component source code is available at GitHub, please have a look to this file, there you'll find some hints:

        https://github.com/WaveEngine/Compon...eraBehavior.cs

        I hope it helps!,

        Marcos

        Comment


        • #5
          Yes that is what i want except i don't want the camera to move only when the mouse is clicked. I want it to move if the mouse is moved... But Thanks in advance
          Last edited by ScifiDynamic; 10-15-2014, 03:59 PM.

          Comment

          Working...
          X