Add cone support.
This commit is contained in:
@@ -19,7 +19,7 @@ impl Capsule {
|
||||
window: &mut window::Window,
|
||||
) -> Capsule {
|
||||
let r = capsule.radius;
|
||||
let h = capsule.half_height() * 2.0;
|
||||
let h = capsule.half_height * 2.0;
|
||||
#[cfg(feature = "dim2")]
|
||||
let node = window.add_planar_capsule(r, h);
|
||||
#[cfg(feature = "dim3")]
|
||||
|
||||
74
src_testbed/objects/cone.rs
Normal file
74
src_testbed/objects/cone.rs
Normal file
@@ -0,0 +1,74 @@
|
||||
use crate::objects::node::{self, GraphicsNode};
|
||||
use kiss3d::window::Window;
|
||||
use na::Point3;
|
||||
use rapier::geometry::{ColliderHandle, ColliderSet};
|
||||
use rapier::math::Isometry;
|
||||
|
||||
pub struct Cone {
|
||||
color: Point3<f32>,
|
||||
base_color: Point3<f32>,
|
||||
gfx: GraphicsNode,
|
||||
collider: ColliderHandle,
|
||||
}
|
||||
|
||||
impl Cone {
|
||||
pub fn new(
|
||||
collider: ColliderHandle,
|
||||
half_height: f32,
|
||||
radius: f32,
|
||||
color: Point3<f32>,
|
||||
window: &mut Window,
|
||||
) -> Cone {
|
||||
#[cfg(feature = "dim2")]
|
||||
let node = window.add_rectangle(radius, half_height);
|
||||
#[cfg(feature = "dim3")]
|
||||
let node = window.add_cone(radius, half_height * 2.0);
|
||||
|
||||
let mut res = Cone {
|
||||
color,
|
||||
base_color: color,
|
||||
gfx: node,
|
||||
collider,
|
||||
};
|
||||
|
||||
// res.gfx.set_texture_from_file(&Path::new("media/kitten.png"), "kitten");
|
||||
res.gfx.set_color(color.x, color.y, color.z);
|
||||
res
|
||||
}
|
||||
|
||||
pub fn select(&mut self) {
|
||||
self.color = Point3::new(1.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
pub fn unselect(&mut self) {
|
||||
self.color = self.base_color;
|
||||
}
|
||||
|
||||
pub fn set_color(&mut self, color: Point3<f32>) {
|
||||
self.gfx.set_color(color.x, color.y, color.z);
|
||||
self.color = color;
|
||||
self.base_color = color;
|
||||
}
|
||||
|
||||
pub fn update(&mut self, colliders: &ColliderSet) {
|
||||
node::update_scene_node(
|
||||
&mut self.gfx,
|
||||
colliders,
|
||||
self.collider,
|
||||
&self.color,
|
||||
&Isometry::identity(),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn scene_node(&self) -> &GraphicsNode {
|
||||
&self.gfx
|
||||
}
|
||||
|
||||
pub fn scene_node_mut(&mut self) -> &mut GraphicsNode {
|
||||
&mut self.gfx
|
||||
}
|
||||
|
||||
pub fn object(&self) -> ColliderHandle {
|
||||
self.collider
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
pub mod ball;
|
||||
pub mod box_node;
|
||||
pub mod capsule;
|
||||
pub mod cone;
|
||||
pub mod convex;
|
||||
pub mod cylinder;
|
||||
pub mod heightfield;
|
||||
|
||||
@@ -10,6 +10,7 @@ use crate::objects::mesh::Mesh;
|
||||
use kiss3d::window::Window;
|
||||
use na::Point3;
|
||||
|
||||
use crate::objects::cone::Cone;
|
||||
use crate::objects::cylinder::Cylinder;
|
||||
use rapier::geometry::{ColliderHandle, ColliderSet};
|
||||
use rapier::math::Isometry;
|
||||
@@ -30,6 +31,7 @@ pub enum Node {
|
||||
Mesh(Mesh),
|
||||
Convex(Convex),
|
||||
Cylinder(Cylinder),
|
||||
Cone(Cone),
|
||||
}
|
||||
|
||||
impl Node {
|
||||
@@ -45,6 +47,7 @@ impl Node {
|
||||
Node::Mesh(ref mut n) => n.select(),
|
||||
Node::Convex(ref mut n) => n.select(),
|
||||
Node::Cylinder(ref mut n) => n.select(),
|
||||
Node::Cone(ref mut n) => n.select(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +63,7 @@ impl Node {
|
||||
Node::Mesh(ref mut n) => n.unselect(),
|
||||
Node::Convex(ref mut n) => n.unselect(),
|
||||
Node::Cylinder(ref mut n) => n.unselect(),
|
||||
Node::Cone(ref mut n) => n.unselect(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +79,7 @@ impl Node {
|
||||
Node::Mesh(ref mut n) => n.update(colliders),
|
||||
Node::Convex(ref mut n) => n.update(colliders),
|
||||
Node::Cylinder(ref mut n) => n.update(colliders),
|
||||
Node::Cone(ref mut n) => n.update(colliders),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,6 +108,7 @@ impl Node {
|
||||
Node::Mesh(ref n) => Some(n.scene_node()),
|
||||
Node::Convex(ref n) => Some(n.scene_node()),
|
||||
Node::Cylinder(ref n) => Some(n.scene_node()),
|
||||
Node::Cone(ref n) => Some(n.scene_node()),
|
||||
#[cfg(feature = "dim2")]
|
||||
_ => None,
|
||||
}
|
||||
@@ -120,6 +126,7 @@ impl Node {
|
||||
Node::Mesh(ref mut n) => Some(n.scene_node_mut()),
|
||||
Node::Convex(ref mut n) => Some(n.scene_node_mut()),
|
||||
Node::Cylinder(ref mut n) => Some(n.scene_node_mut()),
|
||||
Node::Cone(ref mut n) => Some(n.scene_node_mut()),
|
||||
#[cfg(feature = "dim2")]
|
||||
_ => None,
|
||||
}
|
||||
@@ -137,6 +144,7 @@ impl Node {
|
||||
Node::Mesh(ref n) => n.object(),
|
||||
Node::Convex(ref n) => n.object(),
|
||||
Node::Cylinder(ref n) => n.object(),
|
||||
Node::Cone(ref n) => n.object(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,6 +160,7 @@ impl Node {
|
||||
Node::Mesh(ref mut n) => n.set_color(color),
|
||||
Node::Convex(ref mut n) => n.set_color(color),
|
||||
Node::Cylinder(ref mut n) => n.set_color(color),
|
||||
Node::Cone(ref mut n) => n.set_color(color),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user