aboutsummaryrefslogtreecommitdiff
path: root/sons_of_sol/private_db/AIShip.cpp
diff options
context:
space:
mode:
authorJosh Rahm <rahm@google.com>2025-12-23 12:59:23 -0700
committerJosh Rahm <rahm@google.com>2025-12-23 12:59:23 -0700
commit46efbf05fcade8199035f956e20a63ca91fc88fd (patch)
tree9e3f3e297ea66e442e1a11b5ad16ad8ed6fc7fb7 /sons_of_sol/private_db/AIShip.cpp
parent306bb687414f54177eb37ab7cd744e491c397c31 (diff)
downloadSonsOfSol-46efbf05fcade8199035f956e20a63ca91fc88fd.tar.gz
SonsOfSol-46efbf05fcade8199035f956e20a63ca91fc88fd.tar.bz2
SonsOfSol-46efbf05fcade8199035f956e20a63ca91fc88fd.zip
Run clang-format and add .clang-format
Diffstat (limited to 'sons_of_sol/private_db/AIShip.cpp')
-rw-r--r--sons_of_sol/private_db/AIShip.cpp196
1 files changed, 96 insertions, 100 deletions
diff --git a/sons_of_sol/private_db/AIShip.cpp b/sons_of_sol/private_db/AIShip.cpp
index 5940e42..b487d3c 100644
--- a/sons_of_sol/private_db/AIShip.cpp
+++ b/sons_of_sol/private_db/AIShip.cpp
@@ -3,124 +3,120 @@
#include <cmath>
#include <iostream>
+#include "glox/GloxColor.hpp"
#include "glox/GloxScopedRotation.hpp"
#include "glox/GloxScopedTranslation.hpp"
-#include "glox/GloxColor.hpp"
using namespace slox;
using namespace glox;
using namespace std;
-
-SloxModelObject* AIShip::s_high_model ;
-SloxModelObject* AIShip::s_med_model ;
-SloxModelObject* AIShip::s_low_model ;
-GloxCube* AIShip::s_really_far_away_model ;
-
-void AIShip::setModel( slox::SloxModelObject* high, slox::SloxModelObject* med, slox::SloxModelObject* low ) {
- s_high_model = high;
- s_med_model = med;
- s_low_model = low;
- s_really_far_away_model = new glox::GloxCube( 4, 0.5, 8, GloxColor(245,245,220) );
+SloxModelObject* AIShip::s_high_model;
+SloxModelObject* AIShip::s_med_model;
+SloxModelObject* AIShip::s_low_model;
+GloxCube* AIShip::s_really_far_away_model;
+
+void AIShip::setModel(slox::SloxModelObject* high, slox::SloxModelObject* med,
+ slox::SloxModelObject* low) {
+ s_high_model = high;
+ s_med_model = med;
+ s_low_model = low;
+ s_really_far_away_model =
+ new glox::GloxCube(4, 0.5, 8, GloxColor(245, 245, 220));
}
-void AIShip::setUpdateFunction( Updater* updater ){
- update_func = updater;
+void AIShip::setUpdateFunction(Updater* updater) {
+ update_func = updater;
- /* Update 3 times so we have a full set
+ /* Update 3 times so we have a full set
* of points to start with */
- update();
- update();
- update();
+ update();
+ update();
+ update();
}
void AIShip::calculate_roll_to() {
- GloxPoint<> total_change = m_future_position - m_last_position ;
- GloxPoint<> current_change = m_position - m_last_position ;
-
- float scalar_projection = ( current_change.dot( total_change ) / total_change.dot(total_change) ) ;
- total_change *= scalar_projection ;
- GloxPoint<> to_vector = current_change - total_change ;
- to_vector.normalize();
-
- float ang = to_vector.dot( GloxPointf(0,1,0) ) ;
- float tmp = GloxToDegrees( acos( ang ) );
-
- if( tmp == tmp ) {
- /* Cut out NANs */
- m_roll_to = tmp;
- }
-// cout << "m_roll_to " << m_roll_to << endl;
+ GloxPoint<> total_change = m_future_position - m_last_position;
+ GloxPoint<> current_change = m_position - m_last_position;
+
+ float scalar_projection =
+ (current_change.dot(total_change) / total_change.dot(total_change));
+ total_change *= scalar_projection;
+ GloxPoint<> to_vector = current_change - total_change;
+ to_vector.normalize();
+
+ float ang = to_vector.dot(GloxPointf(0, 1, 0));
+ float tmp = GloxToDegrees(acos(ang));
+
+ if (tmp == tmp) {
+ /* Cut out NANs */
+ m_roll_to = tmp;
+ }
+ // cout << "m_roll_to " << m_roll_to << endl;
}
-void AIShip::setTimeOffset( uint32_t off ) {
- m_time_offset = off ;
+void AIShip::setTimeOffset(uint32_t off) {
+ m_time_offset = off;
}
-void AIShip::update( ) {
- m_last_position = m_position;
- m_position = m_future_position ;
- m_future_position = update_func->update( SDL_GetTicks() + m_time_offset ) ;
+void AIShip::update() {
+ m_last_position = m_position;
+ m_position = m_future_position;
+ m_future_position = update_func->update(SDL_GetTicks() + m_time_offset);
}
-void AIShip::draw( float dist ) {
- GloxScopedTranslation __gstr1( m_position );
- /* The the change in the vector, this is where
+void AIShip::draw(float dist) {
+ GloxScopedTranslation __gstr1(m_position);
+ /* The the change in the vector, this is where
* the front of the ship goes */
- GloxPoint<> dpos = m_position - m_last_position ;
-
- /* Project the point onto the x,y plane */
- GloxPoint<> first( dpos.getX(), dpos.getY(), 0 );
- /* A point that represents the x axis */
- GloxPoint<> xaxis( 1, 0, 0 );
-
- /* Rotation around the z axis */
- float dot = first.dot( xaxis ) ;
- float rot = GloxToDegrees(acos( dot )) ;
-
- if( first.getY() < 0 ) {
- rot = - rot;
- }
- rot = rot + 180 ;
- // if( rot != rot ) {
- // cout << "Non existant Z rotation!" << endl ;
- // }
- GloxScopedRotation __gscr1( rot, 0, 0, 1 );
- /* x axis now follows *first* vector */
- /* Rotate around y axis to get x to follow *dpos* vector */
- dot = first.dot( dpos );
-
- rot = acos( dot );
- rot = GloxToDegrees( rot );
-
- if( dpos.getZ() < 0 ) {
- rot = - rot;
- }
-
- // if( rot != rot ) {
- // cout << "Non existant Y rotation!" << endl ;
- // }
- GloxScopedRotation __glcr2( rot, 0, 1, 0 );
-
- calculate_roll_to();
- if( m_roll != m_roll ) {
- m_roll = 0.0f;
- }
- m_roll = ( m_roll_to + (5 - 1) * m_roll) / 5.0f;
-
- float roll = m_roll;
- // if( dpos.getX() < 0 ) {
- // roll += 180 ;
- // }
-
- GloxScopedRotation __glco3( roll, 1, 0, 0 );
- GloxScale( 2,
- if( dist < 20 )
- s_high_model->draw();
- else if ( dist < 50 )
- s_med_model->draw();
- else if ( dist < 1000 )
- s_low_model->draw();
- else
- s_really_far_away_model->draw();
- );
+ GloxPoint<> dpos = m_position - m_last_position;
+
+ /* Project the point onto the x,y plane */
+ GloxPoint<> first(dpos.getX(), dpos.getY(), 0);
+ /* A point that represents the x axis */
+ GloxPoint<> xaxis(1, 0, 0);
+
+ /* Rotation around the z axis */
+ float dot = first.dot(xaxis);
+ float rot = GloxToDegrees(acos(dot));
+
+ if (first.getY() < 0) {
+ rot = -rot;
+ }
+ rot = rot + 180;
+ // if( rot != rot ) {
+ // cout << "Non existant Z rotation!" << endl ;
+ // }
+ GloxScopedRotation __gscr1(rot, 0, 0, 1);
+ /* x axis now follows *first* vector */
+ /* Rotate around y axis to get x to follow *dpos* vector */
+ dot = first.dot(dpos);
+
+ rot = acos(dot);
+ rot = GloxToDegrees(rot);
+
+ if (dpos.getZ() < 0) {
+ rot = -rot;
+ }
+
+ // if( rot != rot ) {
+ // cout << "Non existant Y rotation!" << endl ;
+ // }
+ GloxScopedRotation __glcr2(rot, 0, 1, 0);
+
+ calculate_roll_to();
+ if (m_roll != m_roll) {
+ m_roll = 0.0f;
+ }
+ m_roll = (m_roll_to + (5 - 1) * m_roll) / 5.0f;
+
+ float roll = m_roll;
+ // if( dpos.getX() < 0 ) {
+ // roll += 180 ;
+ // }
+
+ GloxScopedRotation __glco3(roll, 1, 0, 0);
+ GloxScale(2, if (dist < 20) s_high_model->draw();
+ else if (dist < 50) s_med_model->draw();
+ else if (dist < 1000) s_low_model->draw();
+ else s_really_far_away_model->draw(););
}