From: Mikko Rasa Date: Sun, 27 Nov 2022 21:39:34 +0000 (+0200) Subject: Pass bullet's initial transform values directly to the constructor X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=f11589229323a6919a26f07b2f74bb9ffdd94fb5;p=libs%2Fgame.git Pass bullet's initial transform values directly to the constructor --- diff --git a/examples/bassteroids/source/bullet.cpp b/examples/bassteroids/source/bullet.cpp index 260601b..957a039 100644 --- a/examples/bassteroids/source/bullet.cpp +++ b/examples/bassteroids/source/bullet.cpp @@ -2,7 +2,7 @@ using namespace Msp; -Bullet::Bullet(Game::Handle p, const Setup &s): - PhysicalEntity(p, s.physical), +Bullet::Bullet(Game::Handle p, const Setup &s, const Game::TransformValues &tv): + PhysicalEntity(p, s.physical, tv), mesh(*this, s.mesh) { } diff --git a/examples/bassteroids/source/bullet.h b/examples/bassteroids/source/bullet.h index 825125f..44c9d80 100644 --- a/examples/bassteroids/source/bullet.h +++ b/examples/bassteroids/source/bullet.h @@ -18,7 +18,7 @@ private: public: using Setup = BulletSetup; - Bullet(Msp::Game::Handle, const Setup &); + Bullet(Msp::Game::Handle, const Setup &, const Msp::Game::TransformValues & = Msp::Game::TransformValues()); }; #endif diff --git a/examples/bassteroids/source/playercontroller.cpp b/examples/bassteroids/source/playercontroller.cpp index 65a879d..066b5f2 100644 --- a/examples/bassteroids/source/playercontroller.cpp +++ b/examples/bassteroids/source/playercontroller.cpp @@ -60,11 +60,11 @@ void PlayerController::fire() Game::Handle player_tf = player_ship->get_transform(); Game::Handle player_body = player_ship->get_body(); - bullets.emplace_back(stage.get_root(), bullet_setup); + Game::TransformValues tv; + tv.position = (player_tf->get_world_matrix()*LinAl::Vector(2.0f, 0.0f, 0.0f, 1.0f)).slice<3>(0); + tv.rotation = player_tf->get_rotation()*Geometry::Quaternion::rotation(Geometry::Angle::from_degrees(10), LinAl::Vector(0.0f, 0.0f, 1.0f)); + bullets.emplace_back(stage.get_root(), bullet_setup, tv); Game::Handle bullet = bullets.back(); - Game::Handle bullet_tf = bullet->get_transform(); - bullet_tf->set_position((player_tf->get_world_matrix()*LinAl::Vector(2.0f, 0.0f, 0.0f, 1.0f)).slice<3>(0)); - bullet_tf->set_rotation(player_tf->get_rotation()*Geometry::Quaternion::rotation(Geometry::Angle::from_degrees(10), LinAl::Vector(0.0f, 0.0f, 1.0f))); Game::Handle bullet_body = bullet->get_body(); bullet_body->set_velocity(player_body->get_velocity()+(player_tf->get_world_matrix()*LinAl::Vector(20.0f, 0.0f, 0.0f, 0.0f)).slice<2>(0)); }