rfmod/
vector.rs

1/*
2* Rust-FMOD - Copyright (c) 2016 Gomez Guillaume.
3*
4* The Original software, FmodEx library, is provided by FIRELIGHT TECHNOLOGIES.
5*
6* This software is provided 'as-is', without any express or implied warranty.
7* In no event will the authors be held liable for any damages arising from
8* the use of this software.
9*
10* Permission is granted to anyone to use this software for any purpose,
11* including commercial applications, and to alter it and redistribute it
12* freely, subject to the following restrictions:
13*
14* 1. The origin of this software must not be misrepresented; you must not claim
15*    that you wrote the original software. If you use this software in a product,
16*    an acknowledgment in the product documentation would be appreciated but is
17*    not required.
18*
19* 2. Altered source versions must be plainly marked as such, and must not be
20*    misrepresented as being the original software.
21*
22* 3. This notice may not be removed or altered from any source distribution.
23*/
24
25use ffi;
26use std::default::Default;
27
28pub fn from_ptr(vec: ffi::FMOD_VECTOR) -> Vector {
29    Vector {
30        x: vec.x,
31        y: vec.y,
32        z: vec.z,
33    }
34}
35
36pub fn get_ffi(vec: &Vector) -> ffi::FMOD_VECTOR {
37    ffi::FMOD_VECTOR {
38        x: vec.x,
39        y: vec.y,
40        z: vec.z,
41    }
42}
43
44#[derive(Debug, Clone, Copy)]
45/// Structure describing a point in 3D space.
46pub struct Vector {
47    /// X co-ordinate in 3D space.
48    pub x: f32,
49    /// Y co-ordinate in 3D space.
50    pub y: f32,
51    /// Z co-ordinate in 3D space.
52    pub z: f32,
53}
54
55impl Default for Vector {
56    fn default() -> Vector {
57        Vector::new()
58    }
59}
60
61impl Vector {
62    pub fn new() -> Vector {
63        Vector {
64            x: 0f32,
65            y: 0f32,
66            z: 0f32,
67        }
68    }
69}
70
71impl PartialEq for Vector {
72    fn eq(&self, other: &Vector) -> bool {
73        self.x == other.x && self.y == other.y && self.z == other.z
74    }
75
76    fn ne(&self, other: &Vector) -> bool {
77        !self.eq(other)
78    }
79}