Exemplo n.º 1
0
//==== Read Airfoil File ====//
void Af::read(FILE* file_id)
{
  int i;
  Stringc line;
  char buff[255];
  int temp_type;
  int version = geom_ptr->get_aircraft_ptr()->get_version();

  fgets(buff, 80, file_id);
  fgets(buff, 80, file_id);  line = buff;

  if (line.search_for_substring("Num") >= 0)
    {
      sscanf(buff, "%d", &num_pnts);
      if (version >= 5) 
      {
        fscanf(file_id, "%d", &inverted_flag);
        fgets(buff, 80, file_id);
      }
      camber.read(file_id);
      camber_loc.read(file_id);
      thickness.read(file_id);
      temp_type = NACA_4_SERIES;
    }
  else
    {
      sscanf(buff, "%d", &temp_type);
      if (version >= 5)
      {
        fscanf(file_id, "%d", &inverted_flag);
        fgets(buff, 80, file_id);
      }
      camber.read(file_id);
      camber_loc.read(file_id);
      thickness.read(file_id);
      thickness_loc.read(file_id);
      radius_le.read(file_id);
      radius_te.read(file_id);

      if ( temp_type ==  NACA_6_SERIES )
      {
        fscanf( file_id, "%d", &sixser );
        fgets(buff, 80, file_id);
        ideal_cl.read(file_id);
        a.read(file_id);
      }

      if ( temp_type == AIRFOIL_FILE )
        {
          fgets(buff, 80, file_id);
          name = buff;
          name.remove_trailing_blanks();
          name.remove_all_substrings('\n');

          vec3d pnt;
          float x, z;
          int num_upper, num_lower;

          fscanf(file_id, "%f",&orig_af_thickness);		fgets(buff, 80, file_id);
          fscanf(file_id, "%f",&radius_le_correction_factor);	fgets(buff, 80, file_id);
          fscanf(file_id, "%f",&radius_te_correction_factor);	fgets(buff, 80, file_id);
          fscanf(file_id, "%d",&num_upper); 			fgets(buff, 80, file_id);
          upper_curve.init(num_upper);
          for ( i = 0 ; i < num_upper ; i++)
            {
              fscanf(file_id, "%f  %f",&x, &z);
              pnt = vec3d(x, 0.0, z);
              upper_curve.load_pnt( i, pnt );
            }
          fgets(buff, 80, file_id);
          fscanf(file_id, "%d",&num_lower); 			fgets(buff, 80, file_id);
          lower_curve.init(num_lower);
          for (  i = 0 ; i < num_lower ; i++)
            {
              fscanf(file_id, "%f  %f",&x, &z);
              pnt = vec3d(x, 0.0, z);
              lower_curve.load_pnt( i, pnt );
            }
          fgets(buff, 80, file_id);
        }
     }
  set_type(temp_type);
}
Exemplo n.º 2
0
#include <GL/glew.h>
#include <GL/glut.h>
#include <AntTweakBar.h>

#include "util.h"
#include "callbacks.h"
//#include "camera/float3.h"
//#include "camera/Camera.h"
#include "GLCam.h"
#include "mesh.h"


// ------------------ GLOBALS
Window mainWin;                 // Hold window properties
Mouse mouse;
GLCam camera(vec3d(10,10,10), vec3d(0,0,0), vec3d(0,1,0));
Mesh mesh(0.008f);

GLuint axisDL = 0;              // axis display list ID
char filename[255] = "models/fullsphere.txt";

// opengl light settings
GLfloat lightDir[] = {1.0, 0.5, 1.0, 0};
GLfloat lightDiffuse[] = {0.6, 0.6, 0.6, 1.0f};
GLfloat lightAmbient[] = {0.2, 0.2, 0.2, 1.0f};


