aboutsummaryrefslogtreecommitdiff
path: root/sons_of_sol/private_db/Projectile.cpp
diff options
context:
space:
mode:
authorJoshua Rahm <joshua.rahm@colorado.edu>2013-12-10 19:19:26 -0700
committerJoshua Rahm <joshua.rahm@colorado.edu>2013-12-10 19:19:26 -0700
commit010f829485d570afb66c630026504fec63f93cdd (patch)
treed5e42e333178794377c05a99b5bf0c034485bcb6 /sons_of_sol/private_db/Projectile.cpp
parent7be3bda2b664068bf47404278fa9ee1ce552ea0e (diff)
downloadSonsOfSol-010f829485d570afb66c630026504fec63f93cdd.tar.gz
SonsOfSol-010f829485d570afb66c630026504fec63f93cdd.tar.bz2
SonsOfSol-010f829485d570afb66c630026504fec63f93cdd.zip
Almost finished working commit
Diffstat (limited to 'sons_of_sol/private_db/Projectile.cpp')
-rw-r--r--sons_of_sol/private_db/Projectile.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/sons_of_sol/private_db/Projectile.cpp b/sons_of_sol/private_db/Projectile.cpp
new file mode 100644
index 0000000..7819a0c
--- /dev/null
+++ b/sons_of_sol/private_db/Projectile.cpp
@@ -0,0 +1,73 @@
+#include "sons_of_sol/Projectile.hpp"
+#include "glox/GloxColor.hpp"
+#include "glox/GloxScopedRotation.hpp"
+
+using namespace glox ;
+using namespace std ;
+
+GloxCube* Projectile::m_model;
+
+void Projectile::loadModel( ) {
+ if( ! m_model ) {
+ m_model = new GloxCube( 10, 0.1, 0.1, GloxColor( 255, 255, 0 ) );
+ }
+}
+
+inline float jitter() {
+ return (2 * rand() & 0xFF) / 256.0 ;
+}
+
+void Projectile::draw() {
+ GloxPoint<> next = m_position + (m_dpos) * 0.2 + GloxPointf(jitter(),jitter(),jitter());
+ GloxScopedAttributes __glsa( GL_CURRENT_BIT );
+
+ GloxColor(
+ (uint8_t)(255.0f / TTL * m_ttl ),
+ (uint8_t)(250.0f / pow(TTL,2) * pow(m_ttl,2)),
+ (uint8_t)(200.0f / pow(TTL,4) * pow(m_ttl,4)),
+ (uint8_t)(100.0)
+ ).render();
+
+ glLineWidth( m_ttl / 10.0f );
+ GloxWith( GL_LINES,
+ m_position.plot();
+ GloxColor(
+ (uint8_t)(255.0f / TTL * (m_ttl-1) ),
+ (uint8_t)(200.0f / pow(TTL,2) * pow(m_ttl-1,2)),
+ (uint8_t)(100.0f / pow(TTL,4) * pow(m_ttl-1,4))).render();
+ next.plot();
+ );
+}
+
+Projectile::Projectile( const glox::GloxPoint<>& position, const glox::GloxPoint<>& vec ) {
+ m_position = position;
+ m_dpos = vec ;
+ m_ttl = TTL;
+
+ loadModel();
+
+ /* Project the point onto the x,y plane */
+ GloxPoint<> first( m_dpos.getX(), m_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 ;
+ m_roty = rot;
+ /* x axis now follows *first* vector */
+ /* Rotate around y axis to get x to follow *dpos* vector */
+ dot = first.dot( m_dpos );
+ rot = acos( dot );
+ rot = GloxToDegrees( rot );
+
+ if( m_dpos.getZ() < 0 ) {
+ rot = - rot;
+ }
+ m_rotz = rot;
+}