Skip to content

Commit

Permalink
Update to the last Rust.
Browse files Browse the repository at this point in the history
Version of rustc: 0.10-pre (123eb4e 2014-02-28 19:01:38 -0800)
  • Loading branch information
sebcrozet committed Mar 1, 2014
1 parent 6a58314 commit f381891
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 69 deletions.
44 changes: 22 additions & 22 deletions examples/relativity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ struct InertialCamera {
}

impl InertialCamera {
pub fn new(fov: f32, znear: f32, zfar: f32, eye: Vec3<f32>, at: Vec3<f32>) -> InertialCamera {
fn new(fov: f32, znear: f32, zfar: f32, eye: Vec3<f32>, at: Vec3<f32>) -> InertialCamera {
let mut fp = FirstPerson::new_with_frustrum(fov, znear, zfar, eye, at);

fp.set_move_step(0.0);
Expand Down Expand Up @@ -185,7 +185,7 @@ struct Context {
}

impl Context {
pub fn new(speed_of_light: f32, speed_of_player: Vec3<f32>, position: Vec3<f32>) -> Context {
fn new(speed_of_light: f32, speed_of_player: Vec3<f32>, position: Vec3<f32>) -> Context {
Context {
speed_of_light: speed_of_light,
speed_of_player: speed_of_player,
Expand All @@ -195,28 +195,28 @@ impl Context {
}

/// The default material used to draw objects.
pub struct RelativisticMaterial {
priv context: RWArc<Context>,
priv shader: Shader,
priv pos: ShaderAttribute<Vec3<f32>>,
priv normal: ShaderAttribute<Vec3<f32>>,
priv tex_coord: ShaderAttribute<Vec2<f32>>,
priv light: ShaderUniform<Vec3<f32>>,
priv color: ShaderUniform<Vec3<f32>>,
priv transform: ShaderUniform<Mat4<f32>>,
priv scale: ShaderUniform<Mat3<f32>>,
priv ntransform: ShaderUniform<Mat3<f32>>,
priv view: ShaderUniform<Mat4<f32>>,
priv tex: ShaderUniform<GLuint>,
priv light_vel: ShaderUniform<GLfloat>,
priv rel_vel: ShaderUniform<Vec3<f32>>,
priv rot: ShaderUniform<Rot3<f32>>,
priv player_position: ShaderUniform<Vec3<f32>>
struct RelativisticMaterial {
context: RWArc<Context>,
shader: Shader,
pos: ShaderAttribute<Vec3<f32>>,
normal: ShaderAttribute<Vec3<f32>>,
tex_coord: ShaderAttribute<Vec2<f32>>,
light: ShaderUniform<Vec3<f32>>,
color: ShaderUniform<Vec3<f32>>,
transform: ShaderUniform<Mat4<f32>>,
scale: ShaderUniform<Mat3<f32>>,
ntransform: ShaderUniform<Mat3<f32>>,
view: ShaderUniform<Mat4<f32>>,
tex: ShaderUniform<GLuint>,
light_vel: ShaderUniform<GLfloat>,
rel_vel: ShaderUniform<Vec3<f32>>,
rot: ShaderUniform<Rot3<f32>>,
player_position: ShaderUniform<Vec3<f32>>
}

impl RelativisticMaterial {
/// Creates a new `RelativisticMaterial`.
pub fn new(context: RWArc<Context>) -> RelativisticMaterial {
fn new(context: RWArc<Context>) -> RelativisticMaterial {
// load the shader
let mut shader = Shader::new_from_str(RELATIVISTIC_VERTEX_SRC, RELATIVISTIC_FRAGMENT_SRC);

Expand Down Expand Up @@ -326,7 +326,7 @@ impl Material for RelativisticMaterial {
}
}

pub static RELATIVISTIC_VERTEX_SRC: &'static str =
static RELATIVISTIC_VERTEX_SRC: &'static str =
"#version 120
attribute vec3 position;
attribute vec3 normal;
Expand Down Expand Up @@ -382,7 +382,7 @@ pub static RELATIVISTIC_VERTEX_SRC: &'static str =
tex_coord = tex_coord_v;
}";

pub static RELATIVISTIC_FRAGMENT_SRC: &'static str =
static RELATIVISTIC_FRAGMENT_SRC: &'static str =
"#version 120
uniform vec3 color;
uniform vec3 light_position;
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ I’d love to see people improving this library for their own needs. However, ke
#[deny(missing_doc)];
#[deny(unused_result)];
#[deny(unnecessary_typecast)];
#[deny(visible_private_types)];
#[feature(globs)];
#[feature(macro_rules)];
#[feature(managed_boxes)];
Expand Down
27 changes: 12 additions & 15 deletions src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ use light::Light;
#[path = "error.rs"]
mod error;

type Transform3d = Iso3<f32>;
type Scale3d = Mat3<GLfloat>;

/// Set of data identifying a scene node.
pub struct ObjectData {
priv scale: Scale3d,
priv transform: Transform3d,
priv scale: Mat3<GLfloat>,
priv transform: Iso3<f32>,
priv texture: Rc<Texture>,
priv color: Vec3<f32>,
priv visible: bool,
Expand All @@ -27,12 +24,12 @@ pub struct ObjectData {

impl ObjectData {
/// The scale matrix of this object.
pub fn scale<'a>(&'a self) -> &'a Scale3d {
pub fn scale<'a>(&'a self) -> &'a Mat3<GLfloat> {
&'a self.scale
}

/// The transformation matrix (scaling excluded) of this object.
pub fn transform<'a>(&'a self) -> &'a Transform3d {
pub fn transform<'a>(&'a self) -> &'a Iso3<f32> {
&'a self.transform
}

Expand Down Expand Up @@ -314,39 +311,39 @@ impl Object {
}
}

impl Transformation<Transform3d> for Object {
impl Transformation<Iso3<f32>> for Object {
#[inline]
fn transformation(&self) -> Transform3d {
fn transformation(&self) -> Iso3<f32> {
self.data.borrow().borrow().get().transform.clone()
}

#[inline]
fn inv_transformation(&self) -> Transform3d {
fn inv_transformation(&self) -> Iso3<f32> {
self.data.borrow().borrow().get().transform.inv_transformation()
}

#[inline]
fn append_transformation(&mut self, t: &Transform3d) {
fn append_transformation(&mut self, t: &Iso3<f32>) {
self.data.borrow().borrow_mut().get().transform.append_transformation(t)
}

#[inline]
fn append_transformation_cpy(_: &Object, _: &Transform3d) -> Object {
fn append_transformation_cpy(_: &Object, _: &Iso3<f32>) -> Object {
fail!("Cannot clone an object.")
}

#[inline]
fn prepend_transformation(&mut self, t: &Transform3d) {
fn prepend_transformation(&mut self, t: &Iso3<f32>) {
self.data.borrow().borrow_mut().get().transform.prepend_transformation(t)
}

#[inline]
fn prepend_transformation_cpy(_: &Object, _: &Transform3d) -> Object {
fn prepend_transformation_cpy(_: &Object, _: &Iso3<f32>) -> Object {
fail!("Cannot clone an object.")
}

#[inline]
fn set_transformation(&mut self, t: Transform3d) {
fn set_transformation(&mut self, t: Iso3<f32>) {
self.data.borrow().borrow_mut().get().transform.set_transformation(t)
}
}
Expand Down
58 changes: 26 additions & 32 deletions src/resource/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,27 @@ use nalgebra::na;
use resource::ShaderAttribute;
use resource::gpu_vector::{GPUVector, DynamicDraw, StaticDraw, ArrayBuffer, ElementArrayBuffer};

type Coord = Vec3<GLfloat>;
type Normal = Vec3<GLfloat>;
type UV = Vec2<GLfloat>;
type Vertex = GLuint;
type Face = Vec3<Vertex>;

#[path = "../error.rs"]
mod error;

/// Aggregation of vertices, indices, normals and texture coordinates.
///
/// It also contains the GPU location of those buffers.
pub struct Mesh {
priv coords: RWArc<GPUVector<Coord>>,
priv faces: RWArc<GPUVector<Face>>,
priv normals: RWArc<GPUVector<Normal>>,
priv uvs: RWArc<GPUVector<UV>>
priv coords: RWArc<GPUVector<Vec3<GLfloat>>>,
priv faces: RWArc<GPUVector<Vec3<GLuint>>>,
priv normals: RWArc<GPUVector<Vec3<GLfloat>>>,
priv uvs: RWArc<GPUVector<Vec2<GLfloat>>>
}

impl Mesh {
/// Creates a new mesh.
///
/// If the normals and uvs are not given, they are automatically computed.
pub fn new(coords: ~[Coord],
faces: ~[Face],
normals: Option<~[Normal]>,
uvs: Option<~[UV]>,
pub fn new(coords: ~[Vec3<GLfloat>],
faces: ~[Vec3<GLuint>],
normals: Option<~[Vec3<GLfloat>]>,
uvs: Option<~[Vec2<GLfloat>]>,
dynamic_draw: bool)
-> Mesh {
let normals = match normals {
Expand All @@ -58,10 +52,10 @@ impl Mesh {
}

/// Creates a new mesh. Arguments set to `None` are automatically computed.
pub fn new_with_gpu_vectors(coords: RWArc<GPUVector<Coord>>,
faces: RWArc<GPUVector<Face>>,
normals: RWArc<GPUVector<Normal>>,
uvs: RWArc<GPUVector<UV>>)
pub fn new_with_gpu_vectors(coords: RWArc<GPUVector<Vec3<GLfloat>>>,
faces: RWArc<GPUVector<Vec3<GLuint>>>,
normals: RWArc<GPUVector<Vec3<GLfloat>>>,
uvs: RWArc<GPUVector<Vec2<GLfloat>>>)
-> Mesh {
Mesh {
coords: coords,
Expand All @@ -72,17 +66,17 @@ impl Mesh {
}

/// Binds this mesh vertex coordinates buffer to a vertex attribute.
pub fn bind_coords(&mut self, coords: &mut ShaderAttribute<Coord>) {
pub fn bind_coords(&mut self, coords: &mut ShaderAttribute<Vec3<GLfloat>>) {
self.coords.write(|c| coords.bind(c));
}

/// Binds this mesh vertex normals buffer to a vertex attribute.
pub fn bind_normals(&mut self, normals: &mut ShaderAttribute<Normal>) {
pub fn bind_normals(&mut self, normals: &mut ShaderAttribute<Vec3<GLfloat>>) {
self.normals.write(|n| normals.bind(n));
}

/// Binds this mesh vertex uvs buffer to a vertex attribute.
pub fn bind_uvs(&mut self, uvs: &mut ShaderAttribute<UV>) {
pub fn bind_uvs(&mut self, uvs: &mut ShaderAttribute<Vec2<GLfloat>>) {
self.uvs.write(|u| uvs.bind(u));
}

Expand All @@ -93,9 +87,9 @@ impl Mesh {

/// Binds this mesh buffers to vertex attributes.
pub fn bind(&mut self,
coords: &mut ShaderAttribute<Coord>,
normals: &mut ShaderAttribute<Normal>,
uvs: &mut ShaderAttribute<UV>) {
coords: &mut ShaderAttribute<Vec3<GLfloat>>,
normals: &mut ShaderAttribute<Vec3<GLfloat>>,
uvs: &mut ShaderAttribute<Vec2<GLfloat>>) {
self.bind_coords(coords);
self.bind_normals(normals);
self.bind_uvs(uvs);
Expand Down Expand Up @@ -128,27 +122,27 @@ impl Mesh {
}

/// This mesh faces.
pub fn faces<'a>(&'a self) -> &'a RWArc<GPUVector<Face>> {
pub fn faces<'a>(&'a self) -> &'a RWArc<GPUVector<Vec3<GLuint>>> {
&'a self.faces
}

/// This mesh normals.
pub fn normals<'a>(&'a self) -> &'a RWArc<GPUVector<Normal>> {
pub fn normals<'a>(&'a self) -> &'a RWArc<GPUVector<Vec3<GLfloat>>> {
&'a self.normals
}

/// This mesh vertex coordinates.
pub fn coords<'a>(&'a self) -> &'a RWArc<GPUVector<Coord>> {
pub fn coords<'a>(&'a self) -> &'a RWArc<GPUVector<Vec3<GLfloat>>> {
&'a self.coords
}

/// This mesh texture coordinates.
pub fn uvs<'a>(&'a self) -> &'a RWArc<GPUVector<UV>> {
pub fn uvs<'a>(&'a self) -> &'a RWArc<GPUVector<Vec2<GLfloat>>> {
&'a self.uvs
}

/// Computes normals from a set of faces.
pub fn compute_normals_array(coordinates: &[Coord], faces: &[Face]) -> ~[Normal] {
pub fn compute_normals_array(coordinates: &[Vec3<GLfloat>], faces: &[Vec3<GLuint>]) -> ~[Vec3<GLfloat>] {
let mut res = ~[];

Mesh::compute_normals(coordinates, faces, &mut res);
Expand All @@ -157,9 +151,9 @@ impl Mesh {
}

/// Computes normals from a set of faces.
pub fn compute_normals(coordinates: &[Coord],
faces: &[Face],
normals: &mut ~[Normal]) {
pub fn compute_normals(coordinates: &[Vec3<GLfloat>],
faces: &[Vec3<GLuint>],
normals: &mut ~[Vec3<GLfloat>]) {
let mut divisor = vec::from_elem(coordinates.len(), 0f32);

// Shrink the output buffer if it is too big.
Expand Down

0 comments on commit f381891

Please sign in to comment.