diff options
author | Frederico Linhares <fred@linhares.blue> | 2022-08-22 17:26:43 -0300 |
---|---|---|
committer | Frederico Linhares <fred@linhares.blue> | 2022-08-22 17:50:58 -0300 |
commit | 42e03ddc3b28c41b81fb5410feb72750530ffa13 (patch) | |
tree | 3d13318c57d45eb93348edb63122258a61531eef /test | |
parent | 67b78f24a9ec8c823bbb8ff091ccd6bb4144a435 (diff) |
feat Make camera and model instance more abstract
* src/camera.cpp src/camera.hpp: Remove the camera as Vector3D and
Rotation3D are going to replace it.
* src/model.cpp: Add draw command as instances do not exist anymore.
* src/model/instance.cpp src/model/instance.hpp: Remove the instance as
Vector3D and Rotation3D are going to replace it.
Diffstat (limited to 'test')
-rw-r--r-- | test/src/main.rb | 65 |
1 files changed, 29 insertions, 36 deletions
diff --git a/test/src/main.rb b/test/src/main.rb index 31affb8..2c8bdcc 100644 --- a/test/src/main.rb +++ b/test/src/main.rb @@ -12,7 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -ROTATION_SPEED = Math::PI/45; +CAMERA_ROTATION_SPEED = Math::PI/45; +BOX_ROTATION_SPEED = Math::PI/180; TRANSLATION_SPEED = 0.5; def init() @@ -20,54 +21,43 @@ def init() $model = CandyGear::Model.new("models/cube.cgmodel", $texture); $instances = [ - CandyGear::Model::Instance.new( - $model, - 5.0, 0.0, 0.0, - 0.0, 0.0, 0.0), - CandyGear::Model::Instance.new( - $model, - -5.0, 0.0, 0.0, - 0.0, 0.0, 0.0), - CandyGear::Model::Instance.new( - $model, - 0.0, 5.0, 0.0, - 0.0, 0.0, 0.0), - CandyGear::Model::Instance.new( - $model, - 0.0, -5.0, 0.0, - 0.0, 0.0, 0.0), - CandyGear::Model::Instance.new( - $model, - 0.0, 0.0, 5.0, - 0.0, 0.0, 0.0), - CandyGear::Model::Instance.new( - $model, - 0.0, 0.0, -5.0, - 0.0, 0.0, 0.0) + CandyGear::Vector3D.new(5.0, 0.0, 0.0), + CandyGear::Vector3D.new(-5.0, 0.0, 0.0), + CandyGear::Vector3D.new(0.0, 5.0, 0.0), + CandyGear::Vector3D.new(0.0, -5.0, 0.0), + CandyGear::Vector3D.new(0.0, 0.0, 5.0), + CandyGear::Vector3D.new(0.0, 0.0, -5.0) ]; + $instances_rotation = CandyGear::Rotation3D.new(0.0, 0.0, 0.0); - $camera = CandyGear::Camera.new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); - $camera.use(); + $camera_position = CandyGear::Vector3D.new(0.0, 0.0, 0.0); + $camera_rotation = CandyGear::Rotation3D.new(0.0, 0.0, 0.0); + CandyGear.camera_position = $camera_position + CandyGear.camera_rotation = $camera_rotation; end def key_down(key) case key when CandyGear::Key::I - $camera.rotate(ROTATION_SPEED, 0.0, 0.0); + $camera_rotation.rotate(CAMERA_ROTATION_SPEED, 0.0); when CandyGear::Key::K - $camera.rotate(-ROTATION_SPEED, 0.0, 0.0); + $camera_rotation.rotate(-CAMERA_ROTATION_SPEED, 0.0); when CandyGear::Key::J - $camera.rotate(0.0, ROTATION_SPEED, 0.0); + $camera_rotation.rotate(0.0, CAMERA_ROTATION_SPEED); when CandyGear::Key::L - $camera.rotate(0.0, -ROTATION_SPEED, 0.0); + $camera_rotation.rotate(0.0, -CAMERA_ROTATION_SPEED); when CandyGear::Key::E - $camera.translate_by_rotation(0.0, 0.0, -TRANSLATION_SPEED); + $camera_position.translate( + CandyGear::Vector3D.new(0.0, 0.0, -TRANSLATION_SPEED), $camera_rotation); when CandyGear::Key::D - $camera.translate_by_rotation(0.0, 0.0, TRANSLATION_SPEED); + $camera_position.translate( + CandyGear::Vector3D.new(0.0, 0.0, TRANSLATION_SPEED), $camera_rotation); when CandyGear::Key::S - $camera.translate_by_rotation(-TRANSLATION_SPEED, 0.0, 0.0); + $camera_position.translate( + CandyGear::Vector3D.new(-TRANSLATION_SPEED, 0.0, 0.0), $camera_rotation); when CandyGear::Key::F - $camera.translate_by_rotation(TRANSLATION_SPEED, 0.0, 0.0); + $camera_position.translate( + CandyGear::Vector3D.new(TRANSLATION_SPEED, 0.0, 0.0), $camera_rotation); end end @@ -77,5 +67,8 @@ end def quit() = CandyGear.quit(); def tick() - $instances.each {|i| i.draw();}; + $instances_rotation.rotate(0.0, BOX_ROTATION_SPEED); + $instances.each do |i| + $model.draw(i, $instances_rotation); + end end |