int main(int argc, char** argv) {

    TwBar *bar;;
    
Exemplo n.º 3
0
//==== Update Method ===//
void SSControlSurf::Update()
{
    // Build Control Surface as a rectangle with the points counter clockwise

    vec3d c_uws_upper, c_uws_lower, c_uwe_upper, c_uwe_lower;
    vector< vec3d > pnt_vec;
    double u, w;

    Geom* geom = VehicleMgr.GetVehicle()->FindGeom( m_CompID );
    if ( !geom ) { return; }

    VspSurf* surf = geom->GetSurfPtr();
    if ( !surf ) { return; }

    m_UWStart.clear();
    m_UWEnd.clear();

    VspCurve startcrv;
    surf->GetU01ConstCurve( startcrv, m_UStart() );

    piecewise_curve_type c = startcrv.GetCurve();

    double vmin = c.get_parameter_min(); // Really must be 0.0
    double vmax = c.get_parameter_max(); // Really should be 4.0

    double vle = ( vmin + vmax ) * 0.5;

    double vtelow = vmin + TMAGIC;
    double vteup = vmax - TMAGIC;
    double vlelow = vle - TMAGIC;
    double vleup = vle + TMAGIC;

    curve_point_type te, le;
    te = c.f( vmin );
    le = c.f( vle );

    double chord, d;
    chord = dist( le, te );

    if ( m_AbsRelFlag() == vsp::REL )
    {
        d = chord * m_StartLenFrac();
        m_StartLength.Set( d );
    }
    else
    {
        d = m_StartLength();
        m_StartLenFrac.Set( d / chord );
    }

    if ( m_ConstFlag.Get() )
    {
        if ( m_AbsRelFlag() == vsp::REL )
        {
            m_EndLenFrac.Set( d / chord );
        }
        else
        {
            m_EndLength.Set( d );
        }
    }

    curve_point_type telow, teup;
    telow = c.f( vtelow );
    teup = c.f( vteup );

    curve_point_type lelow, leup;
    lelow = c.f( vlelow );
    leup = c.f( vleup );

    piecewise_curve_type clow, cup;
    c.split( clow, cup, vle );


    double vlow, vup;

    if ( m_SurfType() != LOWER_SURF )
    {
        if ( !m_LEFlag() )
        {
            eli::geom::intersect::specified_distance( vup, cup, teup, d );
        }
        else
        {
            eli::geom::intersect::specified_distance( vup, cup, leup, d );
        }
        c_uws_upper = vec3d( m_UStart(), vup / vmax, 0 );
        m_UWStart.push_back( c_uws_upper );
    }

    if ( m_SurfType() != UPPER_SURF )
    {
        if ( !m_LEFlag() )
        {
            eli::geom::intersect::specified_distance( vlow, clow, telow, d );
        }
        else
        {
            eli::geom::intersect::specified_distance( vlow, clow, lelow, d );
        }
        c_uws_lower = vec3d( m_UStart(), vlow / vmax, 0 );
        m_UWStart.push_back( c_uws_lower );
    }

    VspCurve endcrv;
    surf->GetU01ConstCurve( endcrv, m_UEnd() );
    c = endcrv.GetCurve();

    te = c.f( vmin );
    le = c.f( vle );

    chord = dist( le, te );


    if ( m_AbsRelFlag() == vsp::REL )
    {
        d = chord * m_EndLenFrac();
        m_EndLength.Set( d );
    }
    else
    {
        d = m_EndLength();
        m_EndLenFrac.Set( d / chord );
    }

    telow = c.f( vtelow );
    teup = c.f( vteup );
    lelow = c.f( vlelow );
    leup = c.f( vleup );

    c.split( clow, cup, vle );

    if ( m_SurfType() != LOWER_SURF )
    {
        if ( !m_LEFlag() )
        {
            eli::geom::intersect::specified_distance( vup, cup, teup, d );
        }
        else
        {
            eli::geom::intersect::specified_distance( vup, cup, leup, d );
        }
        c_uwe_upper = vec3d( m_UEnd(), vup / vmax, 0 );
        m_UWEnd.push_back( c_uwe_upper );
    }

    if ( m_SurfType() != UPPER_SURF )
    {
        if ( !m_LEFlag() )
        {
            eli::geom::intersect::specified_distance( vlow, clow, telow, d );
        }
        else
        {
            eli::geom::intersect::specified_distance( vlow, clow, lelow, d );
        }
        c_uwe_lower = vec3d( m_UEnd(), vlow / vmax, 0 );
        m_UWEnd.push_back( c_uwe_lower );
    }

    // Build Control Surface

    if ( !m_LEFlag() )
    {
        if ( m_SurfType() == UPPER_SURF )
        {
            pnt_vec.resize( 4 );
            pnt_vec[0] = vec3d( m_UStart(), 1, 0 );
            pnt_vec[1] = c_uws_upper;
            pnt_vec[2] = c_uwe_upper;
            pnt_vec[3] = vec3d( m_UEnd(), 1, 0 );
        }
        else if ( m_SurfType() == LOWER_SURF )
        {
            pnt_vec.resize( 4 );
            pnt_vec[0] = vec3d( m_UStart(), 0, 0 );
            pnt_vec[1] = c_uws_lower;
            pnt_vec[2] = c_uwe_lower;
            pnt_vec[3] = vec3d( m_UEnd(), 0, 0 );
        }
        else
        {
            pnt_vec.resize( 8 );
            pnt_vec[0] = vec3d( m_UStart(), 1, 0 );
            pnt_vec[1] = c_uws_upper;
            pnt_vec[2] = c_uwe_upper;
            pnt_vec[3] = vec3d( m_UEnd(), 1, 0 );
            pnt_vec[4] = vec3d( m_UEnd(), 0, 0 );
            pnt_vec[5] = c_uwe_lower;
            pnt_vec[6] = c_uws_lower;
            pnt_vec[7] = vec3d( m_UStart(), 0, 0 );
        }
        //  pnt_vec[3] = pnt_vec[0];
    }
    else
    {
        if ( m_SurfType() == UPPER_SURF )
        {
            pnt_vec.resize( 5 );
            pnt_vec[0] = vec3d( m_UEnd(), 0.5, 0 );
            pnt_vec[1] = c_uwe_upper;
            pnt_vec[2] = c_uws_upper;
            pnt_vec[3] = vec3d( m_UStart(), 0.5, 0 );
            pnt_vec[4] = pnt_vec[0];
        }
        else if ( m_SurfType() == LOWER_SURF )
        {
            pnt_vec.resize( 5 );
            pnt_vec[3] = vec3d( m_UEnd(), 0.5, 0 );
            pnt_vec[2] = c_uwe_lower;
            pnt_vec[1] = c_uws_lower;
            pnt_vec[0] = vec3d( m_UStart(), 0.5, 0 );
            pnt_vec[4] = pnt_vec[0];
        }
        else
        {
            pnt_vec.resize( 8 );
            pnt_vec[0] = vec3d( m_UEnd(), 0.5, 0 );
            pnt_vec[1] = c_uwe_upper;
            pnt_vec[2] = c_uws_upper;
            pnt_vec[3] = vec3d( m_UStart(), 0.5, 0 );
            pnt_vec[4] = vec3d( m_UStart(), 0.5, 0 );
            pnt_vec[5] = c_uws_lower;
            pnt_vec[6] = c_uwe_lower;
            pnt_vec[7] = vec3d( m_UEnd(), 0.5, 0 );
        }
        //  pnt_vec[3] = pnt_vec[0];
    }

    int pind = 0;
    int num_segs = pnt_vec.size() - 1;

    if ( m_SurfType() == BOTH_SURF )
    {
        num_segs--;
    }


    m_LVec.resize( num_segs );

    for ( int i = 0; i < num_segs; i++ )
    {
        if ( m_SurfType() == BOTH_SURF && i == 3 )
        {
            pind++;
        }
        m_LVec[i].SetSP0( pnt_vec[pind] );
        pind++;
        m_LVec[i].SetSP1( pnt_vec[pind] );
        m_LVec[i].Update( geom );
    }

    SubSurface::Update();
}
Exemplo n.º 4
0
void EditorHandler::redisplay(double t, double dt)
{
    if (editors.empty()) {
        return;
    }

    if (update) {
        for (unsigned int i = 0; i < editors.size(); ++i) {
            if (editors[i]->isActive()) {
                editors[i]->update();
            }
        }
        update = false;
    }
    // mouse in world space
    vec3d p = getPosition(lastPos.x, lastPos.y);

    // camera in local space, altitude in local space
    float altitude = -1.0f;
    for (unsigned int i = 0; i < editors.size(); ++i) {
        if (editors[i]->isActive()) {
            mat4d screenToLocal = editors[i]->getTerrain()->getLocalToScreen().inverse();
            vec4d c = screenToLocal * vec4d(0.0, 0.0, 1.0, 0.0);
            double cx = c.x / c.w;
            double cy = c.y / c.w;
            double cz = c.z / c.w;
            if (isFinite(cx) && isFinite(cy)) {
                vec3d dv = editors[i]->getTerrainNode()->deform->deformedToLocal(vec3d(cx, cy, cz));
                if (isFinite(dv.z)) {
                    altitude = dv.z;
                    break;
                }
            }
        }
    }

    // field of view angle
    vec4d frustum[6];
    ptr<SceneManager> manager = editors[0]->getTerrain()->getOwner();
    SceneManager::getFrustumPlanes(manager->getCameraToScreen(), frustum);
    vec3d left = frustum[0].xyz().normalize();
    vec3d right = frustum[1].xyz().normalize();
    float fov = (float) safe_acos(-left.dotproduct(right));

    // pencil radius
    radius = altitude * tan(fov / 2.0) * relativeRadius;

    for (unsigned int i = 0; i < editors.size(); ++i) {
        if (editors[i]->isActive()) {
            editors[i]->setPencil(vec4f(p.x, p.y, p.z, radius), vec4f(brushColor[0], brushColor[1], brushColor[2], brushColor[3]), paint);
        }
    }
    if (newStrokes > 0) {
        for (unsigned int i = 0; i < editors.size(); ++i) {
            if (editors[i]->isActive()) {
                editors[i]->edit(strokes);
            }
        }
    }
    newStrokes = 0;
}
Exemplo n.º 5
0
void 
TestLocalXform::testScaling()
{
    USING_NK_NS
    USING_NKHIVE_NS

    LocalXform xform(vec3d(0.1, 0.2, 0.5));

    CPPUNIT_ASSERT(xform.localToVoxel(vec3d(0, 0, 0)) == vec3d(0, 0, 0));
    CPPUNIT_ASSERT(xform.localToVoxel(vec3d(1, 1, 1)) == vec3d(0.1, 0.2, 0.5));
    CPPUNIT_ASSERT(xform.localToVoxel(vec3d(10, 5, 2)) == vec3d(1, 1, 1));

    CPPUNIT_ASSERT(xform.voxelToLocal(vec3d(10, 5, 2)) == vec3d(100, 25, 4));
    CPPUNIT_ASSERT(xform.voxelToLocal(vec3d(1, 1, 1)) == vec3d(10, 5, 2));
    CPPUNIT_ASSERT(xform.voxelToLocal(vec3d(0.1, 0.2, 0.5)) == vec3d(1, 1, 1));
    CPPUNIT_ASSERT(xform.voxelToLocal(vec3d(0, 0, 0)) == vec3d(0, 0, 0));
}
Exemplo n.º 6
0
	  Plane(double o=0.0f, vec3d n=vec3d(0,0,0)): mNormal(n), mOrigin(o) {}
Exemplo n.º 7
0
BTEIFGL_API int Bt2Ent_ScriptUpdate(double dt)
{
	BSVM2_Value targs[4];
	double org[3];
	BSVM2_Context *vctx;
	BSVM2_Value *args;
	int i;

	if(!dtvNullP(bt2ent_voxworld->ent_player))
	{
		org[0]=bt2ent_voxworld->reforg[0]+bt2ent_voxworld->camorg[0];
		org[1]=bt2ent_voxworld->reforg[1]+bt2ent_voxworld->camorg[1];
		org[2]=bt2ent_voxworld->reforg[2]+bt2ent_voxworld->camorg[2];
		Bt2Ent_EntSetOrigin(bt2ent_voxworld->ent_player,
			vec3d(org[0], org[1], org[2]));
	}

	Bt2Ent_SetGlobalVec3("player_reforg", vec3d(
			bt2ent_voxworld->reforg[0],
			bt2ent_voxworld->reforg[1],
			bt2ent_voxworld->reforg[2]));

	Bt2Ent_SetGlobalVec3("player_view_fw", vec3d(
			bt2ent_voxworld->camrot[1*3+0],
			bt2ent_voxworld->camrot[1*3+1],
			bt2ent_voxworld->camrot[1*3+2]));
	Bt2Ent_SetGlobalVec3("player_view_rt", vec3d(
			bt2ent_voxworld->camrot[0*3+0],
			bt2ent_voxworld->camrot[0*3+1],
			bt2ent_voxworld->camrot[0*3+2]));
	Bt2Ent_SetGlobalVec3("player_view_up", vec3d(
			bt2ent_voxworld->camrot[2*3+0],
			bt2ent_voxworld->camrot[2*3+1],
			bt2ent_voxworld->camrot[2*3+2]));

	if(!bt2ent_vi_update)
		return(-1);

	args=targs;
	args[0].d=dt;

//	Bt2Ent_SetGlobalA("world_entity", bt2ent_map_entarr);
//	Bt2Ent_SetGlobalI("world_max_entity", bt2ent_map_nents);

	i=Bt2Ent_GetGlobalI("world_max_entity");
	if(i>bt2ent_voxworld->nents)
		bt2ent_voxworld->nents=i;

	Bt2Ent_SetGlobalA("world_entity", bt2ent_voxworld->entarr);
	Bt2Ent_SetGlobalI("world_max_entity", bt2ent_voxworld->nents);

	vctx=BSVM2_Interp_AllocPoolContext();
	BSVM2_Interp_SetupCallVM(vctx, bt2ent_vi_update, args);
	BSVM2_Interp_RunContext(vctx, 999999999);
	BSVM2_Interp_FreePoolContext(vctx);

	bt2ent_voxworld->entarr=Bt2Ent_GetGlobalA("world_entity");
	i=Bt2Ent_GetGlobalI("world_max_entity");
	if(i!=bt2ent_voxworld->nents)
		bt2ent_voxworld->nents=i;

	return(0);
}
void TestLinAlg()
{
    // Instantiate templates, check sizes, make sure operators compile etc.

    static_assert(sizeof(Vec2f)     == 8  , "Vec2f size test failed"    );
    static_assert(sizeof(Vec3f)     == 12 , "Vec3f size test failed"    );
    static_assert(sizeof(Vec4f)     == 16 , "Vec4f size test failed"    );
    static_assert(sizeof(Vec2d)     == 16 , "Vec2d size test failed"    );
    static_assert(sizeof(Vec3d)     == 24 , "Vec3d size test failed"    );
    static_assert(sizeof(Vec4d)     == 32 , "Vec4d size test failed"    );
    static_assert(sizeof(Vec2i)     == 8  , "Vec2i size test failed"    );
    static_assert(sizeof(Vec3i)     == 12 , "Vec3i size test failed"    );
    static_assert(sizeof(Vec4i)     == 16 , "Vec4i size test failed"    );
    static_assert(sizeof(Vec2ui)    == 8  , "Vec2ui size test failed"   );
    static_assert(sizeof(Vec3ui)    == 12 , "Vec3ui size test failed"   );
    static_assert(sizeof(Vec4ui)    == 16 , "Vec4ui size test failed"   );
    static_assert(sizeof(Matrix44f) == 64 , "Matrix44f size test failed");
    static_assert(sizeof(Matrix44d) == 128, "Matrix44d size test failed");

    Vec2f vec2f(0.0f, 0.0f);
    Vec3f vec3f(0.0f, 0.0f, 0.0f);
    Vec4f vec4f(0.0f, 0.0f, 0.0f, 0.0f);
    Vec2d vec2d(0.0, 0.0);
    Vec3d vec3d(0.0, 0.0, 0.0);
    Vec4d vec4d(0.0, 0.0, 0.0, 0.0);
    Vec2i vec2i(-1, -1);
    Vec3i vec3i(-1, -1, -1);
    Vec4i vec4i(-1, -1, -1, -1);
    Vec2ui vec2ui(0, 0);
    Vec3ui vec3ui(0, 0, 0);
    Vec4ui vec4ui(0, 0, 0, 0);
    float f = 0.0f;
    bool b = false;

    b = (vec3f == vec3f);
    b = (vec3f != vec3f);
    vec3f = Vec3f(1.0f) + Vec3f(2.0f);
    vec3f = Vec3f(1.0f) - Vec3f(2.0f);
    vec3f = Vec3f(1.0f) * Vec3f(2.0f);
    vec3f = Vec3f(1.0f) / Vec3f(2.0f);
    vec3f = Vec3f(1.0f) * f;
    vec3f = f * Vec3f(1.0f);
    vec3f = Vec3f(1.0f) / f;
    vec3f = -Vec3f(1.0f);
    vec3f += Vec3f(1.0f);
    vec3f -= Vec3f(1.0f);
    vec3f *= Vec3f(1.0f);
    vec3f /= Vec3f(1.0f);
    vec3f *= f;
    vec3f /= f;
    f = vec3f[0];
    vec3f[0] = f;
    f = Length(vec3f);
    f = LengthSquared(vec3f);
    vec3f = Normalize(vec3f);
    f = Dot(Vec3f(1.0f), Vec3f(2.0f));
    vec3f = Vec3f(1.0f) ^ Vec3f(2.0f);

    Matrix44f matf;
    matf.Identity();
    Matrix44d matd;
    matf.RotationX(1);
    matf.RotationY(1);
    matf.RotationZ(1);
    matf.Scaling(1);
    b = matf == matf;
    matf = matf * matf;
    matf.BuildLookAtMatrix(Vec3f(0.0f, 10.0f, 10.0f), Vec3f(0.0f));
    matf.BuildProjection(90.0f, 4.0f / 3.0f, 1.0f, 1000.0f);
    Vec3f out;
    matf.Transf3x3(vec3f, out);
    matf.Transf4x4(vec3f, out);
    matf.Transpose3x3();
    matf.Transpose4x4();
    matf.Invert();
}
Exemplo n.º 9
0
void CMainState::CalculateDataAlignment()
{
	CProgramContext::SScene & Scene = Context->Scene;

	CSite * CurrentSite = Context->CurrentSite;
	CDataSet const * const DataSet = CurrentSite->GetCurrentDataSet();
	STable & Points = CurrentSite->GetCurrentDataSet()->Points;
	
	longlatd MapLonLatMin;
	longlatd MapLonLatMax;

	if (CurrentSite->GetCurrentLocation())
	{
		MapLonLatMin = (CurrentSite->GetCurrentLocation()->LowerBound);
		MapLonLatMax = (CurrentSite->GetCurrentLocation()->UpperBound);
	}

	SRange<f64> XRange = Points.GetFieldRange(CurrentSite->GetCurrentDataSet()->Traits.PositionXField, 15.0);
	SRange<f64> YRange = Points.GetFieldRange(CurrentSite->GetCurrentDataSet()->Traits.PositionYField, 15.0);
	SRange<f64> ZRange = Points.GetFieldRange(CurrentSite->GetCurrentDataSet()->Traits.PositionZField, 15.0);
	
	if (XRange.IsEmpty())
		XRange = SRange<f64>(MapLonLatMin.Longitude, MapLonLatMax.Longitude);
	if (YRange.IsEmpty())
		YRange = SRange<f64>(-1, 1);
	if (ZRange.IsEmpty())
		ZRange = SRange<f64>(MapLonLatMin.Latitude, MapLonLatMax.Latitude);

	printf("Longlat range is %g %g to %g %g\n", XRange.Minimum, ZRange.Minimum, XRange.Maximum, ZRange.Maximum);

	longlatd const DataLonLatMin(XRange.Minimum, ZRange.Minimum), DataLonLatMax(XRange.Maximum, ZRange.Maximum);
	longlatd const DataLonLatCenter = (DataSet->ManuallySetDataLongLat ? DataSet->DataLonLatCenter : (DataLonLatMin + DataLonLatMax) / 2.f);
	
	vec2d DataRangeMin, DataRangeMax, MapRangeMin, MapRangeMax;
	sharedPtr<longlatd::IProjectionSystem> Projection;
	if (ProjectionMode == 0)
		Projection = sharedNew(new longlatd::CHaversineProjection());
	else if (ProjectionMode == 1)
		Projection = sharedNew(new longlatd::CVincentyProjection());
	else if (ProjectionMode == 2)
		Projection = sharedNew(new longlatd::CEquirectangularProjection(DataLonLatCenter.Latitude));

	DataRangeMin = DataLonLatCenter.OffsetTo(DataLonLatMin, Projection);
	DataRangeMax = DataLonLatCenter.OffsetTo(DataLonLatMax, Projection);

	if (CurrentSite->GetCurrentLocation())
	{
		MapRangeMin = DataLonLatCenter.OffsetTo(MapLonLatMin, Projection);
		MapRangeMax = DataLonLatCenter.OffsetTo(MapLonLatMax, Projection);
	}
	else
	{
		MapRangeMin = DataLonLatCenter.OffsetTo(DataLonLatMin, Projection);
		MapRangeMax = DataLonLatCenter.OffsetTo(DataLonLatMax, Projection);
	}

	vec2d const DataRangeSize = (DataSet->ManuallySetDataLongLat ? DataLonLatMax - DataLonLatMin : DataRangeMax - DataRangeMin);
	vec2d const DataRangeCenter = (DataSet->ManuallySetDataLongLat ? DataRangeSize / 2 : (DataRangeMin + DataRangeMax) / 2.f);
	f64 const DataDepth = YRange.Size();
	
	vec2d const MapRangeSize = MapRangeMax - MapRangeMin;
	vec2d const MapRangeCenter = (MapRangeMin + MapRangeMax) / 2.f;
	f64 const MapDepth = DataSet->MapDepth;
	
	printf("Data range is %f by %f meters,\n", DataRangeSize.X, DataRangeSize.Y);
	printf("Terrain range is %f by %f meters,\n", MapRangeSize.X, MapRangeSize.Y);
	
	vec2d const ActualOffset = MapRangeCenter - DataRangeCenter;
	vec2d const MapOffset = ActualOffset * 3.f / Maximum(DataRangeSize.X, DataRangeSize.Y);
	vec3d const DataScale = 3.0 * vec3d(DataRangeSize.X, DataDepth, DataRangeSize.Y) / Maximum(DataRangeSize.X, DataRangeSize.Y);
	vec3d const MapScale = DataScale * vec3d(MapRangeSize.X, MapDepth, MapRangeSize.Y) / vec3d(DataRangeSize.X, 1, DataRangeSize.Y);

	static f64 const YExaggeration = DataSet->YExaggeration;
	static vec3d const Multiplier = vec3d(1, YExaggeration, 1);

    printf("Main State Transforms\n");
	
	Scene.Glyphs->GetNode()->SetScale(DataScale * Multiplier);
    Scene.Volume->GetNode()->SetScale(DataScale * Multiplier);
	Scene.Glyphs->GetNode()->SetTranslation(vec3f(0, -DataScale.Y * YExaggeration / 2, 0));
	Scene.Volume->GetNode()->SetTranslation(vec3f(0, -DataScale.Y * YExaggeration / 2, 0));
    
	Scene.Terrain->GetNode()->SetScale(MapScale * Multiplier / CTerrainNodeManager::Size);
	//Scene.Water->SetScale(MapScale / CTerrainNodeManager::Size);

	Scene.Terrain->GetNode()->SetTranslation(vec3f(MapOffset.X, 0, -MapOffset.Y));
	//Scene.Water->SetTranslation(vec3f(MapOffset.X, 0, -MapOffset.Y));

	//// Flip for RHC->LHC
	Scene.Glyphs->GetNode()->SetScale(Scene.Glyphs->GetNode()->GetScale() * vec3f(1, 1, -1));
    Scene.Volume->GetNode()->SetScale(Scene.Volume->GetNode()->GetScale() * vec3f(1, 1, -1));
	Scene.Terrain->GetNode()->SetScale(Scene.Terrain->GetNode()->GetScale() * vec3f(1, 1, -1));
	//Scene.Water->SetScale(Scene.Water->GetScale() * vec3f(1, 1, -1));

	//// Flip Height -> Depth
	Scene.Volume->GetNode()->SetScale(Scene.Volume->GetNode()->GetScale() * vec3f(1, -1, 1));
    Scene.Glyphs->GetNode()->SetScale(Scene.Glyphs->GetNode()->GetScale() * vec3f(1, -1, 1));
    }
Exemplo n.º 10
0
//========================================================//
//========================================================//
//========================= Main =========================//
int main( int argc, char** argv )
{
//==== Use CPPTest =====//
    run_tests();
    printf("\n\n");

//==== Use Case 1 ====//
    printf( "\n//==== Use Case 1 ====//\n");
    printf( "Description: Create/Delete/Copy/Paste Geometry\n" );

    //==== Create/Delete/Copy/Paste Geometry ====//
    printf( "Checking Setup\n" );
    vsp::VSPCheckSetup();
    vsp::VSPRenew();
    vsp::ErrorMgr.PopErrorAndPrint( stdout );

    //==== Print Out All Available Geom Types ====//
    vector<string> types = vsp::GetGeomTypes( );
    printf( "All available Geom types.\n" );
    for ( int i = 0 ; i < ( int )types.size() ; i++ )
    {
        printf( "Type %d = %s \n", i, types[i].c_str() );
    }
    vsp::ErrorMgr.PopErrorAndPrint( stdout );

    //==== Add Fuselage Geom =====//
    printf( "Adding a fuselage\n" );
    string fuse_id = vsp::AddGeom( "FUSELAGE" );
    vsp::ErrorMgr.PopErrorAndPrint( stdout );

    //==== Add Pod Geom =====//
    printf( "Adding a pod\n" );
    string pod_id = vsp::AddGeom( "POD", fuse_id );
    vsp::ErrorMgr.PopErrorAndPrint( stdout );

    //==== Edit the Pod ====//
    printf( "Editing the pod\n" );
    //==== Set Name ====//
    vsp::SetGeomName( pod_id, "Pod" );
    //==== Change Length ====//
    string len_id = vsp::GetParm( pod_id, "Length", "Design" );
    vsp::SetParmValUpdate( len_id, 7.0 );
    //==== Change Finess Ration
    vsp::SetParmValUpdate( pod_id, "FineRatio", "Design", 10.0 );
    //==== Change Y Location ====//
    string y_loc_id = vsp::GetParm( pod_id, "Y_Rel_Location", "XForm" );
    vsp::SetParmValUpdate( y_loc_id, 1.0 );
    //==== Change X Location ====//
    vsp::SetParmValUpdate( pod_id, "X_Rel_Location", "XForm", 3.0 );
    //==== Change Symmetry =====//
    string sym_flag_id = vsp::GetParm( pod_id, "Sym_Planar_Flag", "Sym" );
    vsp::SetParmValUpdate( sym_flag_id, vsp::SYM_XZ  );
    vsp::ErrorMgr.PopErrorAndPrint( stdout );

    //==== Copy/Paste Pod Geom =====//
    printf( "Copy/Paste pod\n" );
    vsp::CopyGeomToClipboard( pod_id );
    vsp::PasteGeomClipboard( fuse_id );         // Make fuse_id parent
    //==== Set Name ====//
    vsp::SetGeomName( pod_id, "Original_Pod" );
    string second_pod_id = vsp::FindGeom( "Pod", 0 );
    vsp::ErrorMgr.PopErrorAndPrint( stdout );

    //==== Change Y Location ====//
    printf( "Edit second pod\n" );
    vsp::SetParmVal( second_pod_id, "Sym_Planar_Flag", "Sym", 0 );
    vsp::SetParmVal( second_pod_id, "Y_Rel_Location", "XForm", 0.0 );
    vsp::SetParmVal( second_pod_id, "Z_Rel_Location", "XForm", 1.0 );
    vsp::ErrorMgr.PopErrorAndPrint( stdout );

    //==== List out all geoms ====//
    printf( "All geoms in Vehicle:\n" );
    vector<string> geoms = vsp::FindGeoms();
    for ( int i = 0; i < ( int ) geoms.size(); i++ )
    {
        printf( "Geom id: %s name: %s \n", geoms[i].c_str(), vsp::GetGeomName( geoms[i] ).c_str() );
    }
    vsp::ErrorMgr.PopErrorAndPrint( stdout );

    //==== Save Vehicle to File ====//
    string fname = "apitest.vsp3";
    vsp::WriteVSPFile( fname );
    printf( "Saved file to: %s\n",fname.c_str() );
    vsp::ErrorMgr.PopErrorAndPrint( stdout );

//==== Use Case 2 ====//
    printf( "\n//==== Use Case 2 ====//\n");
    printf( "Description: Fuselage editing\n" );

    //==== Reset Geometry ====//
    printf( "Resetting VSP model to blank slate\n" );
    vsp::VSPRenew();
    vsp::ErrorMgr.PopErrorAndPrint( stdout );

    //==== List out all geoms ====//
    printf( "All geoms in Vehicle:\n" );
    geoms = vsp::FindGeoms();
    for ( int i = 0; i < ( int ) geoms.size(); i++ )
    {
        printf( "Geom id: %s name: %s \n", geoms[i].c_str(), vsp::GetGeomName( geoms[i] ).c_str() );
    }
    vsp::ErrorMgr.PopErrorAndPrint( stdout );

    //==== Add Fuselage Geom =====//
    printf( "Adding a fuselage\n" );
    fuse_id = vsp::AddGeom( "FUSELAGE" );
    vsp::ErrorMgr.PopErrorAndPrint( stdout );

    //==== List out all geoms ====//
    printf( "All geoms in Vehicle:\n" );
    geoms = vsp::FindGeoms();
    for ( int i = 0; i < ( int ) geoms.size(); i++ )
    {
        printf( "Geom id: %s name: %s \n", geoms[i].c_str(), vsp::GetGeomName( geoms[i] ).c_str() );
    }
    vsp::ErrorMgr.PopErrorAndPrint( stdout );

    //==== Get XSec Surf ID ====//
    printf( "Change one of the cross-sections to use XS_SUPER_ELLIPSE type\n" );
    string xsurf_id = vsp::GetXSecSurf( fuse_id, 0 );
    //==== Change Type of First XSec ====//
    vsp::ChangeXSecShape( xsurf_id, 0, vsp::XS_SUPER_ELLIPSE );
    //==== Change Type of First XSec ====//
    string xsec_id = vsp::GetXSec( xsurf_id, 0 );
    string width_id  = vsp::GetXSecParm( xsec_id, "Super_Width" );
    string height_id = vsp::GetXSecParm( xsec_id, "Super_Height" );
    vsp::SetParmVal( width_id, 4.0 );
    vsp::SetParmVal( height_id, 2.0 );
    vsp::ErrorMgr.PopErrorAndPrint( stdout );

    //==== Copy Cros-Section to Clipboard ====//
    printf( "Copy/Paste cross-section\n" );
    vsp::CopyXSec( xsurf_id, 0 );        //FIXME: this operation can't fine this geometry
    vsp::ErrorMgr.PopErrorAndPrint( stdout );
    //==== Paste Cross-Section ====///
    vsp::PasteXSec( xsurf_id, 1 );
    vsp::PasteXSec( xsurf_id, 2 );
    vsp::PasteXSec( xsurf_id, 3 );
    vsp::ErrorMgr.PopErrorAndPrint( stdout );

    //===== Change Type To File XSec ====//
    printf( "Change one of the cross-sections to use XS_FILE_FUSE type\n" );
    vsp::ChangeXSecShape( xsurf_id, 0, vsp::XS_FILE_FUSE );
    string file_xsec_id = vsp::GetXSec( xsurf_id, 0 );
    //===== Build Point Vec ====//
    vector< vec3d > pnt_vec;
    pnt_vec.push_back( vec3d( 0.0, 0.0, 2.0 ) );
    pnt_vec.push_back( vec3d( 0.0, 1.0, 0.0 ) );
    pnt_vec.push_back( vec3d( 0.0, 0.0, -2.0 ) );
    pnt_vec.push_back( vec3d( 0.0, -1.0, 0.0 ) );
    pnt_vec.push_back( vec3d( 0.0, 0.0, 2.0 ) );
    //===== Load Point Into XSec ====//
    vsp::SetXSecPnts( file_xsec_id, pnt_vec );
    vsp::ErrorMgr.PopErrorAndPrint( stdout );

    //==== List out all geoms ====//
    printf( "All geoms in Vehicle:\n" );
    geoms = vsp::FindGeoms();
    for ( int i = 0; i < ( int ) geoms.size(); i++ )
    {
        printf( "Geom id: %s name: %s \n", geoms[i].c_str(), vsp::GetGeomName( geoms[i] ).c_str() );
    }
    vsp::ErrorMgr.PopErrorAndPrint( stdout );

//==== Use Case 3 ====//
    printf( "\n//==== Use Case 3 ====//\n");
    printf( "Description: Read in first-case file.\n" );

    //==== Reset Geometry ====//
    printf( "Resetting VSP model to blank slate\n" );
    vsp::VSPRenew();
    vsp::ErrorMgr.PopErrorAndPrint( stdout );

    //==== Read Geometry From File ====//
    printf( "Reading model from: %s\n",fname.c_str() );
    vsp::ReadVSPFile( fname );
    vsp::ErrorMgr.PopErrorAndPrint( stdout );

    //==== List out all geoms ====//
    printf( "All geoms in Vehicle:\n" );
    geoms = vsp::FindGeoms();
    for ( int i = 0; i < ( int ) geoms.size(); i++ )
    {
        printf( "Geom id: %s name: %s \n", geoms[i].c_str(), vsp::GetGeomName( geoms[i] ).c_str() );
    }
    vsp::ErrorMgr.PopErrorAndPrint( stdout );

//==== Final check for errors ====//
    printf( "\n//==== Final check for errors ====//\n" );
    //==== Check And Print Any Errors ====//
    int num_err = vsp::ErrorMgr.GetNumTotalErrors();
    for ( int i = 0 ; i < num_err ; i++ )
    {
        vsp::ErrorObj err = vsp::ErrorMgr.PopLastError();
        printf( "err = %s\n", err.m_ErrorString.c_str() );
    }

    vsp::StartGui();

}
Exemplo n.º 11
0
//******* Cross Product:  a = cross(a, b) ******//
 vec3d cross(const vec3d& a, const vec3d& b)
{
    return vec3d(a.v[1]*b.v[2] - a.v[2]*b.v[1], 
                 a.v[2]*b.v[0] - a.v[0]*b.v[2], 
                 a.v[0]*b.v[1] - a.v[1]*b.v[0]);
}
Exemplo n.º 12
0
pt3d hwt3d_step(float ***vv,
		pt3d Tm, 
		pt3d To, 
		pt3d Gm, 
		pt3d Gp,
		pt3d Hm,
		pt3d Hp)
/*< one HWT time step >*/
{
    double gdx,gdy,gdz,gdr;
    double hdx,hdy,hdz,hdr;
    double ddx,ddy,ddz;
    double ax,bx,ay,by,az,bz;
    double a,b,c,del;

    double dx,dy,dz;

    pt3d Sm,Sp,S;
    vc3d TmTo,ToSm,ToSp;
    double am,ap;
    float ro;

/*------------------------------------------------------------*/

    ro = To.v * at.d;       /* ray step */

    gdx = Gp.x-Gm.x;
    gdy = Gp.y-Gm.y;
    gdz = Gp.z-Gm.z;
    gdr =(Gp.v-Gm.v)*at.d;

    hdx = Hp.x-Hm.x;
    hdy = Hp.y-Hm.y;
    hdz = Hp.z-Hm.z;
    hdr =(Hp.v-Hm.v)*at.d;

    /* find largest dd (avoid division by 0) */
    ddz = gdy*hdx - gdx*hdy;
    ddx = gdz*hdy - gdy*hdz;
    ddy = gdx*hdz - gdz*hdx;

    if( SF_ABS(ddz) >=SF_ABS(ddx) && 
	SF_ABS(ddz) > SF_ABS(ddy)) {

	ax  = gdr*hdy - hdr*gdy; 
	bx  = gdy*hdz - gdz*hdy; 
	ay  = gdr*hdx - gdx*hdr; 
	by  = gdx*hdz - gdz*hdx; 
	
	a = ddz*ddz + bx*bx + by*by;
	b =         -(ax*bx + ay*by);           b *= ro;
	c =           ax*ax + ay*ay - ddz*ddz;  c *= ro*ro;
	
	del = SF_MAX(b*b - a*c , 0.);
	del = sqrtf(del);
		
	dz = (-b+del)/a;  Sp.z = To.z + dz;
	dx = ro*ax-dz*bx; Sp.x = To.x + dx/  ddz;
	dy = ro*ay-dz*by; Sp.y = To.y + dy/(-ddz);
	
	dz = (-b-del)/a;  Sm.z = To.z + dz;
	dx = ro*ax-dz*bx; Sm.x = To.x + dx/  ddz;
	dy = ro*ay-dz*by; Sm.y = To.y + dy/(-ddz);
	
    } else if( SF_ABS(ddx) >=SF_ABS(ddy) &&
	       SF_ABS(ddx) > SF_ABS(ddz)) {

	ay  = gdr*hdz - hdr*gdz; 
	by  = gdz*hdx - gdx*hdz; 
	az  = gdr*hdy - gdy*hdr; 
	bz  = gdy*hdx - gdx*hdy; 

	a = ddx*ddx + by*by + bz*bz;
	b =         -(ay*by + az*bz);           b *= ro;
	c =           ay*ay + az*az - ddx*ddx;  c *= ro*ro;
	
	del = SF_MAX(b*b - a*c , 0.);
	del = sqrtf(del);

	dx = (-b+del)/a;  Sp.x = To.x + dx;
	dy = ro*ay-dx*by; Sp.y = To.y + dy/  ddx;
	dz = ro*az-dx*bz; Sp.z = To.z + dz/(-ddx);
	
	dx = (-b-del)/a;  Sm.x = To.x + dx;
	dy = ro*ay-dx*by; Sm.y = To.y + dy/  ddx;
	dz = ro*az-dx*bz; Sm.z = To.z + dz/(-ddx);

    } else {

	az  = gdr*hdx - hdr*gdx; 
	bz  = gdx*hdy - gdy*hdx; 
	ax  = gdr*hdz - gdz*hdr; 
	bx  = gdz*hdy - gdy*hdz; 

	a = ddy*ddy + bz*bz + bx*bx;
	b =         -(az*bz + ax*bx);           b *= ro;
	c =           az*az + ax*ax - ddy*ddy;  c *= ro*ro;
	
	del = SF_MAX(b*b - a*c , 0.);
	del = sqrtf(del);

	dy = (-b+del)/a;  Sp.y = To.y + dy;
	dz = ro*az-dy*bz; Sp.z = To.z + dz/  ddy;
	dx = ro*ax-dy*bx; Sp.x = To.x + dx/(-ddy);
	
	dy = (-b-del)/a;  Sm.y = To.y + dy;
	dz = ro*az-dy*bz; Sm.z = To.z + dz/  ddy;
	dx = ro*ax-dy*bx; Sm.x = To.x + dx/(-ddy);
    }

    TmTo = vec3d( &Tm, &To); /* incomming ray */
    ToSm = vec3d( &To, &Sm); /* candidate ray */
    ToSp = vec3d( &To, &Sp); /* candidate ray */
    
    /* angle between ray segments */
    am = ang3d( &TmTo, &ToSm);
    ap = ang3d( &TmTo, &ToSp);

    /* select candidate point that moves forward */
    if(am<ap) S=Sm;
    else      S=Sp;
    S.v = hwt3d_getv(vv,S);

    return S;
}
Exemplo n.º 13
0
pt3d hwt3d_raytr(float ***vv,
		 pt3d Tm, 
		 pt3d To,
		 int scaleray)
/*< ray tracing >*/
{
    pt3d Tp;
    pt3d Gm,Gp,Hm,Hp;
    vc3d TmTo;

    double a1,a2,a3;
    vc3d   v1,v2,v3;
    vc3d   qq,uu,ww; /* unit vectors */
    float ro;

    ro = To.v * at.d; /* ray step */
    TmTo = vec3d(&Tm,&To);       /* ray vector */

    /* axes unit vectors */
    v1 = axa3d(1);
    v2 = axa3d(2);
    v3 = axa3d(3);

    /* ray angle with axes*/
    a1 = ang3d(&TmTo, &v1); a1 = SF_ABS(a1);
    a2 = ang3d(&TmTo, &v2); a2 = SF_ABS(a2);
    a3 = ang3d(&TmTo, &v3); a3 = SF_ABS(a3);

    /* select reference unit vector 
       as "most orthogonal" to an incomming ray 
     */
    if(      SF_ABS(a1-90) <= SF_ABS(a2-90) &&
	     SF_ABS(a1-90) <= SF_ABS(a3-90) )
	ww=v1;
    else if( SF_ABS(a2-90) <= SF_ABS(a1-90) &&
	     SF_ABS(a2-90) <= SF_ABS(a3-90) )
	ww=v2;
    else 
	ww=v3;

    /* build orthogonal wavefront (Gm,Gp,Hm,Hp) */

/*------------------------------------------------------------*/
    /* find Gm, Gp */
    uu   = vcp3d(&TmTo,&ww);       /* uu = TmTo x qq */
    qq   = nor3d(&uu);             /* qq = uu / |uu| */
    uu   = scl3d(&qq,ro*scaleray); /* uu = qq * ro */

    Gm   = tip3d(&To,&uu);         /* Gm at tip of +uu from To */
    qq   = scl3d(&uu,-1);
    Gp   = tip3d(&To,&qq);         /* Gp at tip of -uu from To */

    Gm.v = hwt3d_getv(vv,Gm);
    Gp.v = hwt3d_getv(vv,Gp);
/*------------------------------------------------------------*/
    uu = vec3d(&Gm,&Gp);
    ww = nor3d(&uu);
/*------------------------------------------------------------*/
    /* find Hm, Hp */
    uu   = vcp3d(&TmTo,&ww); 
    qq   = nor3d(&uu);
    uu   = scl3d(&qq,ro*scaleray);

    Hm   = tip3d(&To,&uu);
    qq   = scl3d(&uu,-1);
    Hp   = tip3d(&To,&qq);

    Hm.v = hwt3d_getv(vv,Hm);
    Hp.v = hwt3d_getv(vv,Hp);
/*------------------------------------------------------------*/

    /* execute HWT step 
     * from Tm & (Gm,Hm,To,Gp,Hp) to Tp
     */
    Tp=hwt3d_step(vv,Tm,To,Gm,Gp,Hm,Hp);
    return(Tp);
}
Exemplo n.º 14
0
/**
  Convert the geom object into another geom object.

  Currently the geom can only be converted into a TriMeshGeom.

  \image html plane_geom.png

 \todo Bereits vorhandene Variablen mit übernehmen
*/
void PlaneGeom::convert(GeomObject* target)
{
    TriMeshGeom* tm = dynamic_cast<TriMeshGeom*>(target);

    // Check if the target geom is really a TriMesh
    if (tm==0)
    {
        throw ENotImplementedError("Conversion not supported by the PlaneGeom");
    }

    double lenx = lx.getValue();
    double leny = ly.getValue();
    double lenx2 = lenx/2.0;
    double leny2 = leny/2.0;
    int segsx = segmentsx.getValue();
    int segsy = segmentsy.getValue();
    int i,j;
    if (segsx<1)
        segsx=1;
    if (segsy<1)
        segsy=1;


    // Set number of verts and faces
    tm->deleteAllVariables();
    tm->verts.resize((segsx+1)*(segsy+1));
    tm->faces.resize(2*segsx*segsy);
    tm->newVariable("st", VARYING, FLOAT, 2);

    ArraySlot<double>* stslot = dynamic_cast<ArraySlot<double>*>(&(tm->slot("st")));

    // Set vertices...
    for(j=0; j<=segsy; j++)
    {
        double v = double(j)/segsy;
        double y = v*leny - leny2;
        for(i=0; i<=segsx; i++)
        {
            double u = double(i)/segsx;
            double x = u*lenx - lenx2;
            int idx = j*(segsx+1)+i;
            tm->verts.setValue(idx, vec3d(x,y));
            double st[2] = {u,v};
            stslot->setValues(idx, st);
        }
    }

    // Set faces...
    for(j=0; j<segsy; j++)
    {
        for(i=0; i<segsx; i++)
        {
            int f[3];
            int idx = 2*(j*segsx + i);
            f[0] = j*(segsx+1) + i;
            f[1] = f[0]+1;
            f[2] = f[1]+segsx+1;
            tm->faces.setValues(idx, f);
            f[1] = f[2];
            f[2] = f[1]-1;
            tm->faces.setValues(idx+1, f);
        }
    }

}
Exemplo n.º 15
0
//===== Load Points from Curves ====//
void FuselageXSec::load_uniform_pnts()
{
  int j;
  double y, z;
  int num_pnt_half = num_pnts/2 + 1;

  double l_top    = top_crv.get_length();
  double l_bot    = bot_crv.get_length();
  double l_circle = (double)(corner_rad()*height()*(PI - DEG_2_RAD*top_tan_angle() - DEG_2_RAD*bot_tan_angle()) );

  double total_length = l_top + l_bot + l_circle;

  double len = total_length/(double)(num_pnt_half-1);

  int cnt = 0;
//  double rem_len = 0.0;
  double rem_len = len;

  //==== Check For Point ====//
  if ( total_length < 0.000001 )
  {
    for ( j = 0 ; j <  num_pnt_half ; j++ )
    {
      pnts[cnt] = top_crv.comp_pnt_per_length(0.0);
      cnt++;
    }
  }
  //==== Top Crv Points ====//
  if ( l_top > 0.000001)
  {
    double u = 0.0;
    double del_u = len/l_top;

    while ( u <= 1.00000001 && cnt < num_pnt_half )
    {
      pnts[cnt] = top_crv.comp_pnt_per_length((float)u);

      cnt++;
      u += del_u;
    }
    rem_len = (1.0 - (u - del_u))*l_top;
  }
   //==== Circle Points ====//
   if ( l_circle > 0.000001 && rem_len < l_circle )
     {
       double top_ang =  PI/2.0 - DEG_2_RAD*top_tan_angle();
       double bot_ang = -PI/2.0 + DEG_2_RAD*bot_tan_angle();

       double ang_per_len = (top_ang - bot_ang)/l_circle;

       double ang = (len - rem_len)*ang_per_len;

       while ( (top_ang - ang) >= bot_ang  && cnt <  num_pnt_half )
       {
         double c_ang =  top_ang - ang;

         y = (double)( width()/2.0 + corner_rad()*height()*(cos(c_ang) - 1.0) );
         z = (double)( max_width_loc()*height()/2.0 + corner_rad()*height()*sin(c_ang) );
         pnts[cnt] = vec3d( 0.0, y, z );
         cnt++;

         ang += len*ang_per_len;
       }
       ang -= len*ang_per_len;
	   if ( ang_per_len > 0.000001 )
			rem_len = ((top_ang - ang) - bot_ang)/ang_per_len;
	   else
		    rem_len = 0.0;
     }
  //==== Bot Crv Points ====//
  if ( l_bot > 0.000001)
  {
    double u = (len - rem_len)/l_bot;
    double del_u = len/l_bot;

    while ( u <= 1.000001 && cnt < num_pnt_half )
    {
      pnts[cnt] = bot_crv.comp_pnt_per_length((float)u);

      cnt++;
      u += del_u;
    }
  }

  //==== Fix Last Pnt ====//
  cnt = num_pnt_half-1;
  pnts[cnt] = bot_crv.comp_pnt_per_length(1.0);
  cnt++;

  //==== Reflection Points ====//
  int num_half_pnts = cnt;
  for ( j = num_half_pnts-2 ; j >= 0 ; j-- )
    {
      pnts[cnt] = pnts[j].reflect_xz();
      cnt++;
    }
}
Exemplo n.º 16
0
void SurfCore::WriteSurf( FILE* fp ) const
{
    vector< vector< vec3d > > pntVec;
    int numU, numW;

    int ip, jp, nupatch, nwpatch, ioffset, joffset;
    int icp, jcp, udeg = 0, wdeg = 0;

    nupatch = m_Surface.number_u_patches();
    nwpatch = m_Surface.number_v_patches();

    fprintf( fp, "%d        // Num U Patches, patch order:\n", nupatch );
    numU = 1;
    for ( ip = 0; ip < nupatch; ip++ )
    {
        const surface_patch_type *patch = m_Surface.get_patch( ip, 0 );
        udeg = patch->degree_u();

        numU += udeg;

        fprintf( fp, "%d ", udeg );
        if ( ip == nupatch - 1 )
            fprintf(fp, "\n" );
        else
            fprintf(fp, ", " );
    }

    fprintf( fp, "%d        // Num W Patches, patch order:\n", nwpatch );
    numW = 1;
    for ( jp = 0; jp < nwpatch; jp++ )
    {
        const surface_patch_type *patch = m_Surface.get_patch( 0, jp );
        wdeg = patch->degree_v();

        numW += wdeg;

        fprintf( fp, "%d ", wdeg );
        if ( jp == nwpatch - 1 )
            fprintf(fp, "\n" );
        else
            fprintf(fp, ", " );
    }

    pntVec.resize( numU );
    for ( icp = 0; icp < numU; icp++ )
    {
        pntVec[icp].resize( numW );
    }

    ioffset = 0;
    for( ip = 0; ip < nupatch; ++ip )
    {
        joffset = 0;
        for( jp = 0; jp < nwpatch; ++jp )
        {
            const surface_patch_type *patch = m_Surface.get_patch( ip, jp );
            udeg = patch->degree_u();
            wdeg = patch->degree_v();

            for( icp = 0; icp <= udeg; ++icp )
            {
                for( jcp = 0; jcp <= wdeg; ++jcp )
                {
                    surface_point_type cp;
                    cp = patch->get_control_point( icp, jcp );
                    pntVec[ ioffset + icp ][ joffset + jcp ]  = vec3d( cp.x(), cp.y(), cp.z() );
                }
            }
            joffset += wdeg;
        }
        ioffset += udeg;
    }

    fprintf( fp, "%d        // Num Pnts U \n",    numU );
    fprintf( fp, "%d        // Num Pnts W \n",    numW );
    fprintf( fp, "%d        // Total Pnts (0,0),(0,1),(0,2)..(0,numW-1),(1,0)..(1,numW-1)..(numU-1,0)..(numU-1,numW-1)\n",    numU * numW );

    for ( int i = 0 ; i < numU ; i++ )
    {
        for ( int j = 0 ; j < numW ; j++ )
        {
            fprintf( fp, "%20.20lf, %20.20lf, %20.20lf \n",
                     pntVec[i][j].x(), pntVec[i][j].y(), pntVec[i][j].z() );
        }
    }
}
Exemplo n.º 17
0
int main(int argc, char *argv[])
{
    int i;
    float r = 0;
    Space *space;
    Entity *cube1,*cube2;
    char bGameLoopRunning = 1;
    Vec3D cameraPosition = {-10,3,0};
    Vec3D cameraRotation = {180,0,180};
    SDL_Event e;
    Obj *bgobj;
    Sprite *bgtext;

	//my variables
	Ship *playerShip;
	int specMode;
    
    init_logger("gametest3d.log");
    if (graphics3d_init(1024,768,1,"gametest3d",33) != 0)
    {
        return -1;
    }
    model_init();
    obj_init();
    entity_init(255);
	initShips();
    
    bgobj = obj_load("models/mountainvillage.obj");
    bgtext = LoadSprite("models/mountain_text.png",1024,1024);
    
    //cube1 = newCube(vec3d(0,0,0),"Cubert");
    //cube2 = newCube(vec3d(10,0,0),"Hobbes");
    
    //cube1->body.velocity.x = 0.1;
    
    space = space_new();
    space_set_steps(space,100);
    
    space_add_body(space,&cube1->body);
    space_add_body(space,&cube2->body);

	//my variables
	specMode = 0;
	numShips = 0;
	shipVel = 0;
	shipRot = 0;
	turretRot = 0;
	gunElev = 0;
	realTurrRot = 0;

	playerShip = spawnShip(space, vec3d(-10,0,0), 1);

    while (bGameLoopRunning)
    {
		updateAllShipPos();
		for (i = 0; i < 100;i++)
        {
			space_do_step(space);
        }
		updateAllShipComp();
		applyGrav();
		if(specMode == 0)
		{
			cameraPosition.x = playerShip->hull->body.position.x;
			cameraPosition.y = (playerShip->hull->body.position.y + 5);
			cameraPosition.z = playerShip->hull->body.position.z;
		}

        while ( SDL_PollEvent(&e) ) 
        {
            if (e.type == SDL_QUIT)
            {
                bGameLoopRunning = 0;
            }
            else if (e.type == SDL_KEYDOWN)
            {
                if (e.key.keysym.sym == SDLK_ESCAPE)
                {
                    bGameLoopRunning = 0;
                }
                else if (e.key.keysym.sym == SDLK_SPACE)
                {
                    cameraPosition.z++;
                }
                else if (e.key.keysym.sym == SDLK_z)
                {
                    cameraPosition.z--;
                }
                else if (e.key.keysym.sym == SDLK_w)
                {
                    vec3d_add(
                        cameraPosition,
                        cameraPosition,
                        vec3d(
                            -sin(cameraRotation.z * DEGTORAD),
                            cos(cameraRotation.z * DEGTORAD),
                            0
                        ));
                }
                else if (e.key.keysym.sym == SDLK_s)
                {
                    vec3d_add(
                        cameraPosition,
                        cameraPosition,
                        vec3d(
                            sin(cameraRotation.z * DEGTORAD),
                            -cos(cameraRotation.z * DEGTORAD),
                            0
                        ));
                }
                else if (e.key.keysym.sym == SDLK_d)
                {
                    vec3d_add(
                        cameraPosition,
                        cameraPosition,
                        vec3d(
                            cos(cameraRotation.z * DEGTORAD),
                            sin(cameraRotation.z * DEGTORAD),
                            0
                        ));
                }
                else if (e.key.keysym.sym == SDLK_a)
                {
                    vec3d_add(
                        cameraPosition,
                        cameraPosition,
                        vec3d(
                            -cos(cameraRotation.z * DEGTORAD),
                            -sin(cameraRotation.z * DEGTORAD),
                            0
                        ));
                }
                else if (e.key.keysym.sym == SDLK_LEFT)
                {
                    cameraRotation.y -= 1;
                }
                else if (e.key.keysym.sym == SDLK_RIGHT)
                {
                    cameraRotation.y += 1;
                }
                else if (e.key.keysym.sym == SDLK_UP)
                {
                    cameraRotation.x += 1;
                }
                else if (e.key.keysym.sym == SDLK_DOWN)
                {
                    cameraRotation.x -= 1;
                }
				

				
				else if (e.key.keysym.sym == SDLK_y && shipVel < 0.4)
                {
                    shipVel += 0.1;
                }
				else if (e.key.keysym.sym == SDLK_h && shipVel > 0.05)
                {
                    shipVel -= 0.1;
                }
				else if (e.key.keysym.sym == SDLK_j)
                {
                    shipRot += 0.5;
					if(shipRot >= 360){shipRot -= 360;}
                }
				else if (e.key.keysym.sym == SDLK_g)
                {
                    shipRot -= 0.5;
					if(shipRot < 0){shipRot += 360;}
                }
				else if (e.key.keysym.sym == SDLK_m && turretRot < 135)
                {
                    turretRot += 1;
                }
				else if (e.key.keysym.sym == SDLK_b && turretRot > -135)
                {
                    turretRot -= 1;
                }
				else if (e.key.keysym.sym == SDLK_o && gunElev < 50)
                {
                    gunElev += 0.5;
                }
				else if (e.key.keysym.sym == SDLK_l && gunElev > -5)
                {
                    gunElev -= 0.5;
                }
				else if (e.key.keysym.sym == SDLK_q)
                {
					if(specMode == 0){specMode = 1;}
					else {specMode = 0;}
                }
				else if (e.key.keysym.sym == SDLK_p)
                {
					fireBullet(space, playerShip->gun->body.position, realTurrRot, gunElev, 0.5, -1);
				}
				else if (e.key.keysym.sym == SDLK_x)
                {
					fireBullet(space, playerShip->hull->body.position, shipRot, 0, 0, -2);
				}
				else if (e.key.keysym.sym == SDLK_1)
                {
					startLevel(space, 1);
				}
				else if (e.key.keysym.sym == SDLK_2)
                {
					startLevel(space, 2);
				}
				else if (e.key.keysym.sym == SDLK_3)
                {
					startLevel(space, 3);
				}
            }
        }
		 
        graphics3d_frame_begin();
        
        glPushMatrix();
        set_camera(
            cameraPosition,
            cameraRotation);
        
        entity_draw_all();
		//updateAllShipModels();
        obj_draw(
            bgobj,
            vec3d(0,0,2),
            vec3d(90,90,0),
            vec3d(5,5,5),
            vec4d(1,1,1,1),
            bgtext
        );
        
        if (r > 360)r -= 360;
        glPopMatrix();
        /* drawing code above here! */
        graphics3d_next_frame();
    } 
    return 0;
}
Exemplo n.º 18
0
vec3d CylindricalDeformation::localToDeformed(const vec3d &localPt) const
{
    float alpha = (float) localPt.y / R;
    float r = R - (float) localPt.z;
    return vec3d(localPt.x, r * sin(alpha), -r * cos(alpha));
}
Exemplo n.º 19
0
int Bt2Ent_DrawEntity(BGBDT_VoxWorld *world, dtVal ent)
{
	vec3d org, corg, rdir;
	char *spr, *sprft, *sprlf, *sprbk;
	s64 fl;
	float xs, ys, d, ang, cang, ang1;
//	int xflip=0;
	int rang;
	
	corg=vec3d(
		world->camorg[0]+(world->reforg[0]),
		world->camorg[1]+(world->reforg[1]),
		world->camorg[2]+(world->reforg[2]));
	
	org=Bt2Ent_EntGetOrigin(ent);
	fl=Bt2Ent_EntGetFlags(ent);
	ang=Bt2Ent_EntGetAngle(ent);

	d=v3ddist(org, corg);
//	if(d>1024)
	if(d>128)
		return(0);
	if(d<=0)
		return(0);

	sprft=Bt2Ent_EntGetSprite(ent);
//	sprlf=Bt2Ent_EntGetSpriteLf(ent);
//	sprbk=Bt2Ent_EntGetSpriteBk(ent);

	spr=sprft;

#if 0
	spr=sprft;
	if(sprlf && sprbk)
	{
		rdir=v3dsub(org, corg);
		cang=atan2(v3dy(rdir), v3dx(rdir))*(180/M_PI);
		ang1=(ang-cang)+90;
		if(ang1<0)
			ang1+=360;
		if(ang1>=360)
			ang1-=360;
		
		if((ang1>=315) || (ang1<=45))
			{ spr=sprbk; xflip=0; }
		if((ang1>=45) && ang1<=135)
			{ spr=sprlf; xflip=0; }
		if((ang1>=135) && ang1<=225)
			{ spr=sprft; xflip=0; }
		if((ang1>=225) && ang1<=315)
			{ spr=sprlf; xflip=1; }
	}
#endif

	rdir=v3dsub(org, corg);
	cang=atan2(v3dy(rdir), v3dx(rdir))*(180/M_PI);
	ang1=(ang-cang)+90;
	if(ang1<0)
		ang1+=360;
	if(ang1>=360)
		ang1-=360;
	rang=ang1*(8.0/360);
//	rang&=7;

	Bt2Ent_EntGetSpriteSize(ent, &xs, &ys);
	
	if(!spr)
		return(0);
	
//	if(xs<=0)xs=32;
//	if(ys<=0)ys=32;

	if(xs==0)xs=32;
	if(ys==0)ys=32;

	if(fl&BGBDT_ENTFL_ZFLIP)
		ys=-ys;
//	if(xflip)
//		xs=-xs;

	Bt2Ent_DrawSprite(world, spr, org, xs/32, ys/32, rang);
	return(1);
}
Exemplo n.º 20
0
vec3d CylindricalDeformation::deformedToLocal(const vec3d &deformedPt) const
{
    float y = R * atan2((float) deformedPt.y, (float) -deformedPt.z);
    float z = R - sqrt((float) (deformedPt.y * deformedPt.y + deformedPt.z * deformedPt.z));
    return vec3d(deformedPt.x, y, z);
}
Exemplo n.º 21
0
BTEIFGL_API dtVal Bt2Ent_SpawnEntityBasicXyz(
	char *cname, double x, double y, double z)
{
	return(Bt2Ent_SpawnEntityBasic(cname, vec3d(x, y, z)));
}
Exemplo n.º 22
0
//==== Read Fuse Cross Section File ====//
void FuselageXSec::read_parms(xmlNodePtr node)
{
	int i;
	xstype = xmlFindInt( node, "Type", xstype );

	height =  xmlFindDouble( node, "Height", height() );
	width  =  xmlFindDouble( node, "Width",  width() );

	max_width_loc  = xmlFindDouble( node, "Max_Width_Location",  max_width_loc() );
	corner_rad     = xmlFindDouble( node, "Corner_Radius",  corner_rad() );
	top_tan_angle = xmlFindDouble( node, "Top_Tan_Angle", top_tan_angle());
	bot_tan_angle = xmlFindDouble( node, "Bot_Tan_Angle", bot_tan_angle());

	top_str  = xmlFindDouble( node, "Top_Tan_Strength",    top_str() );
	upp_str  = xmlFindDouble( node, "Upper_Tan_Strength",  upp_str() );
	low_str  = xmlFindDouble( node, "Lower_Tan_Strength",  low_str() );
	bot_str  = xmlFindDouble( node, "Bottom_Tan_Strength", bot_str() );

	if ( xstype == FXS_FROM_FILE )
	{
		xstype = FXS_GENERAL;				// If this fails fall back on something...

		fileName = Stringc( xmlFindString( node, "File_Name", "File_Xsec" ) );					// fileName is a Stringc

		xmlNodePtr yn = xmlGetNode( node, "File_Y_Pnts", 0 );
		xmlNodePtr zn = xmlGetNode( node, "File_Z_Pnts", 0 );

		if ( yn && zn )
		{
			int numy = xmlGetNumArray( yn, ',' );
			int numz = xmlGetNumArray( zn, ',' );
			if ( numy == numz )
			{
				int num_pnts = numy;
				double* arry = (double*)malloc( num_pnts*sizeof(double) );
				double* arrz = (double*)malloc( num_pnts*sizeof(double) );
				xmlExtractDoubleArray( yn, ',', arry, num_pnts );
				xmlExtractDoubleArray( zn, ',', arrz, num_pnts );

				xstype = FXS_FROM_FILE;	

				file_crv.init( num_pnts );
				for ( i = 0 ; i < num_pnts ; i++ )
				{
					file_crv.load_pnt( i, vec3d( 0.0, arry[i],  arrz[i] ));
				}
				free( arry );
				free( arrz );

				file_crv.comp_tans();

				vec3d top_tan = vec3d( 0.0, 1.0, 0.0 );
				double tan_mag = file_crv.get_tan(0).mag();

				file_crv.load_tan( 0, top_tan*tan_mag );

				int last_id =  file_crv.get_num_pnts() - 1;
				vec3d bot_tan = vec3d( 0.0, -1.0, 0.0 );
				tan_mag = file_crv.get_tan( last_id ).mag();
				file_crv.load_tan( last_id, bot_tan*tan_mag );
			}
		}
	}
	else if ( xstype == FXS_EDIT_CRV )
	{
		edit_crv.read( node );
	}
	set_type(xstype);  

}
Exemplo n.º 23
0
void WorldParticleLayer::initParticle(ParticleStorage::Particle *p)
{
    WorldParticle *w = getWorldParticle(p);
    w->worldPos = vec3d(UNINITIALIZED, UNINITIALIZED, UNINITIALIZED);
    w->worldVelocity = vec3f(UNINITIALIZED, UNINITIALIZED, UNINITIALIZED);
}
Exemplo n.º 24
0
//===== Generate  Xsec  =====//
void FuselageXSec::generate()
{
    double y, z;
	if ( xstype == FXS_FROM_FILE )
	{
	 pnts.init(num_pnts);
	 load_file_pnts();
	}
	else if ( xstype == FXS_EDIT_CRV )
	{
	 pnts.init(num_pnts);
	 load_edit_crv_pnts();
	}
	else if ( xstype == FXS_BOX )
	{
	  pnts.init(num_pnts);
	  load_box_pnts();
	}
	else
	{
		if ( xstype != FXS_GENERAL )
		{
			upp_str = low_str = bot_str =  top_str();
		}

		y = 0.0;
		z = height()/2.0;
		top_crv.load_pnt( 0, vec3d( 0.0, y, z ));

		y = (double)(top_str()*width());
		z = 0.0;
		top_crv.load_tan( 0, vec3d( 0.0, y, z ));

		y = (double)( width()/2.0 + corner_rad()*height()*(sin(DEG_2_RAD*top_tan_angle())-1.0) );
		z = (double)(max_width_loc()*height()/2.0 + corner_rad()*height()*cos(DEG_2_RAD*top_tan_angle()) ) ;
		top_crv.load_pnt( 1, vec3d( 0.0, y, z ));

		y = (double)( upp_str()*height()*cos(DEG_2_RAD*top_tan_angle()) );
		z = (double)( -upp_str()*height()*sin(DEG_2_RAD*top_tan_angle()) );
		top_crv.load_tan( 1, vec3d( 0.0, y, z ));

		y = (double)(width()/2.0 + corner_rad()*height()*(sin(DEG_2_RAD*bot_tan_angle())-1.0) );
		z = (double)(max_width_loc()*height()/2.0 - corner_rad()*height()*cos(DEG_2_RAD*bot_tan_angle()) );
		bot_crv.load_pnt( 0, vec3d( 0.0, y, z ));

		y = (double)( -low_str()*height()*cos(DEG_2_RAD*bot_tan_angle()) );
		z = (double)( -low_str()*height()*sin(DEG_2_RAD*bot_tan_angle()) );
		bot_crv.load_tan( 0, vec3d( 0.0, y, z ));

		y = 0.0;
		z = (double)( -height()/2.0 );
		bot_crv.load_pnt( 1, vec3d( 0.0, y, z ));

		y = (double)( -bot_str()*width() );
		z = 0.0;
		bot_crv.load_tan( 1, vec3d( 0.0, y, z ));

		pnts.init(num_pnts);
		if ( pntSpaceType == PNT_SPACE_FIXED || pntSpaceType == PNT_SPACE_PER_XSEC )
		{
			load_pnts();
		}
		else if ( pntSpaceType == PNT_SPACE_UNIFORM )
		{
			load_uniform_pnts();
		}
	}
}
Exemplo n.º 25
0
void PtCloudGeom::LoadDrawObjs(vector< DrawObj* > & draw_obj_vec)
{
    vec3d ptColor = vec3d( m_GuiDraw.GetWireColor().x() / 255.0,
        m_GuiDraw.GetWireColor().y() / 255.0,
        m_GuiDraw.GetWireColor().z() / 255.0 );

    m_PtsDrawObj.m_Type = DrawObj::VSP_POINTS;
    m_PtsDrawObj.m_PointColor = ptColor;
    m_PtsDrawObj.m_PointSize = 4.0;
    m_PtsDrawObj.m_Visible = !m_GuiDraw.GetNoShowFlag();
    m_PtsDrawObj.m_GeomID = m_ID;

    m_SelDrawObj.m_Type = DrawObj::VSP_POINTS;
    m_SelDrawObj.m_PointColor = vec3d( 0., 0., 1.0 );
    m_SelDrawObj.m_PointSize = 4.0;
    m_SelDrawObj.m_GeomID = m_ID + "_SELPTCLD";

    m_ShownIndx.clear();
    m_PtsDrawObj.m_PntVec.clear();
    m_SelDrawObj.m_PntVec.clear();

    if ( FitModelMgr.IsGUIShown() )
    {
        for ( int j = 0; j < ( int ) m_XformPts.size(); j++ )
        {
            if ( !m_Hidden[j] && !m_Selected[j] )
            {
                m_PtsDrawObj.m_PntVec.push_back( m_XformPts[j] );
                m_ShownIndx.push_back( j );
            }

            if ( m_Selected[j] )
            {
                m_SelDrawObj.m_PntVec.push_back( m_XformPts[j] );
            }
        }
        m_SelDrawObj.m_Visible = !m_GuiDraw.GetNoShowFlag();
        m_PickDrawObj.m_Visible = !m_GuiDraw.GetNoShowFlag();
    }
    else
    {
        for ( int j = 0; j < ( int ) m_XformPts.size(); j++ )
        {
            m_PtsDrawObj.m_PntVec.push_back( m_XformPts[j] );
            m_ShownIndx.push_back( j );
        }
        m_SelDrawObj.m_Visible = false;
        m_PickDrawObj.m_Visible = false;
    }


    draw_obj_vec.push_back( &m_PtsDrawObj );
    draw_obj_vec.push_back( &m_SelDrawObj );
    draw_obj_vec.push_back( &m_PickDrawObj );

    if ( m_Vehicle->IsGeomActive( m_ID ) )
    {
        m_HighlightDrawObj.m_Screen = DrawObj::VSP_MAIN_SCREEN;
        m_HighlightDrawObj.m_GeomID = BBOXHEADER + m_ID;
        m_HighlightDrawObj.m_LineWidth = 2.0;
        m_HighlightDrawObj.m_LineColor = vec3d( 1.0, 0., 0.0 );
        m_HighlightDrawObj.m_Type = DrawObj::VSP_LINES;
        draw_obj_vec.push_back( &m_HighlightDrawObj );
    }
}
Exemplo n.º 26
0
//===== Load Points for Box ====//
void FuselageXSec::load_box_pnts( )
{
	vector< vec3d > pnt_vec;

	double y = height()/2.0;
	double x = width()/2.0;
	double f = 0.25;
	double g = 0.75;

	pnt_vec.push_back( vec3d( 0, y, 0 ) );
	pnt_vec.push_back( vec3d( f*x, y, 0 ) );
	pnt_vec.push_back( vec3d( g*x, y, 0 ) );

	pnt_vec.push_back( vec3d( x, y, 0 ) );
	pnt_vec.push_back( vec3d( x, g*y, 0 ) );
	pnt_vec.push_back( vec3d( x, f*y, 0 ) );

	pnt_vec.push_back( vec3d( x, 0, 0 ) );
	pnt_vec.push_back( vec3d( x, -f*y, 0 ) );
	pnt_vec.push_back( vec3d( x, -g*y, 0 ) );

	pnt_vec.push_back( vec3d( x, -y, 0 ) );
	pnt_vec.push_back( vec3d( g*x, -y, 0 ) );
	pnt_vec.push_back( vec3d( f*x, -y, 0 ) );

	pnt_vec.push_back( vec3d( 0, -y, 0 ) );
	pnt_vec.push_back( vec3d( -f*x, -y, 0 ) );
	pnt_vec.push_back( vec3d( -g*x, -y, 0 ) );

	pnt_vec.push_back( vec3d( -x, -y, 0 ) );
	pnt_vec.push_back( vec3d( -x, -g*y, 0 ) );
	pnt_vec.push_back( vec3d( -x, -f*y, 0 ) );

	pnt_vec.push_back( vec3d( -x,  0, 0 ) );
	pnt_vec.push_back( vec3d( -x, f*y, 0 ) );
	pnt_vec.push_back( vec3d( -x, g*y, 0 ) );

	pnt_vec.push_back( vec3d( -x, y, 0 ) );
	pnt_vec.push_back( vec3d( -g*x, y, 0 ) );
	pnt_vec.push_back( vec3d( -f*x, y, 0 ) );

	pnt_vec.push_back( vec3d( 0, y, 0 ) );

	Bezier_curve crv;
	
	crv.init_num_sections( 8 );
	for ( int i = 0 ; i < (int)pnt_vec.size() ; i++ )
		crv.put_pnt( i, pnt_vec[i] );

	vec3d p;
	for ( int i = 0 ; i < num_pnts ; i++ )
	{
		float u = (float)i/(float)(num_pnts-1);
		p = crv.comp_pnt(u);
        pnts[i] = vec3d( 0.0, p.x(), p.y() );
	}

}
Exemplo n.º 27
0
TMesh* SSLineSeg::CreateTMesh()
{
    int num_cut_lines = 0;
    int num_z_lines = 0;

    TMesh* tmesh = new TMesh();

    vec3d dc = m_line / ( num_cut_lines + 1.0 );
    vec3d dz = vec3d( 0, 0, 2.0 ) / ( num_z_lines + 1 );
    vec3d start = m_P0 + vec3d( 0, 0, -1 );

    int c, cz;

    vector< vector< vec3d > > pnt_mesh;
    pnt_mesh.resize( num_cut_lines + 2 );
    for ( int i = 0; i < ( int )pnt_mesh.size(); i++ )
    {
        pnt_mesh[i].resize( num_z_lines + 2 );
    }

    // Build plane
    for ( c = 0 ; c < num_cut_lines + 2 ; c++ )
    {
        for ( cz = 0 ; cz < num_z_lines + 2 ; cz++ )
        {
            pnt_mesh[c][cz] = start + dc * c + dz * cz;
        }
    }

    // Build triangles on that plane

    for ( c = 0 ; c < ( int )pnt_mesh.size() - 1 ; c++ )
    {
        for ( cz = 0 ; cz < ( int )pnt_mesh[c].size() - 1 ; cz ++ )
        {
            vec3d v0, v1, v2, v3, d01, d21, d20, d03, d23, norm;

            v0 = pnt_mesh[c][cz];
            v1 = pnt_mesh[c + 1][cz];
            v2 = pnt_mesh[c + 1][cz + 1];
            v3 = pnt_mesh[c][cz + 1];

            d21 = v2 - v1;
            d01 = v0 - v1;
            d20 = v2 - v0;

            if ( d21.mag() > 0.000001 && d01.mag() > 0.000001 && d20.mag() > 0.000001 )
            {
                norm = cross( d21, d01 );
                norm.normalize();
                tmesh->AddUWTri( v0, v1, v2, norm );
            }

            d03 = v0 - v3;
            d23 = v2 - v3;
            if ( d03.mag() > 0.000001 && d23.mag() > 0.000001 && d20.mag() > 0.000001 )
            {
                norm = cross( d03, d23 );
                norm.normalize();
                tmesh->AddUWTri( v0, v2, v3, norm );
            }
        }
    }
    return tmesh;
}
Exemplo n.º 28
0
//===== Read AF File =====//
int FuselageXSec::read_xsec_file( Stringc file_name )
{
  int i;
  Stringc line;
  char buff[255];

  //==== Open file ====//
  FILE* file_id = fopen(file_name, "r");
  if (file_id == (FILE *)NULL) return(0);

  fgets(buff, 80, file_id);  line = buff;
  if (line.search_for_substring("FUSE XSEC FILE") < 0)
    return 0;

  char name[255];
  int num_pnts;
  float y, z;

  fscanf(file_id, "%s", name);       fgets(buff, 80, file_id);
  fileName = name;
  fscanf(file_id, "%d", &num_pnts);  fgets(buff, 80, file_id);

  file_crv.init( num_pnts );
  for ( i = 0 ; i < num_pnts ; i++ )
  {
    fscanf(file_id, "%f  %f", &y, &z);  fgets(buff, 80, file_id);
    file_crv.load_pnt( i, vec3d( 0.0, y,  z ));
  }

  //==== Find Height & Width ====//
  vec3d p0 = file_crv.get_pnt( 0 );
  vec3d pn = file_crv.get_pnt( num_pnts-1 );
  height = fabs(p0.z() - pn.z());

  double max_y = 0;
  for ( i = 0 ; i < num_pnts ; i++ )
  {
    double y = file_crv.get_pnt( i ).y();
    if  ( fabs(y) > max_y )
      max_y = fabs(y);
  }
  width = (2.0*max_y);

  //==== Scale Point By Height & Width ====//
  for ( i = 0 ; i < num_pnts ; i++ )
  {
    double y = 2.0*file_crv.get_pnt( i ).y()/width();
    double z = 2.0*file_crv.get_pnt( i ).z()/height();
    file_crv.load_pnt( i, vec3d( 0.0, y,  z ));
  }

  file_crv.comp_tans();
  vec3d top_tan = vec3d( 0.0, 1.0, 0.0 );
  double tan_mag = (file_crv).get_tan(0).mag();

  file_crv.load_tan( 0, top_tan*tan_mag );
  int last_id =  file_crv.get_num_pnts() - 1;
  vec3d bot_tan = vec3d( 0.0, -1.0, 0.0 );
  tan_mag = file_crv.get_tan( last_id ).mag();
  file_crv.load_tan( last_id, bot_tan*tan_mag );

  fclose(file_id);

  return 1;
}
Exemplo n.º 29
0
void createLevel(int sc){

	int i, j, c;
	//int iSect[5][5];
	int randomNum;
	Entity *testEn;
	char enText[] = "models/red_piece.png";
	char shipText[] = "models/yell_piece.png";
	char powText[] = "models/green_piece.png";
	char blText[] = "models/orange_piece.png";
	char enObj[] = "models/cube.obj";
	
	//memcpy(iSect, *lvlSect, sizeof(lvlSect));
	testEn = newScorer(vec3d(100, cameraPosition.y + 60, 100),sc);
	for (i = 0; i < 5; i++){ //Y-Axis
		for (j = 0; j < 5; j++){ //X-Axis
			c = lvlSect[i][j];
			switch (c){
				case 0:
					//nothing
					//testEn = newship(vec3d((worldWidth / 2) * ((float)j - 2), cameraPosition.y + 60, (worldHeight / 2) * ((float)i - 2)), "ship", obj_load("models/cube.obj"), LoadSprite(shipText, 1024, 1024));
					break;
				case 1:
					//ships
					testEn = newship(vec3d(worldWidth/2 * (j - 2), cameraPosition.y + 60, worldHeight/2 * (i - 2)), "ship", obj_load(enObj), LoadSprite(shipText, 1024, 1024));
					break;
				case 2:
					//powerups
					switch (rand() % 3){
						case 1:
							testEn = newPower(vec3d(worldWidth / 2 * (j - 2), cameraPosition.y + 60, worldHeight / 2 * (i - 2)), "power", obj_load(enObj), LoadSprite(powText, 1024, 1024), P_MINI);
							break;
						case 2:
							testEn = newPower(vec3d(worldWidth / 2 * (j - 2), cameraPosition.y + 60, worldHeight / 2 * (i - 2)), "power", obj_load(enObj), LoadSprite(powText, 1024, 1024), P_BOMB);
							break;
						default:
							testEn = newPower(vec3d(worldWidth / 2 * (j - 2), cameraPosition.y + 60, worldHeight / 2 * (i - 2)), "power", obj_load(enObj), LoadSprite(powText, 1024, 1024), P_INVERT);
							break;
					}
					break;
				case 3:
					//walls
					switch (rand() % 4){
						case 0:
							testEn = newWall(vec3d(worldWidth / 2 * (j - 2), cameraPosition.y + 60, worldHeight / 2 * (i - 2)), "wall", obj_load(enObj), LoadSprite(enText, 1024, 1024), W_STRAIGHT, 0);
							break;
						case 1:
							testEn = newWall(vec3d(worldWidth / 2 * (j - 2), cameraPosition.y + 60, worldHeight / 2 * (i - 2)), "wall", obj_load(enObj), LoadSprite(enText, 1024, 1024), W_HORZ, rand() % 2);
							break;
						case 2:
							testEn = newWall(vec3d(worldWidth / 2 * (j - 2), cameraPosition.y + 60, worldHeight / 2 * (i - 2)), "wall", obj_load(enObj), LoadSprite(enText, 1024, 1024), W_ZIG, rand() % 4);
							break;
						default:
							testEn = newWall(vec3d(worldWidth / 2 * (j - 2), cameraPosition.y + 60, worldHeight / 2 * (i - 2)), "wall", obj_load(enObj), LoadSprite(enText, 1024, 1024), W_VERT, rand() % 2);
							break;
					}
					break;
			}
		}
	}

}
Exemplo n.º 30
0
void Af::read(xmlNodePtr node)
{
  int i;

  int temp_type = xmlFindInt( node, "Type", 0 );
  inverted_flag = xmlFindInt( node, "Inverted_Flag", inverted_flag );

  camber        = xmlFindDouble( node, "Camber", camber() );
  camber_loc    = xmlFindDouble( node, "Camber_Loc", camber_loc() );
  thickness     = xmlFindDouble( node, "Thickness", thickness() );
  thickness_loc = xmlFindDouble( node, "Thickness_Loc", thickness_loc() );

  radius_le    = xmlFindDouble( node, "Radius_Le", radius_le() );
  radius_te    = xmlFindDouble( node, "Radius_Te", radius_te() );

  sixser = xmlFindInt( node, "Six_Series", sixser );
  ideal_cl = xmlFindDouble( node, "Ideal_Cl", ideal_cl() );
  a = xmlFindDouble( node, "A", a() );

  slat_flag = xmlFindInt( node, "Slat_Flag", slat_flag );
  slat_shear_flag = xmlFindInt( node, "Slat_Shear_Flag", slat_shear_flag );
  slat_chord = xmlFindDouble( node, "Slat_Chord", slat_chord() );
  slat_angle = xmlFindDouble( node, "Slat_Angle", slat_angle() );

  flap_flag = xmlFindInt( node, "Flap_Flag", flap_flag );
  flap_shear_flag = xmlFindInt( node, "Flap_Shear_Flag", flap_shear_flag );
  flap_chord = xmlFindDouble( node, "Flap_Chord", flap_chord() );
  flap_angle = xmlFindDouble( node, "Flap_Angle", flap_angle() );

  if ( temp_type == AIRFOIL_FILE )
  {
    vec3d pnt;
    name = xmlFindString( node, "Name", name );
    orig_af_thickness = (float)xmlFindDouble( node, "Original_AF_Thickness", orig_af_thickness );
    radius_le_correction_factor = (float)xmlFindDouble( node, "Radius_LE_Correction_Factor", radius_le_correction_factor );
    radius_te_correction_factor = (float)xmlFindDouble( node, "Radius_TE_Correction_Factor", radius_te_correction_factor );

    xmlNodePtr upp_node = xmlGetNode( node, "Upper_Pnts", 0 );

    if ( upp_node )
    {
      int num_arr =  xmlGetNumArray( upp_node, ',' );
      double* arr = (double*)malloc( num_arr*sizeof(double) );
      xmlExtractDoubleArray( upp_node, ',', arr, num_arr );

      int num_upper = num_arr/2;

      upper_curve.init(num_upper);
      for ( i = 0 ; i < num_arr ; i+=2)
      {
        pnt = vec3d(arr[i], 0.0, arr[i+1]);
        upper_curve.load_pnt( i/2, pnt );
      }
      free(arr);
    }
    xmlNodePtr low_node = xmlGetNode( node, "Lower_Pnts", 0 );

    if ( low_node )
    {
      int num_arr =  xmlGetNumArray( low_node, ',' );
      double* arr = (double*)malloc( num_arr*sizeof(double) );
      xmlExtractDoubleArray( low_node, ',', arr, num_arr );

      int num_lower = num_arr/2;

      lower_curve.init(num_lower);
      for ( i = 0 ; i < num_arr ; i+=2)
      {
        pnt = vec3d(arr[i], 0.0, arr[i+1]);
        lower_curve.load_pnt( i/2, pnt );
      }
      free(arr);
    }
  }

  set_type(temp_type);
}