コード例 #1
0
ファイル: Player.cs プロジェクト: starandserpent/Voxel-demo
    public override void _Ready()
    {
        GD.Print(ConfigManager.BASE_CONFIG_FILE_DIRECTORY_PATH);
        GD.Print(ConfigManager.BASE_DIRECTORY);
        GD.Print(ConfigManager.BASE_CONFIG_FILE_PATH);
        VisualServer.SetDebugGenerateWireframes(true);
        gameController = (GameController)FindParent("GameController");
        ray            = (RayCast)gameController.FindNode("Picker");
        camera         = (Camera)FindNode("Camera");
        fps            = (Label)camera.FindNode("FPS");
        position       = (Label)camera.FindNode("Position");
        chunks         = (Label)camera.FindNode("Chunks");
        vertices       = (Label)camera.FindNode("Vertices");
        memory         = (Label)camera.FindNode("Memory");
        speed          = (Label)camera.FindNode("Movement Speed");

        initialRotation = new Vector3();

        picker = gameController.GetPicker();

        Input.SetMouseMode(Input.MouseMode.Captured);

        TerraVector3 origin = Converter.ConvertVector(GlobalTransform.origin);
        TerraBasis   basis  = Converter.ConvertBasis(GlobalTransform.basis);

        marker = new LoadMarker(origin, basis);

        gameController.Prepare(camera, marker);
    }
コード例 #2
0
 public bool Equals(TerraVector3 origin, TerraBasis basis)
 {
     return(origin == this.origin &&
            basis.matrix[0] == this.basis.matrix[0] &&
            basis.matrix[1] == this.basis.matrix[1] &&
            basis.matrix[2] == this.basis.matrix[2]);
 }
コード例 #3
0
    public override void ChangePosition(TerraVector3 origin, TerraBasis basis)
    {
        this.origin = origin;
        this.basis  = basis;

        foreman.Release();
    }
コード例 #4
0
    public TerraVector3 ToGlobal(TerraVector3 coords)
    {
        TerraVector3 pos = new TerraVector3();

        pos.x = (basis.matrix[0].Dot(coords) + origin.x);
        pos.y = (basis.matrix[1].Dot(coords) + origin.y);
        pos.z = (basis.matrix[2].Dot(coords) + origin.z);
        return(pos);
    }
コード例 #5
0
ファイル: TerraBasis.cs プロジェクト: starandserpent/Terra
    public static TerraBasis InitEmpty()
    {
        TerraVector3[] matrix = new TerraVector3[3];

        matrix[0].x = 1;
        matrix[0].y = 0;
        matrix[0].z = 0;
        matrix[1].x = 0;
        matrix[1].y = 1;
        matrix[1].z = 0;
        matrix[2].x = 0;
        matrix[2].y = 0;
        matrix[2].z = 1;

        return(new TerraBasis(matrix));
    }
コード例 #6
0
ファイル: TerraBasis.cs プロジェクト: starandserpent/Terra
    public TerraBasis(TerraVector3 euler)
    {
        matrix = new TerraVector3[3];

        float c, s;

        c = (float)Math.Cos(euler.x);
        s = (float)Math.Sin(euler.x);
        TerraBasis xmat = new TerraBasis(1.0f, 0.0f, 0.0f, 0.0f, c, -s, 0.0f, s, c);

        c = (float)Math.Cos(euler.y);
        s = (float)Math.Sin(euler.y);
        TerraBasis ymat = new TerraBasis(c, 0.0f, s, 0.0f, 1.0f, 0.0f, -s, 0.0f, c);

        c = (float)Math.Cos(euler.z);
        s = (float)Math.Sin(euler.z);
        TerraBasis zmat = new TerraBasis(c, -s, 0.0f, s, c, 0.0f, 0.0f, 0.0f, 1.0f);

        //optimizer will optimize away all this anyway
        this = ymat * xmat * zmat;
    }
