Пример #1
0
/*
 * Draws a Entity with optional offset from parent.
 * If an Animation is active, the frames transformation is added as well.
 * TODO: Shooting brings lags
 */
void Player::draw(Transformation transformation){
    glPushMatrix();

    for(auto& anim : m_PlayingAnimations){
        Transformation *animTransformation = anim.second->tick();
        if(animTransformation == NULL){
            map<string,Animation*>::iterator it = m_PlayingAnimations.find(anim.first);
            m_PlayingAnimations.erase(it);
            continue;
        }
        m_Transformation += *animTransformation;
        //cout << "Adding to scalex " << animTransformation->m_Scale.x << endl;
        //m_Transformation.m_Scale += animTransformation->m_Scale;
    }


    transformation += m_Transformation;
    transformation.m_Scale = m_Transformation.m_Scale;

    Vec3D parentScale = Vec3D(1,1,1);
    if(m_Parent != NULL){
        parentScale = m_Parent->getTransformation()->m_Scale;
    }


    glTranslatef(transformation.m_Translation.x, transformation.m_Translation.y , transformation.m_Translation.z );
    glRotatef(transformation.m_Angle, transformation.m_Rotation.x, transformation.m_Rotation.y , transformation.m_Rotation.z);
    glScalef(transformation.m_Scale.x,transformation.m_Scale.y,transformation.m_Scale.z);

    glColor3f(0.2,0.9,0.2);
//        drawBody();
    glutSolidSphere(1,30,30);

    // Cockpit
    //glPushMatrix();
    glTranslatef(0,0,10 / transformation.m_Scale.z);
    //glScalef(transformation.m_Scale.x / 20,transformation.m_Scale.y / 20, transformation.m_Scale.z / 20);
    glScalef(15 / transformation.m_Scale.x, 20 / transformation.m_Scale.y , 10 / transformation.m_Scale.z);
    glColor3f(0.2,0.2,0.9);
    glutSolidSphere(1,30,30);
    // glPopMatrix();

    glPopMatrix();

    for(auto& part : m_Parts){
        part->draw(transformation);
    }
    //glPopMatrix();
}
Пример #2
0
Frame::Frame()
    : _offx(0), _offy(0), _width(640), _height(480), 
      _fontsize(12.0), _titlespace(10.0), _cmlspace(10.0), _bg(Vec3D(1,1,1)), _fg(Vec3D(0,0,0)),
      _legend_enable(true), _legend_pos(LEGEND_POS_TOP_RIGHT), _cm_legend(NULL),
      _cml_enable(true), _fixedaspect(PLOT_FIXED_ASPECT_DISABLED), _automargin(true)
{
    _legend.set_font_size( _fontsize );

    // Ruler X1
    _ruler[0].set_coord_index( 0 );
    _ruler[0].set_indir( true );
    _fenable[0] = false;
    _autorange[0] = true;
    _autorange[1] = true;

    // Ruler Y1
    _ruler[1].set_coord_index( 1 );
    _ruler[1].set_indir( false );
    _fenable[1] = false;
    _autorange[2] = true;
    _autorange[3] = true;

    // Ruler X2
    _ruler[2].set_coord_index( 0 );
    _ruler[2].set_indir( false );
    _fenable[2] = false;
    _autorange[4] = true;
    _autorange[5] = true;

    // Ruler Y2
    _ruler[3].set_coord_index( 1 );
    _ruler[3].set_indir( true );
    _fenable[3] = false;
    _autorange[6] = true;
    _autorange[7] = true;
}
Пример #3
0
 TeteNode::TeteNode(Device* d, QGraphicsItem* parent, QGraphicsScene* scene) :
   RespondNode(d, parent, scene) {
   tete_ = NULL;
   x_vel_ = 0.0;
   y_vel_ = 0.0;
   frame_rect_ = QRectF(-1, -1, 2, 2);
   frame_rect_object_ = NULL;
   mouse_moved_ = true;
   velocity_ = Vec3D();
   dormant_ = false;
   frame_on_needed_ = false;
   frame_on_threshold_ = 1.001;
   setFlag(QGraphicsItem::ItemIsMovable);
   //setAcceptDrops(true); // Needed for drag and drop events (like dragEnterEvent)
 }
