Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed the way the turret is controlled. The azimuth and inclinatio… #13

Merged
merged 1 commit into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions carrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,8 @@ int main(int argc, char** argv) {
// Initialize ODE, create islands, structures and populate the world.
if (argc>1 && strcmp(argv[1],"-test")==0)
initWorldModelling(atoi(argv[2]));
else if (argc>2 && strcmp(argv[2],"-test")==0)
initWorldModelling(atoi(argv[3]));
else
initWorldModelling();

Expand Down
1 change: 1 addition & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "camera.h"

#include "sounds.h"


float modAngleY=0, modAngleX = 0, modAngleZ=0;
Expand Down
110 changes: 110 additions & 0 deletions math/splines.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#ifndef SPLINES_HPP
#define SPLINES_HPP

#include <vector>

// =============================================================================
namespace spline {
// =============================================================================

enum Node_e {
eUNIFORM,
eOPEN_UNIFORM ///< Connected to the first and last control points
};

}// END ESPline ================================================================

/**
* @class Spline
*
* @brief Handling spline curves of arbitrary dimensions
* @note This class use the efficient blossom algorithm to compute a position on
* the curve.
*
* @tparam Point_t : type of a point operators such as '+' '*' must be correctly
* overloaded. The default constructor must be defined to return the
* null vector (0, 0 ,0 ...)
* @tparam Real_t ; floating point reprensentation of the points
* (float, double etc.)
*/
template<typename Point_t, typename Real_t>
class Spline {
public:

/// Type of the nodal vector
/// @param k : order of the spline (minimum is two)
/// @param node_type : nodal vector type (uniform, open_uniform)
/// This will define the behavior of the spline with its control points
/// as well as its speed according to its parameter.
Spline(int k = 2, spline::Node_e node_type = spline::eOPEN_UNIFORM);

/// Set the position of the spline control points.
void set_ctrl_points(const std::vector<Point_t>& point);

/// Get the control points of the spline
void get_ctrl_points(std::vector<Point_t>& points) const;

/// The the nodal vector type
void set_node_type( spline::Node_e type);

/// Evaluate position of the spline
/// @param u : curve parameter ranging from [0; 1]
Point_t eval_f(Real_t u) const;

/// Evaluate speed of the spline
Point_t eval_df(Real_t u) const;

int get_order() const { return _k; }

private:
// -------------------------------------------------------------------------
/// @name Class tools
// -------------------------------------------------------------------------

void assert_splines() const;

/// set value and size of the nodal vector depending on the current number
/// of control points
void set_nodal_vector();

/// Set values of the nodal vector to be uniform
void set_node_to_uniform();

/// Set values of the nodal vector to be open uniform
void set_node_to_open_uniform();

/// Evaluate the equation of a splines using the blossom algorithm
/// @param u : the curve parameter which range from the values
/// [node[k-1]; node[point.size()]]
/// @param point : the control points which size must be at least equal to
/// the order of the spline (point.size() >= k)
/// @param k : the spline order (degree == k-1)
/// @param node : the nodal vector which defines the speed of the spline
/// parameter u. The nodal vector size must be equal to (k + point.size())
/// @param off : offset to apply to the nodal vector 'node' before reading
/// from it. this is useful to compute derivatives.
Point_t eval(Real_t u,
const std::vector<Point_t>& point,
int k,
const std::vector<Real_t>& node,
int off = 0) const;

Point_t eval_rec(Real_t u,
std::vector<Point_t> p_in,
int k,
std::vector<Real_t> node_in) const;

// -------------------------------------------------------------------------
/// @name attributes
// -------------------------------------------------------------------------

spline::Node_e _node_type; ///< Nodal vector type
int _k; ///< spline order
std::vector<Point_t> _point; ///< Control points
std::vector<Point_t> _vec; ///< Control points differences
std::vector<Real_t> _node; ///< Nodal vector
};

#include "splines.inl"

#endif // SPLINES_HPP
192 changes: 192 additions & 0 deletions math/splines.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
#include "splines.hpp"

#include <cassert>
#include <algorithm>

template<typename Point_t, typename Real_t>
Spline<Point_t, Real_t>::Spline(
int k,
spline::Node_e node_type)
:
_node_type(node_type),
_k(k),
_point( _k ),
_vec( _k-1 ),
_node( _k + _point.size() )
{
assert_splines();
}

// -----------------------------------------------------------------------------

template<typename Point_t, typename Real_t>
void Spline<Point_t, Real_t>::set_ctrl_points(const std::vector<Point_t>& point)
{
_point = point;
_vec.resize(_point.size() - 1);
for(int i = 0; i < (int)_vec.size(); ++i)
_vec[i] = _point[i + 1] - _point[i];
set_nodal_vector();
assert_splines();

for(int i = 0; i < (int)_vec.size(); ++i)
_vec[i] /= _node[_k+i] - _node[i+1];
}

// -----------------------------------------------------------------------------

template<typename Point_t, typename Real_t>
void Spline<Point_t, Real_t>::get_ctrl_points(std::vector<Point_t>& points) const
{
points = _point;
}

// -----------------------------------------------------------------------------

/// The the nodal vector type
template<typename Point_t, typename Real_t>
void Spline<Point_t, Real_t>::set_node_type( spline::Node_e type)
{
_node_type = type;
set_nodal_vector();
assert_splines();
}

// -----------------------------------------------------------------------------

template<typename Point_t, typename Real_t>
Point_t Spline<Point_t, Real_t>::eval_f(Real_t u) const
{
u = std::max(std::min(u, (Real_t)1), (Real_t)0); // clamp between [0 1]
return eval(u, _point, _k, _node);
}

// -----------------------------------------------------------------------------

template<typename Point_t, typename Real_t>
Point_t Spline<Point_t, Real_t>::eval_df(Real_t u) const
{
u = std::max(std::min(u, (Real_t)1), (Real_t)0); // clamp between [0 1]
return eval(u, _vec, (_k-1), _node, 1) * (Real_t)(_k-1);
}

// -----------------------------------------------------------------------------

template<typename Point_t, typename Real_t>
void Spline<Point_t, Real_t>::assert_splines() const
{
assert( _k > 1);
assert((int)_point.size() >= _k );
assert(_node. size() == (_k + _point.size()) );
assert(_point.size() == (_vec.size() + 1) );
}

// -----------------------------------------------------------------------------

template<typename Point_t, typename Real_t>
void Spline<Point_t, Real_t>::set_nodal_vector()
{
if( _node_type == spline::eOPEN_UNIFORM)
set_node_to_open_uniform();
else if( _node_type == spline::eUNIFORM )
set_node_to_uniform();
}

// -----------------------------------------------------------------------------

template<typename Point_t, typename Real_t>
void Spline<Point_t, Real_t>::set_node_to_uniform()
{
const int n = _point.size() - 1;
_node.resize( _k + n + 1 );

Real_t step = (Real_t)1 / (Real_t)(n-_k+2);
for (int i = 0; i < (int)_node.size(); ++i){
_node[i] = ((Real_t)i) * step - step * (Real_t)(_k-1);
}
}

// -----------------------------------------------------------------------------

template<typename Point_t, typename Real_t>
void Spline<Point_t, Real_t>::set_node_to_open_uniform()
{
_node.resize( _k + _point.size() );

int acc = 1;
for (int i = 0; i < (int)_node.size(); ++i)
{
if(i < _k)
_node[i] = 0.;
else if( i >= ((int)_point.size() + 1) )
_node[i] = 1.;
else{
_node[i] = (Real_t)acc / (Real_t)(_point.size() + 1 - _k);
acc++;
}
}
}

// -----------------------------------------------------------------------------

template<typename Point_t, typename Real_t>
Point_t Spline<Point_t, Real_t>::

eval(Real_t u,
const std::vector<Point_t>& point,
int k,
const std::vector<Real_t>& node,
int off) const
{
assert( k > 1);
assert((int)point.size() >= k );
assert_splines();
int dec = 0;
// TODO: better search with dychotomi ?
// TODO: check for overflow
while( u > node[dec + k + off] )
dec++;

// TODO: use buffers in attributes for better performances ?
std::vector<Point_t> p_rec(k, Point_t());
for(int i = dec, j = 0; i < (dec + k); ++i, ++j)
p_rec[j] = point[i];

std::vector<Real_t> node_rec(k + k - 2, (Real_t)0);
for(int i = (dec + 1), j = 0; i < (dec + k + k - 1); ++i, ++j)
node_rec[j] = node[i + off];

return eval_rec(u, p_rec, k, node_rec);
}

// -----------------------------------------------------------------------------

template<typename Point_t, typename Real_t>
Point_t Spline<Point_t, Real_t>::

eval_rec(Real_t u,
std::vector<Point_t> p_in,
int k,
std::vector<Real_t> node_in) const
{
if(p_in.size() == 1)
return p_in[0];

// TODO: use buffers in attributes for better performances ?
std::vector<Point_t> p_out(k - 1, Point_t());
for(int i = 0; i < (k - 1); ++i)
{
const Real_t n0 = node_in[i + k - 1];
const Real_t n1 = node_in[i];
const Real_t f0 = (n0 - u) / (n0 - n1);
const Real_t f1 = (u - n1) / (n0 - n1);

p_out[i] = p_in[i] * f0 + p_in[i + 1] * f1;
}

std::vector<Real_t> node_out(node_in.size() - 2);
for(int i = 1, j = 0; i < ((int)node_in.size()-1); ++i, ++j)
node_out[j] = node_in[i];

return eval_rec(u, p_out, (k - 1), node_out);
}
5 changes: 3 additions & 2 deletions math/yamathutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ void Normalize(float v[3][3], float out[3])
* @param dx
* @param dy
* @param dz
* @param azimuth In degrees.
* @param inclination In degrees.
* @param azimuth In degrees. glRotatef(-Structure::azimuth,0.0f,1.0f,0.0f);
* @param inclination In degrees. glRotatef(-Structure::inclination,0.0f,0.0f,1.0f);
* @return
*/
Vec3f toVectorInFixedSystem(float dx, float dy, float dz,float azimuth, float inclination)
Expand Down Expand Up @@ -93,6 +93,7 @@ float getAzimuth(Vec3f aim)
}

/**
* @FIXME No funca
* @brief getInclination This is the inverse operation of the one above. Given a vector, it returs the inclination of the given vector.
* @param aim
* @return The inclination in degrees. -90 is the cenit, 0 is the horizon, positive looking down towards the floor and 90 is your feet.
Expand Down
18 changes: 18 additions & 0 deletions samplerandom.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "stdio.h"
#include "math.h"

int main(int argc, char *argv[])
{
srand(atoi(argv[1]));


for(int i=0;i<38;i++)
{
float x = (rand() % 3550 + 1); x -= 1800;
float z = (rand() % 3550 + 1); z -= 1800;

double rfs = rand();

printf ("rand %10.5f x %10.5f ,z %10.5f\n", rfs, x, z);
}
}
Binary file added sounds/boozing.m4a
Binary file not shown.
Binary file modified sounds/intro.mp3
Binary file not shown.
Binary file added sounds/introoriginal.mp3
Binary file not shown.
Binary file added sounds/mantasoaring.wav
Binary file not shown.
Binary file added sounds/win.mp3
Binary file not shown.
Loading