コード例 #7
0
ファイル: TerraBasis.cs プロジェクト: starandserpent/Terra
    public TerraBasis(TerraVector3 axis, float radians)
    {
        matrix = new TerraVector3[3];

        TerraVector3 axisSQ = new TerraVector3(axis.x * axis.x, axis.y * axis.y, axis.z * axis.z);

        float cosine = (float)Math.Cos(radians);
        float sine   = (float)Math.Sin(radians);

        matrix[0].x = axisSQ.x + cosine * (1.0f - axisSQ.x);
        matrix[0].y = axis.x * axis.y * (1.0f - cosine) - axis.z * sine;
        matrix[0].z = axis.z * axis.x * (1.0f - cosine) + axis.y * sine;

        matrix[1].x = axis.x * axis.y * (1.0f - cosine) + axis.z * sine;
        matrix[1].y = axisSQ.y + cosine * (1.0f - axisSQ.y);
        matrix[1].z = axis.y * axis.z * (1.0f - cosine) - axis.x * sine;

        matrix[2].x = axis.z * axis.x * (1.0f - cosine) - axis.y * sine;
        matrix[2].y = axis.y * axis.z * (1.0f - cosine) + axis.x * sine;
        matrix[2].z = axisSQ.z + cosine * (1.0f - axisSQ.z);
    }
コード例 #8
0
ファイル: Player.cs プロジェクト: starandserpent/Voxel-demo
    public override void _PhysicsProcess(float delta)
    {
        if (ray.IsColliding())
        {
            picker.Pick(ray.GetCollisionPoint(), ray.GetCollisionNormal());
            ray.Enabled = false;
        }

        chunks.Text   = "Chunks: " + Foreman.chunksPlaced;
        vertices.Text = "Vertices: " + Performance.GetMonitor(Performance.Monitor.RenderVerticesInFrame);
        fps.Text      = "FPS: " + Performance.GetMonitor(Performance.Monitor.TimeFps);
        position.Text = "X: " + GlobalTransform.origin.x + "Y: " +
                        GlobalTransform.origin.y + "Z:" + GlobalTransform.origin.z;
        memory.Text = "Memory: " + GC.GetTotalMemory(false) / (1048576) + "MB";

        Vector3 velocity = new Vector3();

        if (Input.IsActionPressed("walk_left"))
        {
            motion.x = 1;
        }
        else if (Input.IsActionPressed("walk_right"))
        {
            motion.x = -1;
        }
        else
        {
            motion.x = 0;
        }

        if (Input.IsActionPressed("walk_forward"))
        {
            motion.z = -1;
        }
        else if (Input.IsActionPressed("walk_backward"))
        {
            motion.z = 1;
        }
        else
        {
            motion.z = 0;
        }

        if (Input.IsActionPressed("move_up"))
        {
            motion.y = 1;
        }
        else if (Input.IsActionPressed("move_down"))
        {
            motion.y = -1;
        }
        else
        {
            motion.y = 0;
        }

        motion = motion.Normalized();

        if (Input.IsActionPressed("move_speed"))
        {
            motion *= 2;
        }

        motion = motion.Rotated(new Vector3(0, 1, 0), Rotation.y - initialRotation.y)
                 .Rotated(new Vector3(1, 0, 0), (float)Math.Cos(Rotation.y) * Rotation.x)
                 .Rotated(new Vector3(0, 0, 1), -(float)Math.Sin(Rotation.y) * Rotation.x);

        velocity = motion * MOVE_SPEED;

        speed.Text = "Movement Speed: " + velocity.Length() + "m/s";

        Vector3 translation = new Vector3(Translation.x + velocity.x, Translation.y + velocity.y,
                                          Translation.z + velocity.z);

        Translation = translation;

        TerraVector3 origin = Converter.ConvertVector(translation);

        marker.MoveTo(origin);
    }
コード例 #9
0
 public float Dot(TerraVector3 b)
 {
     return((x * b.x) + (y * b.y) + (z * b.z));
 }
コード例 #10
0
 public void MoveTo(TerraVector3 origin)
 {
     this.origin = origin;
     foreman.Release();
 }
コード例 #11
0
 public override void Move(TerraVector3 origin)
 {
     this.origin = this.origin + origin;
     foreman.Release();
 }
コード例 #12
0
 public LoadMarker(TerraVector3 origin)
 {
     this.origin = origin;
     this.basis  = TerraBasis.InitEmpty();
 }
コード例 #13
0
 public LoadMarker(TerraVector3 origin, TerraBasis basis)
 {
     this.origin = origin;
     this.basis  = basis;
 }
コード例 #14
0
ファイル: TerraBasis.cs プロジェクト: starandserpent/Terra
 public float Tdoty(TerraVector3 v)
 {
     return(matrix[0].y * v.x + matrix[1].y * v.y + matrix[2].y * v.z);
 }
コード例 #15
0
 public abstract void ChangePosition(TerraVector3 origin, TerraBasis basis);
コード例 #16
0
 public abstract void Move(TerraVector3 origin);