Пример #4
0
bool toxi::geom::AABB::planeBoxOverlap( Vec3D & normal, const float & d, const Vec3D & maxBox )
{
	Vec3D vmin = Vec3D();
	Vec3D vmax = Vec3D();

	if (normal.getX() > 0.0f) {
		vmin.setX( -maxBox.getX() );
		vmax.setX( maxBox.getX() );
	} else {
		vmin.setX( maxBox.getX() );
		vmax.setX( -maxBox.getX() );
	}

	if (normal.getY() > 0.0f) {
		vmin.setY( -maxBox.getY() );
		vmax.setY( maxBox.getY() );
	} else {
		vmin.setY( maxBox.getY() );
		vmax.setY( -maxBox.getY() );
	}

	if (normal.getZ() > 0.0f) {
		vmin.setZ( -maxBox.getZ() );
		vmax.setZ( maxBox.getZ() );
	} else {
		vmin.setZ( maxBox.getZ() );
		vmax.setZ( -maxBox.getZ() );
	}
	if (normal.dot(vmin) + d > 0.0f) {
		return false;
	}
	if (normal.dot(vmax) + d >= 0.0f) {
		return true;
	}
	return false;
}
Пример #5
0
void TSpawnZone::debugDraw( bool beDebug )
{
    if ( beDebug )
    {
        FnMaterial mat = UF_CreateMaterial();
        mat.SetEmissive( Vec3D(1,1,1) );
        m_dbgObj.Object( getLiveLevel()->getFlyScene().CreateObject() );
        UF_CreateBoxLine( &m_dbgObj , 5 , 5 , 10 , mat.Object());
        m_dbgObj.SetWorldPosition( pos );
    }
    else
    {
        UF_DestoryObject( m_dbgObj );
    }
}
Пример #6
0
  void setupInitialConditions()
  {	
    BaseParticle p0;
    p0.setRadius(0.005);
    p0.setPosition(Vec3D(0.5*getXMax(),0.5*getYMax(),0.0));
    p0.setVelocity(Vec3D(1.2,1.3,0.0));
    particleHandler.copyAndAddObject(p0);

//! [T7:infiniteWalls]
    InfiniteWall w0;

    w0.set(Vec3D(1.0,0.0,0.0),Vec3D(getXMax(),0.0,0.0));
    wallHandler.copyAndAddObject(w0);

    w0.set(Vec3D(-1.0,0.0,0.0),Vec3D(getXMin(),0.0,0.0));
    wallHandler.copyAndAddObject(w0);

    w0.set(Vec3D(0.0,1.0,0.0),Vec3D(0.0,getYMax(),0.0));
    wallHandler.copyAndAddObject(w0);

    w0.set(Vec3D(0.0,-1.0,0.0),Vec3D(0.0,getYMin(),0.0));
    wallHandler.copyAndAddObject(w0);
//! [T7:infiniteWalls]
  }
