74 lines
1.6 KiB
Rust
74 lines
1.6 KiB
Rust
use super::CodePiece;
|
|
use glsl::parser::Parse;
|
|
use glsl::syntax::ShaderStage;
|
|
use glsl::syntax::TranslationUnit;
|
|
use glsl::transpiler::glsl::show_translation_unit;
|
|
|
|
use crate::impl_code_piece;
|
|
|
|
pub struct Trackball(pub ShaderStage);
|
|
|
|
impl Trackball {
|
|
pub fn new() -> Self {
|
|
let raw = {
|
|
"
|
|
uniform mat4 trackball_view;
|
|
uniform mat4 trackball_model;
|
|
uniform mat4 trackball_projection;
|
|
|
|
vec4 transform(vec4 position)
|
|
{
|
|
return trackball_projection
|
|
* trackball_view
|
|
* trackball_model
|
|
* position;
|
|
}
|
|
|
|
vec4 position(float x)
|
|
{
|
|
return vec4(x, 0.0, 0.0, 1.0);
|
|
}
|
|
|
|
vec4 position(float x, float y)
|
|
{
|
|
return vec4(x, y, 0.0, 1.0);
|
|
}
|
|
|
|
vec4 position(vec2 xy)
|
|
{
|
|
return vec4(xy, 0.0, 1.0);
|
|
}
|
|
|
|
vec4 position(float x, float y, float z)
|
|
{
|
|
return vec4(x, y, z, 1.0);
|
|
}
|
|
|
|
vec4 position(vec3 xyz)
|
|
{
|
|
return vec4(xyz, 1.0);
|
|
}
|
|
|
|
vec4 position(vec4 xyzw)
|
|
{
|
|
return xyzw;
|
|
}
|
|
|
|
vec4 position(vec2 xy, float z)
|
|
{
|
|
return vec4(xy, z, 1.0);
|
|
}
|
|
|
|
vec4 position(float x, vec2 yz)
|
|
{
|
|
return vec4(x, yz, 1.0);
|
|
}
|
|
"
|
|
};
|
|
|
|
Self(ShaderStage::parse(raw).unwrap())
|
|
}
|
|
}
|
|
|
|
impl_code_piece!(Trackball, 0);
|