mirror of
https://github.com/storytold/point-generator.git
synced 2026-10-09 00:09:43 +00:00
Now it works. It was endianness
This commit is contained in:
Generated
+7
@@ -6,6 +6,12 @@ version = "1.2.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "byteorder"
|
||||||
|
version = "1.4.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ae44d1a3d5a19df61dd0c8beb138458ac2a53a7ac09eba97d55592540004306b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytes"
|
name = "bytes"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
@@ -92,6 +98,7 @@ checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c"
|
|||||||
name = "point-generator"
|
name = "point-generator"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"byteorder",
|
||||||
"bytes",
|
"bytes",
|
||||||
"rand",
|
"rand",
|
||||||
"zmq",
|
"zmq",
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ path = "src/main.rs"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bytes = "1.0.1"
|
bytes = "1.0.1"
|
||||||
|
byteorder = "1.4.2"
|
||||||
rand = "0.8.2"
|
rand = "0.8.2"
|
||||||
zmq = { version = "0.9", features = ['vendored'] }
|
zmq = { version = "0.9", features = ['vendored'] }
|
||||||
#zeromq = "0.2.0" # Doesn't compile. Complains about Rust issue #54727
|
#zeromq = "0.2.0" # Doesn't compile. Complains about Rust issue #54727
|
||||||
|
|||||||
+1
-1
@@ -31,7 +31,7 @@ fn main() {
|
|||||||
let mut messaging_state = MessagingState::Sending;
|
let mut messaging_state = MessagingState::Sending;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let point = Point::at_random_range(-1.0f32, 1.0f32, Color::Blue);
|
let point = Point::at_random_range(-1000.0f32, 1000.0f32, Color::Blue);
|
||||||
let bytes = point.to_bytes();
|
let bytes = point.to_bytes();
|
||||||
println!("Point : {}", point.debug_string());
|
println!("Point : {}", point.debug_string());
|
||||||
|
|
||||||
|
|||||||
+13
-2
@@ -2,6 +2,7 @@ use bytes::{BytesMut, BufMut};
|
|||||||
use rand::distributions::Uniform;
|
use rand::distributions::Uniform;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use crate::color::Color;
|
use crate::color::Color;
|
||||||
|
use byteorder::{WriteBytesExt, LittleEndian, BigEndian};
|
||||||
|
|
||||||
|
|
||||||
pub struct Point {
|
pub struct Point {
|
||||||
@@ -64,7 +65,7 @@ impl Point {
|
|||||||
|
|
||||||
|
|
||||||
pub fn to_bytes(&self) -> Vec<u8> {
|
pub fn to_bytes(&self) -> Vec<u8> {
|
||||||
let mut buf = BytesMut::with_capacity(32);
|
/*let mut buf = BytesMut::with_capacity(32);
|
||||||
buf.put_f32(self.x);
|
buf.put_f32(self.x);
|
||||||
buf.put_f32(self.y);
|
buf.put_f32(self.y);
|
||||||
buf.put_f32(self.z);
|
buf.put_f32(self.z);
|
||||||
@@ -77,7 +78,17 @@ impl Point {
|
|||||||
buf.put_u32(self.g);
|
buf.put_u32(self.g);
|
||||||
buf.put_u32(self.b);
|
buf.put_u32(self.b);
|
||||||
buf.put_u32(self.a);
|
buf.put_u32(self.a);
|
||||||
buf.to_vec()
|
buf.to_vec()*/
|
||||||
|
let mut buf = Vec::with_capacity(32);
|
||||||
|
buf.write_f32::<LittleEndian>(self.x);
|
||||||
|
buf.write_f32::<LittleEndian>(self.y);
|
||||||
|
buf.write_f32::<LittleEndian>(self.z);
|
||||||
|
buf.write_f32::<LittleEndian>(0.0f32);
|
||||||
|
buf.write_u32::<LittleEndian>(self.r);
|
||||||
|
buf.write_u32::<LittleEndian>(self.g);
|
||||||
|
buf.write_u32::<LittleEndian>(self.b);
|
||||||
|
buf.write_u32::<LittleEndian>(self.a);
|
||||||
|
buf
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn location_string(&self) -> String {
|
pub fn location_string(&self) -> String {
|
||||||
|
|||||||
Reference in New Issue
Block a user