]> git.tdb.fi Git - libs/game.git/commitdiff
Pass bullet's initial transform values directly to the constructor
authorMikko Rasa <tdb@tdb.fi>
Sun, 27 Nov 2022 21:39:34 +0000 (23:39 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 27 Nov 2022 21:41:44 +0000 (23:41 +0200)
examples/bassteroids/source/bullet.cpp
examples/bassteroids/source/bullet.h
examples/bassteroids/source/playercontroller.cpp

index 260601b4d77b2f447ecef111c14a19cf6b13b86c..957a0394757c1b25bdda9c588d5d844429f370f3 100644 (file)
@@ -2,7 +2,7 @@
 
 using namespace Msp;
 
-Bullet::Bullet(Game::Handle<Game::Entity> p, const Setup &s):
-       PhysicalEntity(p, s.physical),
+Bullet::Bullet(Game::Handle<Game::Entity> p, const Setup &s, const Game::TransformValues &tv):
+       PhysicalEntity(p, s.physical, tv),
        mesh(*this, s.mesh)
 { }
index 825125fa01c1490463a29ba9f59dd7f68d06e16f..44c9d8053e366931a3536a1803d14dc716976555 100644 (file)
@@ -18,7 +18,7 @@ private:
 public:
        using Setup = BulletSetup;
 
-       Bullet(Msp::Game::Handle<Msp::Game::Entity>, const Setup &);
+       Bullet(Msp::Game::Handle<Msp::Game::Entity>, const Setup &, const Msp::Game::TransformValues & = Msp::Game::TransformValues());
 };
 
 #endif
index 65a879d2447727277ce4da16c4b4e1f822f57aef..066b5f24d002b01f5e68824d620753651ba7bf6a 100644 (file)
@@ -60,11 +60,11 @@ void PlayerController::fire()
        Game::Handle<Game::Transform> player_tf = player_ship->get_transform();
        Game::Handle<RigidBody> 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<float, 4>(2.0f, 0.0f, 0.0f, 1.0f)).slice<3>(0);
+       tv.rotation = player_tf->get_rotation()*Geometry::Quaternion<float>::rotation(Geometry::Angle<float>::from_degrees(10), LinAl::Vector<float, 3>(0.0f, 0.0f, 1.0f));
+       bullets.emplace_back(stage.get_root(), bullet_setup, tv);
        Game::Handle<Bullet> bullet = bullets.back();
-       Game::Handle<Game::Transform> bullet_tf = bullet->get_transform();
-       bullet_tf->set_position((player_tf->get_world_matrix()*LinAl::Vector<float, 4>(2.0f, 0.0f, 0.0f, 1.0f)).slice<3>(0));
-       bullet_tf->set_rotation(player_tf->get_rotation()*Geometry::Quaternion<float>::rotation(Geometry::Angle<float>::from_degrees(10), LinAl::Vector<float, 3>(0.0f, 0.0f, 1.0f)));
        Game::Handle<RigidBody> bullet_body = bullet->get_body();
        bullet_body->set_velocity(player_body->get_velocity()+(player_tf->get_world_matrix()*LinAl::Vector<float, 4>(20.0f, 0.0f, 0.0f, 0.0f)).slice<2>(0));
 }