Пример #7
0
Sky::Sky(MPQFile &f)
{
	lightinfo li;
	f.read(&li, 64);

	pos = Vec3D(li.fa/skymul, li.fb/skymul, li.fc/skymul);
	r1 = li.fd / skymul;
	r2 = li.fe / skymul;

	strcpy(name,li.name);

	for (int i=0; i<36; i++) mmin[i] = -2;

	global = (li.ia==-1);
}
Пример #8
0
void CUIDisplayWorld::MoveCamera(int x, int y)
{
	Matrix mCameraRot;
	// ----
	Vec3D vPos = CGameCamera::getInstance().getTargetPos();
	// ----
	// # 基于摄像机的 yaw 创建旋转矩阵 (Warning ! huihui need translate)
	// ----
	mCameraRot.rotationYawPitchRoll(CGameCamera::getInstance().getYawAngle(), 0, 0);
	// ----
	vPos	+= mCameraRot * Vec3D(x, 0, y) * 0.001f * CGameCamera::getInstance().getRadius();
	// ----
	vPos.y	= CWorld::getInstance().getHeight(vPos.x, vPos.z);
	// ----
	CGameCamera::getInstance().setTargetPos(vPos);
}
Пример #9
0
toxi::geom::Vec3D toxi::geom::AABB::getNormalForPoint( Vec3D & p )
{
	p = p.sub( Vec3D( x, y, z ) );
	Vec3D pabs = extent.sub( p.getAbs() );
	Vec3D psign = p.getSignum();
	Vec3D normal = Vec3D::X_AXIS().scale( static_cast< float > ( psign.getX() ) );
	double minDist = pabs.getX();
	if (pabs.getY() < minDist) {
		minDist = pabs.getY();
		normal = Vec3D::Y_AXIS().scale( static_cast< float > ( psign.getY() ) );
	}
	if (pabs.getZ() < minDist) {
		normal = Vec3D::Z_AXIS().scale( static_cast< float > ( psign.getZ() ) );
	}
	return normal;
}
Пример #10
0
void PlayerBoxTrigger::debugDraw( bool beDebug )
{
    if ( beDebug )
    {
        FnMaterial mat = UF_CreateMaterial();
        mat.SetEmissive( Vec3D(1,1,1) );
        Vec3D min , max;
        getPhyBody()->getAabb( min , max  );
        Vec3D len = 0.5 * ( max - min );
        UF_CreateBoxLine( &m_dbgObj , len.x() , len.y() , len.z() , mat.Object());
    }
    else
    {
        m_dbgObj.RemoveAllGeometry();
    }

}
Пример #11
0
Vec3D Sky::colorFor(int r, int t) const
{
    if (mmin[r]<0)
    {
        return Vec3D(0, 0, 0);
    }
    Vec3D c1, c2;
    int t1, t2;
    size_t last = colorRows[r].size() - 1;

    if (t<mmin[r])
    {
        // reverse interpolate
        c1 = colorRows[r][last].color;
        c2 = colorRows[r][0].color;
        t1 = colorRows[r][last].time;
        t2 = colorRows[r][0].time + 2880;
        t += 2880;
    }
    else
    {
        for (size_t i = last; true; i--)
        {   //! \todo iterator this.
            if (colorRows[r][i].time <= t)
            {
                c1 = colorRows[r][i].color;
                t1 = colorRows[r][i].time;

                if (i == last)
                {
                    c2 = colorRows[r][0].color;
                    t2 = colorRows[r][0].time + 2880;
                }
                else
                {
                    c2 = colorRows[r][i + 1].color;
                    t2 = colorRows[r][i + 1].time;
                }
                break;
            }
        }
    }

    float tt = static_cast<float>(t - t1) / static_cast<float>(t2 - t1);
    return c1*(1.0f - tt) + c2*tt;
}
Пример #12
0
void CFrustum::Build(Vec3D vecMin,Vec3D vecMax)
{
	m_vtx[0] = Vec3D(vecMin.x, vecMin.y,  vecMin.z); // xyz
	m_vtx[1] = Vec3D(vecMax.x, vecMin.y,  vecMin.z); // Xyz
	m_vtx[2] = Vec3D(vecMin.x, vecMax.y,  vecMin.z); // xYz
	m_vtx[3] = Vec3D(vecMax.x, vecMax.y,  vecMin.z); // XYz
	m_vtx[4] = Vec3D(vecMin.x, vecMin.y,  vecMax.z); // xyZ
	m_vtx[5] = Vec3D(vecMax.x, vecMin.y,  vecMax.z); // XyZ
	m_vtx[6] = Vec3D(vecMin.x, vecMax.y,  vecMax.z); // xYZ
	m_vtx[7] = Vec3D(vecMax.x, vecMax.y,  vecMax.z); // XYZ

	m_planes.resize(6);
	m_planes[0]=Plane(m_vtx[0], m_vtx[1], m_vtx[2]); // Near
	m_planes[1]=Plane(m_vtx[6], m_vtx[7], m_vtx[5]); // Far
	m_planes[2]=Plane(m_vtx[2], m_vtx[6], m_vtx[4]); // Left
	m_planes[3]=Plane(m_vtx[7], m_vtx[3], m_vtx[5]); // Right
	m_planes[4]=Plane(m_vtx[2], m_vtx[3], m_vtx[6]); // Top
	m_planes[5]=Plane(m_vtx[1], m_vtx[0], m_vtx[4]); // Bottom
}
Пример #13
0
CDMask::CDMask( Vec2i const& size , CFScene* scene )
	:size( size )
	,needShow( true )
{

	spr = scene->createObject( nullptr );
	
	spr->setOpacity( 0.5f );
	//spr->createPlane( NULL , 100 , 100 , Vec3D(1,0,0) );
	spr->setLocalPosition( Vec3D(0,0,10) );
	spr->enableVisibleTest( false );
	spr->setRenderOption( CFly::CFRO_CULL_FACE , CFly::CF_CULL_NONE );

	int geom = createMask( spr , nullptr );

	CFly::MeshBase* shape = spr->getElement( geom )->getMesh();
	mGoemBuf = shape->getVertexElement( CFly::CFV_XYZ , mGoemOffset );
}
Пример #14
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// Method for finding boost to special r.f.
inline Vec3D Vec4D::SRFBoost() const
{
    VEC3D_T n=Norm2();
    if( n > 0.) {            // time-like vector
        // e.g. physical particle

        return r/r0;           // boost to r.f. where r=0
        // i.e. particle's rest frame

    } else if ( n < 0.) {    // space-like vector
        // e.g. tachyon

        return r0*r/(r*r);     // boost to r.f. where r0=0

    }
    // light-like
    return Vec3D();          // boost=0. is returned
}
Пример #15
0
TChestTrigger::TChestTrigger() :TBoxTrigger( Vec3D( 100 , 100 , 100 ) )
	,m_items( new TItemStorage(MaxItemNum) )
{
	m_DTime = 0.0f;

	OBJECTid objID = TResManager::instance().cloneModel( "bag" , true );

	modelObj.Object( objID );
	float scale = 20;
	modelObj.Scale( scale , scale , scale , LOCAL  );
	modelObj.Rotate( X_AXIS , 90 , LOCAL );
	modelObj.XForm();

	XForm trans;
	trans.setIdentity();
	TObjMotionState* motionState = new TObjMotionState( trans , objID );
	setMotionState( motionState );
}
Пример #16
0
void Skies::initSky(Vec3D pos, int t)
{
	if (numSkies==0) return;

	findSkyWeights(pos);

	for (int i=0; i<18; i++) colorSet[i] = Vec3D(0,0,0);

	// interpolation
	for (size_t j=0; j<skies.size(); j++) {
		if (skies[j].weight>0) {
			// now calculate the color rows
			for (int i=0; i<18; i++) {
				colorSet[i] += skies[j].colorFor(i,t) * skies[j].weight;
			}
		}
	}
}
Пример #17
0
  /* Part of the object has changed.  Broadcast a message to Grids that lets
       the server know of the change. */
  QVariant InputTextItem::itemChange(GraphicsItemChange change,
                                     const QVariant &value)
  {
    if (change == QGraphicsItem::ItemSelectedHasChanged)
      emit selectedChange(this);

    /* Check for text change. */

    /*d->getNoticeWindow()->write("change");*/

    /* Check for position change. */
    if(change == QGraphicsItem::ItemPositionChange) {
      //d->getNoticeWindow()->write("Pos change");
      updatePosition(d, Vec3D(value.toPointF().x(), value.toPointF().y(), zValue()));
    }
    return value;
    //return QGraphicsItem::itemChange(change, value);
  }
Пример #18
0
//! [T1:main]
int main(int argc, char *argv[])
{
  // Problem setup
  Tutorial1 problem;

//! [T1:problemSetup]
  problem.setName("Tutorial1");
  problem.setSystemDimensions(3);
  problem.setGravity(Vec3D(0.0,0.0,0.0));
  problem.setXMax(1.0);
  problem.setYMax(1.0);
  problem.setZMax(1.0);
  problem.setTimeMax(2.0);
//! [T1:problemSetup]

//! [T1:speciesProp]
  // The normal spring stiffness and normal dissipation is computed and set as 
  // For collision time tc=0.005 and restitution coefficeint rc=1.0,
  auto species = problem.speciesHandler.copyAndAddObject(LinearViscoelasticSpecies());
  species->setDensity(2500.0); // sets the species type-0 density
  species->setStiffness(258.5);// sets the spring stiffness
  species->setDissipation(0.0);// sets the dissipation
//! [T1:speciesProp]

//! [T1:output]
  problem.setSaveCount(10);
  problem.dataFile.setFileType(FileType::ONE_FILE);
  problem.restartFile.setFileType(FileType::ONE_FILE);
  problem.fStatFile.setFileType(FileType::NO_FILE);
  problem.eneFile.setFileType(FileType::NO_FILE);
  std::cout << problem.dataFile.getCounter() << std::endl;
//! [T1:output]

//! [T1:visualOutput] 	
  problem.setXBallsAdditionalArguments("-solidf -v0");
//! [T1:visualOutput]

//! [T1:solve]
  problem.setTimeStep(.005/50.0); // (collision time)/50.0
  problem.solve(argc, argv);
//! [T1:solve]
  return 0;
}
Пример #19
0
Vec3D Plane::getTexCoords(const Vec3D& pnt, const CIsect& isect/* = CIsect()*/) const
{
	// That's not really good to calculate coordinates according to set texture, but plane if infinite and so on..

	const float xu = dot(pnt, mUAxis) * mMtrl->TexScaleU;
	const float yv = dot(pnt, mVAxis) * mMtrl->TexScaleV; 

	//float u = (static_cast<int>(xu) % TILE_SIZE + (xu - floorf(xu))) * 1.f / TILE_SIZE; 
	//float v = (static_cast<int>(yv) % TILE_SIZE + (yv - floorf(yv))) * 1.f / TILE_SIZE;
	//// Repeat texture around negative axis
	//if (u < 0.f)
	//{
	//	u = 1.f + u;
	//}
	//if (v < 0.f)
	//{
	//	v = 1.f + v; 
	//}
	return Vec3D(xu, yv, 0.f);
}
Пример #20
0
toxi::geom::Vec3D toxi::geom::Triangle3D::toBarycentric( Vec3D & p )
{
    Vec3D e = b.sub( a ).cross( c.sub( a ) );
    Vec3D n = e.getNormalized();

    // Compute twice area of triangle ABC
    float areaABC = n.dot( e );
    // Compute lambda1
    float areaPBC = n.dot( b.sub( p ).cross( c.sub( p ) ) );
    float l1 = areaPBC / areaABC;

    // Compute lambda2
    float areaPCA = n.dot( c.sub( p ).cross( a.sub( p ) ) );
    float l2 = areaPCA / areaABC;

    // Compute lambda3
    float l3 = 1.0f - l1 - l2;

    return Vec3D(l1, l2, l3);
}
Пример #21
0
ParticleGraph::ParticleGraph( const Geometry &geom, const ParticleDataBase &pdb, 
			      uint32_t particle_div, uint32_t particle_offset,
			      bool qm_discr )
    : Graph3D(geom), _geom(geom), _pdb(pdb), 
      _particle_div(particle_div), _particle_offset(particle_offset),
      _coordsize(3), _qm_discr(qm_discr)
{
    // Allocate work space
    _coord = new double[2*_coordsize];

    // Add default colors
    _color.push_back( Vec3D( 1.0, 0.2, 0.2 ) ); // Red

    _color.push_back( Vec3D( 1.0, 1.0, 0.2 ) ); // Yellow
    _color.push_back( Vec3D( 1.0, 0.2, 1.0 ) ); // Magenta
    _color.push_back( Vec3D( 0.2, 1.0, 1.0 ) ); // Cyan

    _color.push_back( Vec3D( 1.0, 0.5, 0.2 ) ); // Orange
    _color.push_back( Vec3D( 0.5, 0.2, 1.0 ) ); // Purple
    _color.push_back( Vec3D( 0.2, 1.0, 0.5 ) ); // Bluish green
    _color.push_back( Vec3D( 1.0, 0.2, 0.5 ) ); // Pink
}
Пример #22
0
Vec3D Cylinder::getTexCoords(const Vec3D& pnt, const CIsect& isect /*= CIsect()*/) const
{
	// Get position of pnt on the surface of the cylinder
	const Vec3D CO = pnt - mBottom;

	float CODotAxis = dot(CO, mAxis);

	Vec3D atCircle = pnt - CODotAxis * mAxis - mBottom;
	float		 x			  = dot(atCircle, mVe);
	float		 z				= dot(atCircle, mVn);

	float u = atan2(x, z) / (2 * M_PI);

	// v coordinate is the projection of the pnt on axis, mapped to [0..1]
	const float height = length(mTop - mBottom);

	float v = CODotAxis / height;

	return Vec3D(u, v, 0.f);
}
Пример #23
0
//------------------------------------------------------------------------------
void NBodyWnd::Init(int num)
{
    /*
      m_galaxy.Reset(15000,    // radius of the galaxy
                     4000,     // radius of the core
                     0.000306, // angluar offset of the density wave per parsec of radius
                     0.8,      // excentricity at the edge of the core
                     0.85,     // excentricity at the edge of the disk
                     200,      // orbital velocity at the edge of the core
                     300,      // orbital velovity at the edge of the disk
                     40000);   // total number of stars
    */
    m_galaxy.Reset(13000,    // radius of the galaxy
                   4000,     // radius of the core
                   0.0004,   // angluar offset of the density wave per parsec of radius
                   0.9,      // excentricity at the edge of the core
                   0.9,      // excentricity at the edge of the disk
                   0.5,
                   200,      // orbital velocity at the edge of the core
                   300,      // orbital velovity at the edge of the disk
                   30000);   // total number of stars


    m_roi = m_galaxy.GetFarFieldRad() * 1.3;

    // OpenGL initialization
    glEnable (GL_LINE_SMOOTH);
    glEnable (GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
    glLineWidth (1);

    glClear(GL_COLOR_BUFFER_BIT  | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_POINT_SPRITE);
    glDisable(GL_DEPTH_TEST);
    glClearColor(0.0f, 0.0f, 0.03f, 0.0f);  // black background
    SetCameraOrientation(Vec3D(0, 1, 0));

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}
Пример #24
0
Vec3D Palette::operator()( double x ) const
{
    // If undefined
    if( _entries.size() == 0 )
	return( Vec3D( 0, 0, 0 ) );
    else if( _entries.size() == 1 )
	return( _entries[0]._color );

    // If out of limits
    if( x <= 0.0 )
	return( _entries[0]._color );
    else if( x >= 1.0 )
	return( _entries[_entries.size()-1]._color );

    // If stepped palette
    if( _steps > 1 ) {
	x *= _steps;
	x = floor( x );
	x = x / (_steps-1);
	if( x > 1.0 )
	    x = 1.0;
    }

    // Search correct index
    size_t a;
    for( a = 1; a < _entries.size(); a++ ) {
	if( x < _entries[a]._val )
	    break;
    }
    if( a == _entries.size() ) 
	a = _entries.size()-1;
    
    // Interpolate
    double t = (x-_entries[a-1]._val) / (_entries[a]._val-_entries[a-1]._val);
    Vec3D c = _entries[a-1]._color + 
	t*(_entries[a]._color-_entries[a-1]._color);

    return( c );
}
Пример #25
0
void Graphics::DrawBox3D( const Pos3D *corner, const Vec3D *fwd, const Vec3D *up, const Vec3D *right, float line_width, float r, float g, float b, float a )
{
	Vec3D rbl = Vec3D( corner->X, corner->Y, corner->Z );
	Vec3D fbl = rbl + *fwd;
	Vec3D rbr = rbl + *right;
	Vec3D fbr = fbl + *right;
	Vec3D rtl = rbl + *up;
	Vec3D ftl = fbl + *up;
	Vec3D rtr = rbr + *up;
	Vec3D ftr = fbr + *up;
	
	glColor4f( r, g, b, a );
	glLineWidth( line_width );
	
	glBegin( GL_LINE_LOOP );
		glVertex3d( rbl.X, rbl.Y, rbl.Z );
		glVertex3d( fbl.X, fbl.Y, fbl.Z );
		glVertex3d( fbr.X, fbr.Y, fbr.Z );
		glVertex3d( rbr.X, rbr.Y, rbr.Z );
	glEnd();
	
	glBegin( GL_LINE_LOOP );
		glVertex3d( rtl.X, rtl.Y, rtl.Z );
		glVertex3d( ftl.X, ftl.Y, ftl.Z );
		glVertex3d( ftr.X, ftr.Y, ftr.Z );
		glVertex3d( rtr.X, rtr.Y, rtr.Z );
	glEnd();
	
	glBegin( GL_LINES );
		glVertex3d( rtl.X, rtl.Y, rtl.Z );
		glVertex3d( rbl.X, rbl.Y, rbl.Z );
		glVertex3d( ftl.X, ftl.Y, ftl.Z );
		glVertex3d( fbl.X, fbl.Y, fbl.Z );
		glVertex3d( ftr.X, ftr.Y, ftr.Z );
		glVertex3d( fbr.X, fbr.Y, fbr.Z );
		glVertex3d( rtr.X, rtr.Y, rtr.Z );
		glVertex3d( rbr.X, rbr.Y, rbr.Z );
	glEnd();
}
Пример #26
0
void Skies::draw()
{
    // draw sky sphere?
    //! \todo  do this as a vertex array and use glColorPointer? :|
    Vec3D basepos1[cnum], basepos2[cnum];
    glBegin(GL_QUADS);
    for (int h = 0; h<hseg; h++) {
        for (int i = 0; i<cnum; ++i) {
            basepos1[i] = basepos2[i] = Vec3D(cosf(angles[i] * (float)PI / 180.0f)*rad, sinf(angles[i] * (float)PI / 180.0f)*rad, 0);
            rotate(0, 0, &basepos1[i].x, &basepos1[i].z, (float)PI*2.0f / hseg*h);
            rotate(0, 0, &basepos2[i].x, &basepos2[i].z, (float)PI*2.0f / hseg*(h + 1));
        }

        for (int v = 0; v<cnum - 1; v++) {
            glColor3fv(colorSet[skycolors[v]]);
            glVertex3fv(basepos2[v]);
            glVertex3fv(basepos1[v]);
            glColor3fv(colorSet[skycolors[v + 1]]);
            glVertex3fv(basepos1[v + 1]);
            glVertex3fv(basepos2[v + 1]);
        }
    }
    glEnd();
}
Пример #27
0
Event Simulator::simulate (const Launch launch)
{
    Vec3D position(0,0,0);
    Vec3D velocity = launch.speed * Vec3D(
            cos(launch.theta)*cos(launch.phi),
            cos(launch.theta)*sin(launch.phi),
            sin(launch.theta)
            );
    double t = 0;
    Vec3D prev_position(0, 0, 0);
    do
    {
        prev_position = position;
        Vec3D acceleration = this->calculate_friction(velocity) + this->calculate_nonfriction(position,velocity);
        position = position + this->dtime * velocity + .5 * (this->dtime*this->dtime) * acceleration;
        velocity = velocity + this->dtime * acceleration;
        t += this->dtime;
    }
    while (position.z > target_elevation);
    
    Target trg = Target(0.5 * (position.x + prev_position.x), 0.5 * (position.y + prev_position.y));
    
    return Event(launch, trg, t - 0.5*dtime);
}
Пример #28
0
Vec3D DXFSolid::rotz( const Vec3D &x )
{
    return( Vec3D( x[2], sqrt( x[0]*x[0] + x[1]*x[1] ) ) );
}
Пример #29
0
ModelInstance::ModelInstance(MPQFile &f, const char* ModelInstName, uint32 mapID, uint32 tileX, uint32 tileY, FILE *pDirfile)
{
    float ff[3];
    f.read(&id, 4);
    f.read(ff, 12);
    pos = fixCoords(Vec3D(ff[0], ff[1], ff[2]));
    f.read(ff, 12);
    rot = Vec3D(ff[0], ff[1], ff[2]);
    f.read(&scale, 4);
    // scale factor - divide by 1024. blizzard devs must be on crack, why not just use a float?
    sc = scale / 1024.0f;

    char tempname[512];
    sprintf(tempname, "%s/%s", szWorkDirWmo, ModelInstName);
    FILE *input;
    input = fopen(tempname, "r+b");

    if (!input)
    {
        //printf("ModelInstance::ModelInstance couldn't open %s\n", tempname);
        return;
    }

    fseek(input, 8, SEEK_SET); // get the correct no of vertices
    int nVertices;
    fread(&nVertices, sizeof (int), 1, input);
    fclose(input);

    if (nVertices == 0)
        return;

    uint16 adtId = 0;// not used for models
    uint32 flags = MOD_M2;
    if (tileX == 65 && tileY == 65) flags |= MOD_WORLDSPAWN;
    //write mapID, tileX, tileY, Flags, ID, Pos, Rot, Scale, name
    fwrite(&mapID, sizeof(uint32), 1, pDirfile);
    fwrite(&tileX, sizeof(uint32), 1, pDirfile);
    fwrite(&tileY, sizeof(uint32), 1, pDirfile);
    fwrite(&flags, sizeof(uint32), 1, pDirfile);
    fwrite(&adtId, sizeof(uint16), 1, pDirfile);
    fwrite(&id, sizeof(uint32), 1, pDirfile);
    fwrite(&pos, sizeof(float), 3, pDirfile);
    fwrite(&rot, sizeof(float), 3, pDirfile);
    fwrite(&sc, sizeof(float), 1, pDirfile);
    uint32 nlen=strlen(ModelInstName);
    fwrite(&nlen, sizeof(uint32), 1, pDirfile);
    fwrite(ModelInstName, sizeof(char), nlen, pDirfile);

    /* int realx1 = (int) ((float) pos.x / 533.333333f);
    int realy1 = (int) ((float) pos.z / 533.333333f);
    int realx2 = (int) ((float) pos.x / 533.333333f);
    int realy2 = (int) ((float) pos.z / 533.333333f);

    fprintf(pDirfile, "%s/%s %f, %f, %f_%f, %f, %f %f %d %d %d, %d %d\n",
        MapName,
        ModelInstName,
        (float) pos.x, (float) pos.y, (float) pos.z,
        (float) rot.x, (float) rot.y, (float) rot.z,
        sc,
        nVertices,
        realx1, realy1,
        realx2, realy2
        ); */
}
Пример #30
0
Vec3D fixCoordSystem2(Vec3D v)
{
    return Vec3D(v.x, v.z, v.y);
}