adjust demo and implementation to demonstrate proper camera movement
Signed-off-by: Hartmut Seichter <hartmut@technotecture.com>
This commit is contained in:
parent
42c9fac38e
commit
2d8244386a
2 changed files with 13 additions and 2 deletions
|
@ -56,6 +56,7 @@ void register_core_function(sol::state&,sol::table& ns)
|
|||
, "column",&matrix4x4::column
|
||||
, "set_identity",&matrix4x4::set_identity
|
||||
, "inverse",&matrix4x4::inverse
|
||||
, "identity", &matrix4x4::identity
|
||||
);
|
||||
|
||||
ns.new_usertype<vector3>("vector3"
|
||||
|
@ -72,6 +73,9 @@ void register_core_function(sol::state&,sol::table& ns)
|
|||
,"right",&vector3::right
|
||||
,"up",&vector3::up
|
||||
,"down",&vector3::down
|
||||
,sol::meta_function::addition,&vector3::operator+
|
||||
,sol::meta_function::subtraction,&vector3::operator-
|
||||
,sol::meta_function::multiplication,&vector3::operator*
|
||||
);
|
||||
|
||||
ns.new_usertype<vector4>("vector4"
|
||||
|
|
|
@ -70,6 +70,7 @@ s:set_source(pw.shader_type.fragment,[[
|
|||
#version 400
|
||||
uniform vec4 color = vec4(1.0, 0.0, 0.0, 1.0);
|
||||
out vec4 frag_colour;
|
||||
|
||||
void main() {
|
||||
frag_colour = color;
|
||||
}
|
||||
|
@ -91,6 +92,8 @@ end
|
|||
-- camera position
|
||||
local cam_pos = pw.vector3:new(0,0,0)
|
||||
|
||||
local model_pos = pw.vector3:new(0,0,0)
|
||||
|
||||
|
||||
local ctx = pw.context:new()
|
||||
|
||||
|
@ -106,8 +109,8 @@ w.on_update = function(self)
|
|||
-- set identity on model matrix
|
||||
mm:set_identity()
|
||||
|
||||
-- set view matrix with look_at
|
||||
mv = pw.matrixtransform.look_at(cam_pos,pw.vector3.forward(),pw.vector3.up())
|
||||
-- set view matrix with look_at - view matrix is moving the world - hence inverse!
|
||||
mv = pw.matrixtransform.look_at(cam_pos,cam_pos + pw.vector3.forward(),pw.vector3.up()):inverse()
|
||||
|
||||
-- compute aspect ratio from canvas size
|
||||
aspect_ratio = self.client_size.width / self.client_size.height
|
||||
|
@ -166,6 +169,10 @@ while w:update() do
|
|||
cam_pos.x = cam_pos.x - move_step
|
||||
elseif pw.input.get().input_string == 'd' then
|
||||
cam_pos.x = cam_pos.x + move_step
|
||||
elseif pw.input.get().input_string == 'z' then
|
||||
cam_pos.y = cam_pos.y + move_step
|
||||
elseif pw.input.get().input_string == 'x' then
|
||||
cam_pos.y = cam_pos.y - move_step
|
||||
end
|
||||
|
||||
print(cam_pos.x,cam_pos.y,cam_pos.z)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue