Exemple #1
0
void PolyMolecule::computeNormals()
{
  m_FaceNormals.fill(vec3_t(0,0,0), m_Faces.size());
  m_NodeNormals.fill(vec3_t(0,0,0), m_Nodes.size());
  for (int i = 0; i < m_Faces.size(); ++i) {
    QVector<vec3_t> x(m_Faces[i].size() + 1);
    vec3_t x_face(0,0,0);
    for (int j = 0; j < m_Faces[i].size(); ++j) {
      x[j] = getXNode(m_Faces[i][j]);
      x_face += x[j];
    }
    x.last() = x.first();
    x_face *= 1.0/m_Faces[i].size();
    m_FaceNormals[i] = vec3_t(0,0,0);
    for (int j = 0; j < m_Faces[i].size(); ++j) {
      m_FaceNormals[i] += triNormal(x_face, x[j], x[j+1]);
    }
    for (int j = 0; j < m_Faces[i].size(); ++j) {
      vec3_t n = m_FaceNormals[i];
      //n.normalise();
      m_NodeNormals[m_Faces[i][j]] += n;
    }
  }
  for (int i = 0; i < m_Nodes.size(); ++i) {
    m_NodeNormals[i].normalise();
  }
}
GuiEdgeLengthSourceCone::GuiEdgeLengthSourceCone()
{
  m_X1 = vec3_t(0,0,0);
  m_X2 = vec3_t(1,0,0);
  m_R1 = 1;
  m_R2 = 1;
  m_Length1 =1;
  m_Length2 =1;
}
GuiEdgeLengthSourceSphere::GuiEdgeLengthSourceSphere()
{
  m_Centre = vec3_t(0,0,0);
  m_Radius = 1;
  m_Length1 = 1;
  m_Length2 = 1;
}
Exemple #4
0
void CParticleSystem::Update(const float dt, const uint32_t ticks, const vec3_t& ownerpos)
{
    const float gravity = GetGravity();

    std::vector<particle_t>::iterator iter;
    for(iter = m_particles.begin();iter != m_particles.end(); ++iter)
    {
        if(iter->lifetime < 0.0f)
        {
            if(iter->respawn)
            {
                InitParticle(*iter, ownerpos);
            }
            else
            {
                continue;
            }
        }

        iter->origin = iter->origin + iter->vel*dt - vec3_t(0,dt*dt*0.5f*gravity,0);
        iter->vel.y -= gravity*dt;
        iter->lifetime -= dt;
        const float f = iter->lifetime / iter->totallifetime;
        const float scale = sin(f * lynxmath::PI);
        iter->alpha = iter->startalpha * scale;
        iter->size = scale * iter->startsize + 0.1f;
    }
}
Exemple #5
0
vec3_t orthogonalVector(vec3_t v)
{
  // get absolute values
  double xx = v[0] < 0.0 ? -v[0] : v[0];
  double yy = v[1] < 0.0 ? -v[1] : v[1];
  double zz = v[2] < 0.0 ? -v[2] : v[2];
  // switch both biggest values and set the other one to zero
  vec3_t u;
  if (xx < yy) {
    u = xx < zz ? vec3_t(0,v[2],-v[1]) : vec3_t(v[1],-v[0],0);
  } else {
    u = yy < zz ? vec3_t(-v[2],0,v[0]) : vec3_t(v[1],-v[0],0);
  }
  u.normalise();
  return u;
}
Exemple #6
0
bool CPartEffects::Collision( Particle_s *pPart )
{
	// check collsion
	int iContents = gEngfuncs.PM_PointContents( pPart->vOrg, NULL );
	if( iContents == CONTENTS_WIND )
	{
		// if we are in a force based object get the force to add to the particle
		pmtrace_s *pmTrace = gEngfuncs.PM_TraceLine( pPart->vOrg, pPart->vOrg, PM_TRACELINE_PHYSENTSONLY, 2, -1 );

		// get entitys index
		if( pmTrace->ent != 0 )
		{
			cl_entity_t *pEnt = gEngfuncs.GetEntityByIndex( pmTrace->ent );

			if( pEnt && pEnt->curstate.skin == CONTENTS_WIND )
			{
				// add wind to object
				vec3_t vVel = pEnt->curstate.angles + vec3_t( gEngfuncs.pfnRandomFloat( -pEnt->curstate.fuser1, pEnt->curstate.fuser1 ),
					gEngfuncs.pfnRandomFloat( -pEnt->curstate.fuser1, pEnt->curstate.fuser1 ),
					gEngfuncs.pfnRandomFloat( -pEnt->curstate.fuser1, pEnt->curstate.fuser1 ) );	// angle randomization
				vVel = vVel.Normalize( );
				vVel = vVel * pEnt->curstate.fuser2;		// speed scaler

				pPart->vVel = pPart->vVel + vVel;
			}
		}
		return true;
	}
	else if( iContents != CONTENTS_EMPTY )
	{
		return true;
	}

	return false;
}
Exemple #7
0
void CPartEffects::AnimOnCol( Particle_s *pPart )
{
	// check for collision
	if( Collision( pPart ) )
	{
		//set gravity to 0, and velocity to 0
		pPart->flGrav = 0;
		pPart->vVel = vec3_t( 0,0,0 );

		if( pPart->iCurFrame == 0 )		//first run
		{
			// set soemthign saying it has already been 0
			pPart->iBounces = 1;
			pmtrace_t *pTrace = gEngfuncs.PM_TraceLine( pPart->vPOrg, pPart->vOrg, PM_TRACELINE_ANYVISIBLE, 2, -1 );
			if( pTrace->fraction != 1.0 )
			{
				pPart->vOrg = pTrace->endpos;
			}

		}
		Anim( pPart );
		if( pPart->iCurFrame == 0 )
		{
			// set a flag to kill it
			pPart->iBounces = -1;
		}
	}
}
void SeligAirfoilReader::operate()
{
  try {
    readInputFileName("");
    if (isValid()) {
      QFile file(getFileName());
      file.open(QIODevice::ReadOnly | QIODevice::Text);
      QTextStream f(&file);
      f.readLine();
      EG_VTKSP(vtkPolyData, poly);
      double read_value;
      int num_upper, num_lower;
      f >> read_value;
      num_upper = int(read_value);
      f >> read_value;
      num_lower = int(read_value);
      int num_nodes = num_lower + num_upper - 1;
      QVector<vec3_t> coord(num_nodes, vec3_t(0,0,0));
      for (int i = 0; i < num_upper; ++i) {
        f >> coord[i][0] >> coord[i][1];
      }
      double dummy;
      f >> dummy;
      f >> dummy;
      for (int i = num_nodes - 1; i >= num_upper; --i) {
        f >> coord[i][0] >> coord[i][1];
      }
      EG_VTKSP(vtkPoints, points);
      points->SetNumberOfPoints(num_nodes);
      poly->SetPoints(points);
      poly->Allocate(num_nodes);
      for (vtkIdType id_node = 0; id_node < num_nodes; ++id_node) {
        poly->GetPoints()->SetPoint(id_node, coord[id_node].data());
      }
      for (vtkIdType id_node = 0; id_node < num_nodes; ++id_node) {
        vtkIdType pts[2];
        pts[0] = id_node;
        if (id_node < num_nodes-1) {
          pts[1] = id_node + 1;
        } else {
          pts[1] = 0;
        }
        poly->InsertNextCell(VTK_LINE, 2, pts);
      }

      EG_VTKSP(vtkDelaunay2D, tri);
      tri->SetInputData(poly);
      tri->SetSourceData(poly);
      EG_VTKSP(vtkEgPolyDataToUnstructuredGridFilter, poly2ug);
      poly2ug->SetInputConnection(tri->GetOutputPort());
      poly2ug->Update();
      makeCopy(poly2ug->GetOutput(), m_Grid);
      UpdateNodeIndex(m_Grid);
      UpdateCellIndex(m_Grid);
    }
  } catch (Error err) {
    err.display();
  }
}
Exemple #9
0
void CParticleSystemBlood::InitParticle(particle_t& p, const vec3_t& ownerpos)
{
    p.startalpha = p.alpha = 0.2f + 0.4f*CLynx::randfabs();
    p.color = vec3_t(1,1,1);
    p.totallifetime = p.lifetime = 0.4f + CLynx::randfabs()*0.4f;
    p.origin = vec3_t::rand(0.8f,0.4f,0.8f) + m_dir*0.5f + ownerpos;
    p.size = p.startsize = m_size;
    p.vel = (m_dir + vec3_t::rand(1.5f, 1.5f, 1.5f)).Normalized() * 10.0f;
}
Exemple #10
0
// robi updejt pociskow
void HBulletManager::Update() {
    /* TODO (#1#): Implement HBulletManager::Update() */
    float delta=HTimer::GetSingleton().GetDelta()/100;
    for (int i=0;i<MAX_BULLETS;i++) {
        if (m_Bullets[i].type==BulletNone) continue;
        m_Bullets[i].pos+=m_Bullets[i].vel*delta;
        if (m_Bullets[i].pos.GetDistance(vec3_t(0,0,0))>10000) m_Bullets[i].type=BulletNone;
    }
}
Exemple #11
0
void CAWP::PrimaryAttack()
{
	if( m_iClip <= 0 )
		return;

	m_iClip--;

	m_pPlayer->SetAnimation( PLAYER_ATTACK1 );

	Vector vecSrc( m_pPlayer->GetGunPosition() );
	Vector vecAim( m_pPlayer->GetAutoaimVector( AUTOAIM_2DEGREES ) );
	Vector vecAcc( g_vecZero );

	if ( !( m_pPlayer->pev->flags & FL_ONGROUND ) )
		vecAcc = vec3_t( 0.85, 0.85, 0.85 );
	else if ( m_pPlayer->pev->velocity.Length2D() > 140 || !scope )
		vecAcc = vec3_t( 0.25, 0.25, 0.25 );
    else if ( m_pPlayer->pev->velocity.Length2D() > 10 )
		vecAcc = vec3_t( 0.10, 0.10, 0.10 );
    else
		vecAcc = vec3_t( 0, 0, 0 );

	Vector vecDir( m_pPlayer->FireBulletsPlayer( 1, vecSrc, vecAim, vecAcc, 8192,0, 0, 114, m_pPlayer->pev, m_pPlayer->random_seed ) );

	SendWeaponAnim( AWP_SHOOT1 );

	PLAYBACK_EVENT_FULL( FEV_NOTHOST, m_pPlayer->edict(), m_event, 0.0,
		(float *)&g_vecZero, (float *)&g_vecZero,
		vecDir.x, vecDir.y, 0, 0, (m_iClip ? 0 : 1), 0 );

	m_pPlayer->pev->fov = 0;
	m_pPlayer->m_iFOV = m_pPlayer->pev->fov;
	scope = false;
	g_engfuncs.pfnSetClientMaxspeed(m_pPlayer->edict(), 210 );
#ifndef CLIENT_DLL
	MESSAGE_BEGIN( MSG_ONE, gmsgScopeToggle, NULL, m_pPlayer->pev );
		WRITE_BYTE( 0 );
	MESSAGE_END();
#endif

	m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 1.45;
	m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 1.45;
	m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.45;
}
bool GuiEdgeLengthSourceBox::read(QString txt)
{
  QStringList parts = txt.split(":");
  if (parts.size() != 2) {
    return false;
  }
  if (parts[0].trimmed() == "box") {
    QStringList words = parts[1].split(";");
    if (words.size() < 8) {
      return false;
    }
    m_Name = words[0].trimmed();
    m_X1 = vec3_t(words[1].toDouble(), words[2].toDouble(), words[3].toDouble());
    m_X2 = vec3_t(words[4].toDouble(), words[5].toDouble(), words[6].toDouble());
    m_Length = words[7].toDouble();
  } else {
    return false;
  }
  return true;
}
void TriangularCadInterface::updateBackgroundGridInfo()
{
  getAllCells(m_Cells, m_BGrid);
  getNodesFromCells(m_Cells, m_Nodes, m_BGrid);
  setBoundaryCodes(GuiMainWindow::pointer()->getAllBoundaryCodes());
  setAllCells();
  readVMD();
  updatePotentialSnapPoints();
  l2l_t  c2c   = getPartC2C();
  g2l_t _cells = getPartLocalCells();
  QVector<int> m_LNodes(m_Nodes.size());
  for (int i = 0; i < m_LNodes.size(); ++i) {
    m_LNodes[i] = i;
  }
  createNodeToNode(m_Cells, m_Nodes, m_LNodes, m_N2N, m_BGrid);

  // create m_Triangles
  m_Triangles.resize(m_BGrid->GetNumberOfCells());
  for (vtkIdType id_cell = 0; id_cell < m_BGrid->GetNumberOfCells(); ++id_cell) {
    m_Triangles[id_cell] = Triangle(m_BGrid, id_cell);
    for (int i = 0; i < 3; i++) {
      int i_cell = _cells[id_cell];
      if (c2c[i_cell][i] < 0) {
        m_Triangles[id_cell].setNeighbourFalse(i);
      } else {
        m_Triangles[id_cell].setNeighbourTrue(i);
      }
    }
  }

  // compute node normals
  m_NodeNormals.resize(m_BGrid->GetNumberOfPoints());
  for (vtkIdType id_node = 0; id_node < m_BGrid->GetNumberOfPoints(); ++id_node) {
    m_NodeNormals[id_node] = vec3_t(0, 0, 0);
  }

  foreach(Triangle T, m_Triangles) {
    double angle_a = GeometryTools::angle(m_BGrid, T.idC(), T.idA(), T.idB());
    double angle_b = GeometryTools::angle(m_BGrid, T.idA(), T.idB(), T.idC());
    double angle_c = GeometryTools::angle(m_BGrid, T.idB(), T.idC(), T.idA());
    if (isnan(angle_a) || isinf(angle_a)) EG_BUG;
    if (isnan(angle_b) || isinf(angle_b)) EG_BUG;
    if (isnan(angle_c) || isinf(angle_c)) EG_BUG;
    if (!checkVector(T.g3())) {
      qWarning() << "T.g3 = " << T.g3();
      EG_BUG;
    }
    m_NodeNormals[T.idA()] += angle_a * T.g3();
    m_NodeNormals[T.idB()] += angle_b * T.g3();
    m_NodeNormals[T.idC()] += angle_c * T.g3();
    if (!checkVector(m_NodeNormals[T.idA()])) EG_BUG;
    if (!checkVector(m_NodeNormals[T.idB()])) EG_BUG;
    if (!checkVector(m_NodeNormals[T.idC()])) EG_BUG;
  }
Exemple #14
0
//=========================================================
// Sets up movetype, size, solidtype for a new weapon. 
//=========================================================
void CBasePlayerItem :: FallInit( void )
{
	pev->movetype = MOVETYPE_TOSS;
	pev->solid = SOLID_BBOX;

	UTIL_SetOrigin( pev, pev->origin + vec3_t( 0, 0, 0 ) );
	UTIL_SetSize(pev, Vector( 0, 0, 0), Vector(0, 0, 0) );//pointsize until it lands on the ground.
	
	SetTouch( DefaultTouch );
	SetThink( FallThink );

	pev->nextthink = gpGlobals->time + 0.1;
}
Exemple #15
0
void PolyMolecule::computeCentreOfGravity()
{
  m_AllPositive = true;
  // first guess of centre of gravity
  vec3_t x_centre(0,0,0);
  for (int i = 0; i < m_Faces.size(); ++i) {
    x_centre += getXFace(i);
  }
  m_N2BadFaces.resize(m_Nodes.size());
  for (int i = 0; i < m_Nodes.size(); ++i) {
    m_N2BadFaces[i].clear();
  }
  x_centre *= 1.0/m_Faces.size();
  for (int iter = 0; iter < 2; ++iter) {
    double V_total = 0;
    m_CentreOfGravity = vec3_t(0,0,0);
    m_MaxPyramidVolume = -1e99;
    m_MinPyramidVolume =  1e99;
    for (int i = 0; i < m_Faces.size(); ++i) {
      double V_pyramid = 0;
      vec3_t x_face = getXFace(i);
      QVector<vec3_t> x(m_Faces[i].size() + 1);
      for (int j = 0; j < m_Faces[i].size(); ++j) {
        x[j] = getXNode(m_Faces[i][j]);
      }
      x.last() = x.first();      
      for (int j = 0; j < m_Faces[i].size(); ++j) {
        double V = GeometryTools::tetraVol(x_face, x[j+1], x[j], x_centre, true);
        if (V <= 0) {
          m_AllPositive = false;
        }
        V_total += V;
        V_pyramid += V;
        m_CentreOfGravity += 0.25*V*(x_face + x[j+1] + x[j] + x_centre);
      }
      if (V_pyramid <= 0) {
        for (int j = 0; j < m_Faces[i].size(); ++j) {
          m_N2BadFaces[m_Faces[i][j]].insert(i);
        }
      }
      m_MaxPyramidVolume = max(V_pyramid, m_MaxPyramidVolume);
      m_MinPyramidVolume = min(V_pyramid, m_MinPyramidVolume);
    }
    m_CentreOfGravity *= 1.0/V_total;
    x_centre = m_CentreOfGravity;
  }
}
Exemple #16
0
void FaceFinder::setGrid(vtkUnstructuredGrid *grid)
{
  m_Grid = grid;
  m_Triangles.resize(m_Grid->GetNumberOfCells());
  m_Centres.resize(m_Grid->GetNumberOfCells());
  for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
    if (m_Grid->GetCellType(id_cell) != VTK_TRIANGLE) {
      EG_BUG;
    }
    m_Triangles[id_cell] = Triangle(m_Grid, id_cell);
    m_Centres[id_cell] = cellCentre(m_Grid, id_cell);
  }
  {
    double bounds[6];
    m_Grid->GetBounds(bounds);
    vec3_t x1(bounds[0], bounds[2], bounds[4]);
    vec3_t x2(bounds[1], bounds[3], bounds[5]);
    vec3_t xc = 0.5*(x1 + x2);
    vec3_t Dx = x2 - xc;
    double dx_max = max(Dx[0], max(Dx[1], Dx[2]));
    Dx = vec3_t(dx_max, dx_max, dx_max);
    x1 = xc - 2*Dx;
    x2 = xc + 2*Dx;
    m_Octree.setBounds(x1, x2);
    if (m_UseImprovedFaceSearch) {
      m_MinSize = 0.005*Dx[0];
    } else {
      m_MinSize = 0.0001*Dx[0];
    }
  }
  m_Faces.resize(1);
  for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
    m_Faces[0].append(id_cell);
  }  
  if (m_UseImprovedFaceSearch) {
    m_CritLengthOctreeCell.fill(EG_LARGE_REAL, 1);
    foreach (vtkIdType id_cell, m_Faces[0]) {
      m_CritLengthOctreeCell[0] = min(m_CritLengthOctreeCell[0], calcCritLength(id_cell));
    }
    calcCritLengthForAllNodes();
  } else {
// inEntityIndex, x, y, z
static int setPos(lua_State* inState)
{
	// Get entity index
	int theIndex = lua_tonumber(inState, 1);
	if(theIndex > 0)
	{
		// Look it up
		CBaseEntity* theEntity = CBaseEntity::Instance(g_engfuncs.pfnPEntityOfEntIndex(theIndex));
		if(theEntity)
		{
			// Set it's position
			float theX = lua_tonumber(inState, 2);
			float theY = lua_tonumber(inState, 3);
			float theZ = lua_tonumber(inState, 4);
			theEntity->pev->origin = vec3_t(theX, theY, theZ);
		}
	}
	
	// Return true or false
	return 0;
}
void SensorFusion::process(const sensors_event_t& event) {
    if (event.type == SENSOR_TYPE_GYROSCOPE) {
        if (mGyroTime != 0) {
            const float dT = (event.timestamp - mGyroTime) / 1000000000.0f;
            const float freq = 1 / dT;
            if (freq >= 100 && freq<1000) { // filter values obviously wrong
                const float alpha = 1 / (1 + dT); // 1s time-constant
                mGyroRate = freq + (mGyroRate - freq)*alpha;
            }
        }
        mGyroTime = event.timestamp;
        mFusion.handleGyro(vec3_t(event.data), 1.0f/mGyroRate);
    } else if (event.type == SENSOR_TYPE_MAGNETIC_FIELD) {
        const vec3_t mag(event.data);
        mFusion.handleMag(mag);
    } else if (event.type == SENSOR_TYPE_ACCELEROMETER) {
        const vec3_t acc(event.data);
        mFusion.handleAcc(acc);
        mAttitude = mFusion.getAttitude();
    }
}
bool GuiEdgeLengthSourceSphere::read(QString txt)
{
  QStringList parts = txt.split(":");
  if (parts.size() != 2) {
    return false;
  }
  if (parts[0].trimmed() == "sphere") {
    QStringList words = parts[1].split(";");
    if (words.size() < 7) {
      return false;
    }
    m_Name = words[0].trimmed();
    m_Centre = vec3_t(words[1].toDouble(), words[2].toDouble(), words[3].toDouble());
    m_Radius = words[4].toDouble();
    m_Length1 = words[5].toDouble();
    m_Length2 = words[6].toDouble();
  } else {
    return false;
  }
  return true;
}
void SensorFusion::process(const sensors_event_t& event) {
    if (event.type == mGyro.getType()) {
        if (mGyroTime != 0) {
            const float dT = (event.timestamp - mGyroTime) / 1000000000.0f;
            mFusion.handleGyro(vec3_t(event.data), dT);
            // here we estimate the gyro rate (useful for debugging)
            const float freq = 1 / dT;
            if (freq >= 100 && freq<1000) { // filter values obviously wrong
                const float alpha = 1 / (1 + dT); // 1s time-constant
                mEstimatedGyroRate = freq + (mEstimatedGyroRate - freq)*alpha;
            }
        }
        mGyroTime = event.timestamp;
    } else if (event.type == SENSOR_TYPE_MAGNETIC_FIELD) {
        const vec3_t mag(event.data);
        mFusion.handleMag(mag);
    } else if (event.type == SENSOR_TYPE_ACCELEROMETER) {
        const vec3_t acc(event.data);
        mFusion.handleAcc(acc);
        mAttitude = mFusion.getAttitude();
    }
}
Exemple #21
0
vec3_t vec3_t::rand(float mx, float my, float mz)
{
    return vec3_t( mx * ( (float)(::rand()%20000)*0.0001f - 1.0f ),
                   my * ( (float)(::rand()%20000)*0.0001f - 1.0f ),
                   mz * ( (float)(::rand()%20000)*0.0001f - 1.0f ) );
}
void CreateCadTesselation::operate()
{
  double preview_memory = min(1024*1024*100.0, m_ScanMemory);
  int N = int(pow(preview_memory/sizeof(float), 1.0/3.0));
  m_Ni = N;
  m_Nj = N;
  m_Nk = N;
  m_X1 = vec3_t(-1e6,-1e6,-1e6);
  m_X2 = vec3_t( 1e6, 1e6, 1e6);
  m_Dx = (m_X2[0] - m_X1[0])/(m_Ni-1);
  m_Dy = (m_X2[1] - m_X1[1])/(m_Nj-1);
  m_Dz = (m_X2[2] - m_X1[2])/(m_Nk-1);
  double new_vol, old_vol;
  int count = 0;
  do {
    old_vol = (m_X2[0]-m_X1[0])*(m_X2[1]-m_X1[1])*(m_X2[2]-m_X1[2]);
    QString num;
    QString text = "scanning (V=";
    num.setNum(old_vol);
    text += num + ")";

    GuiMainWindow::pointer()->resetProgress(text, 3*N*N);
    scan(false);
    if (m_GeometryFound) {
      m_X1 = m_XScan1 - 2*vec3_t(m_Dx, m_Dy, m_Dz);
      m_X2 = m_XScan2 + 2*vec3_t(m_Dx, m_Dy, m_Dz);
    } else {
      m_X1 *= 0.1;
      m_X2 *= 0.1;
    }
    new_vol = (m_X2[0]-m_X1[0])*(m_X2[1]-m_X1[1])*(m_X2[2]-m_X1[2]);
  } while (count < 20 && (old_vol - new_vol)/old_vol > 0.05);

  // bounding box should now be established
  // last scan run with the full resoluion (if required)
  double Lx = m_X2[0] - m_X1[0];
  double Ly = m_X2[1] - m_X1[1];
  double Lz = m_X2[2] - m_X1[2];
  double max_size = m_ScanMemory/sizeof(float);
  double delta = max(m_SmallestResolution, pow(Lx*Ly*Lz/max_size, 1.0/3.0));
  int interlaces = 0;
  if (preserveFluid() || preserveSolid()) {
    interlaces = int(2*delta/m_SmallestFeatureSize);
  }
  m_Ni = int(Lx/delta) + 1;
  m_Nj = int(Ly/delta) + 1;
  m_Nk = int(Lz/delta) + 1;
  QString num;
  QString text = "scanning (h=";
  num.setNum(delta/(interlaces+1));
  text += num + ")";
  GuiMainWindow::pointer()->resetProgress(text, m_Ni*m_Nj + m_Ni*m_Nk + m_Nj*m_Nk);
  scan(true, interlaces);

  updateNodeIndex(m_Grid);
  updateCellIndex(m_Grid);
  GuiMainWindow::pointer()->resetXmlDoc();
  GuiMainWindow::pointer()->clearBCs();
  GuiMainWindow::pointer()->setBC(1, BoundaryCondition("imported", "patch", 1));

  GuiMainWindow::pointer()->resetProgress(" ", 100);
}
void GuiNormalExtrusion::operate()
{
  QSet<int> bcs;
  getSelectedItems(m_Ui.listWidget, bcs);
  EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
  QSet<int> volume_codes;
  EG_FORALL_CELLS(id_cell, m_Grid) {
    if (isSurface(id_cell, m_Grid)) {
      if (bcs.contains(cell_code->GetValue(id_cell))) {
        vtkIdType id_volume_cell = m_Part.getVolumeCell(id_cell);
        if (id_volume_cell != -1) {
          volume_codes.insert(cell_code->GetValue(id_volume_cell));
        }
      }
    }
  }

  EG_VTKSP(vtkEgNormalExtrusion, extr);
  QVector<double> y;
  
  if (m_Ui.radioButtonSimple->isChecked()) {
    y.resize(m_Ui.lineEditSimpleNumLayers->text().toInt() + 1);
    double h = m_Ui.lineEditSimpleHeight->text().toDouble();
    double f = m_Ui.lineEditSimpleIncrease->text().toDouble();
    y[0] = 0.0;
    for (int i = 1; i < y.size(); ++i) {
      y[i] = y[i-1] + h;
      h *= f;
    }
  } else if (m_Ui.radioButtonFixedHeights->isChecked()) {
    y.resize(m_Ui.lineEditFixedHeightsNumLayers->text().toInt() + 1);
    QVector<double> x(y.size());
    for (int i = 0; i < x.size(); ++i) {
      x[i] = i*1.0/(x.size() - 1);
    }
    mat3_t A;
    clinit(A[0]) = pow(x[1],5.0), pow(x[1],3.0), x[1];
    clinit(A[1]) = pow(x[x.size() - 2],5.0), pow(x[x.size() - 2],3.0), x[x.size() - 2];
    clinit(A[2]) = pow(x[x.size() - 1],5.0), pow(x[x.size() - 1],3.0), x[x.size() - 1];
    vec3_t h;
    h[0] = m_Ui.lineEditFixedHeightsHeightFirst->text().toDouble();
    h[2] = m_Ui.lineEditFixedHeightsTotalHeight->text().toDouble();
    h[1] = h[2] - m_Ui.lineEditFixedHeightsHeightLast->text().toDouble();
    mat3_t AI = A.inverse();
    vec3_t coeff = AI*h;
    for (int i = 0; i < y.size(); ++i) {
      y[i] = coeff[0]*pow(x[i],5.0) + coeff[1]*pow(x[i],3.0) + coeff[2]*x[i];
      if (i > 0) {
        if (y[i] < y[i-1]) {
          EG_ERR_RETURN("unable to compute layer heights");
        }
      }
    }
  }
  extr->SetLayers(y);
  
  if (m_Ui.radioButtonFixed->isChecked()) {
    extr->SetNormal(vec3_t(m_Ui.lineEditFixedNX->text().toDouble(),
                           m_Ui.lineEditFixedNY->text().toDouble(),
                           m_Ui.lineEditFixedNZ->text().toDouble()));
    double min_dist = m_Ui.lineEditFixedDist->text().toDouble();
    if (min_dist <= 0) {
      extr->SetFixed();
    } else {
      extr->SetPlanar();
      extr->SetMinDist(min_dist);
    }
  }
  if (m_Ui.radioButtonCylinder->isChecked()) {
    extr->SetCylindrical();
    extr->SetOrigin(vec3_t(m_Ui.lineEditCylinderX0->text().toDouble(),
                           m_Ui.lineEditCylinderY0->text().toDouble(),
                           m_Ui.lineEditCylinderZ0->text().toDouble()));
    extr->SetAxis(vec3_t(m_Ui.lineEditCylinderNX->text().toDouble(),
                         m_Ui.lineEditCylinderNY->text().toDouble(),
                         m_Ui.lineEditCylinderNZ->text().toDouble()));
  }
  if (m_Ui.radioButtonRotation->isChecked()) {
    extr->SetRotation();
    extr->SetOrigin(vec3_t(m_Ui.lineEditCylinderX0->text().toDouble(),
                           m_Ui.lineEditCylinderY0->text().toDouble(),
                           m_Ui.lineEditCylinderZ0->text().toDouble()));
    extr->SetAxis(vec3_t(m_Ui.lineEditCylinderNX->text().toDouble(),
                         m_Ui.lineEditCylinderNY->text().toDouble(),
                         m_Ui.lineEditCylinderNZ->text().toDouble()));
  }

  if (m_Ui.radioButtonNoRestrict->isChecked()) {
    extr->SetRestrictNone();
  }
  if (m_Ui.radioButtonXY->isChecked()) {
    extr->SetRestrictXY();
  }
  if (m_Ui.radioButtonXZ->isChecked()) {
    extr->SetRestrictXZ();
  }
  if (m_Ui.radioButtonYZ->isChecked()) {
    extr->SetRestrictYZ();
  }

  if (m_Ui.checkBoxNewVolume->isChecked()) {
    extr->SetRemoveInternalFacesOff();
  }

  QList<VolumeDefinition> vols = GuiMainWindow::pointer()->getAllVols();
  int vc = 1;
  foreach (VolumeDefinition vol, vols) {
    vc = max(vc, vol.getVC());
  }
GuiEdgeLengthSourceBox::GuiEdgeLengthSourceBox()
{
  m_X1 = vec3_t(0,0,0);
  m_X2 = vec3_t(1,0,0);
  m_Length = 1;
}
void CreateCadTesselation::scan(bool create_grid, int interlaces)
{
  m_Dx = (m_X2[0] - m_X1[0])/(m_Ni-1);
  m_Dy = (m_X2[1] - m_X1[1])/(m_Nj-1);
  m_Dz = (m_X2[2] - m_X1[2])/(m_Nk-1);

  EG_VTKSP(vtkImageData, gdata);
  gdata->SetDimensions(m_Ni, m_Nj, m_Nk);
  EG_VTKSP(vtkFloatArray, g);
  g->SetName("g");
  g->SetNumberOfValues(m_Ni*m_Nj*m_Nk);
  gdata->GetPointData()->AddArray(g);
  for (int i = 0; i < m_Ni; ++i) {
    for (int j = 0; j < m_Nj; ++j) {
      for (int k = 0; k < m_Nk; ++k) {                
        if (preserveFluid()) {
          g->SetValue(getIdx(i,j,k), 1);
        } else {
          g->SetValue(getIdx(i,j,k), 0);
        }
      }
    }
  }
  m_XScan1 = m_X2;
  m_XScan2 = m_X1;

  vec3_t x_in, x_out, n_in, n_out;

  int progress = 0;
  m_GeometryFound = false;

  double dxi = m_Dx/(interlaces + 1);
  double dyi = m_Dy/(interlaces + 1);
  double dzi = m_Dz/(interlaces + 1);

  double shift = 1e-6;

  // scan ij plane -> k direction
  //      xy plane -> z direction
  for (int i = 0; i < m_Ni; ++i) {
    for (int j = 0; j < m_Nj; ++j) {
      vec3_t x0 = getX(i,j,0);
      for (int i_il = 0; i_il <= interlaces; ++i_il) {
        for (int j_il = 0; j_il <= interlaces; ++j_il) {
          vec3_t x = x0;
          x[0] += i_il*dxi;
          x[1] += j_il*dyi;
          int k_last = 0;
          while (shootRay(x, vec3_t(0,0,1), x_in, x_out, n_in, n_out)) {
            m_GeometryFound = true;
            m_XScan1[2] = min(m_XScan1[2], x_in[2]);
            m_XScan2[2] = max(m_XScan2[2], x_out[2]);
            int k1 = int((x_in[2] - m_X1[2])/m_Dz) + 1;
            int k2 = int((x_out[2] - m_X1[2])/m_Dz);
            if (preserveFluid()) {
              for (int k = k_last; k < min(m_Nk-1,k1); ++k) {
                g->SetValue(getIdx(i,j,k), 0);
              }
            } else {
              for (int k = max(0,k1); k <= min(m_Nk-1,k2); ++k) {
                g->SetValue(getIdx(i,j,k), 1);
              }
            }
            x = x_out;
            x[2] += shift*m_Dz;
            k_last = min(m_Nk-1,k2+1);
          }
          if (preserveFluid()) {
            for (int k = k_last; k <= m_Nk-1; ++k) {
              g->SetValue(getIdx(i,j,k), 0);
            }
          }
        }
      }
    }
    progress += m_Nj;
    GuiMainWindow::pointer()->setProgress(progress);
  }

  // scan ik plane -> j direction
  //      xz plane -> y direction
  for (int i = 0; i < m_Ni; ++i) {
    for (int k = 0; k < m_Nk; ++k) {
      vec3_t x0 = getX(i,0,k);
      for (int i_il = 0; i_il <= interlaces; ++i_il) {
        for (int k_il = 0; k_il <= interlaces; ++k_il) {
          vec3_t x = x0;
          x[0] += i_il*dxi;
          x[2] += k_il*dzi;
          int j_last = 0;
          /*
          if (fabs(x0[0]) < 1.5 && fabs(x0[2]) < 1.5 && create_grid) {
            cout << x0 << endl;
          }
          */
          while (shootRay(x, vec3_t(0,1,0), x_in, x_out, n_in, n_out)) {
            m_GeometryFound = true;
            m_XScan1[1] = min(m_XScan1[1], x_in[1]);
            m_XScan2[1] = max(m_XScan2[1], x_out[1]);
            int j1 = int((x_in[1]-m_X1[1])/m_Dy) + 1;
            int j2 = int((x_out[1]-m_X1[1])/m_Dy);
            if (preserveFluid()) {
              for (int j = j_last; j < min(m_Nj-1,j1); ++j) {
                g->SetValue(getIdx(i,j,k), 0);
              }
            } else {
              for (int j = max(0,j1); j <= min(m_Nj-1,j2); ++j) {
                g->SetValue(getIdx(i,j,k), 1);
              }
            }
            x = x_out;
            x[1] += shift*m_Dy;
            j_last = min(m_Nj-1,j2+1);
          }
          if (preserveFluid()) {
            for (int j = j_last; j <= m_Nj-1; ++j) {
              g->SetValue(getIdx(i,j,k), 0);
            }
          }
        }
      }
    }
    progress += m_Nk;
    GuiMainWindow::pointer()->setProgress(progress);
  }

  // scan jk plane -> i direction
  //      yz plane -> x direction
  for (int j = 0; j < m_Nj; ++j) {
    for (int k = 0; k < m_Nk; ++k) {
      vec3_t x0 = getX(0,j,k);
      for (int j_il = 0; j_il <= interlaces; ++j_il) {
        for (int k_il = 0; k_il <= interlaces; ++k_il) {
          vec3_t x = x0;
          x[1] += j_il*dyi;
          x[2] += k_il*dzi;
          int i_last = 0;
          while (shootRay(x, vec3_t(1,0,0), x_in, x_out, n_in, n_out)) {
            m_GeometryFound = true;
            m_XScan1[0] = min(m_XScan1[0], x_in[0]);
            m_XScan2[0] = max(m_XScan2[0], x_out[0]);
            int i1 = int((x_in[0]-m_X1[0])/m_Dx) + 1;
            int i2 = int((x_out[0]-m_X1[0])/m_Dx);
            if (preserveFluid()) {
              for (int i = i_last; i < min(m_Ni-1,i1); ++i) {
                g->SetValue(getIdx(i,j,k), 0);
              }
            } else {
              for (int i = max(0,i1); i <= min(m_Ni-1,i2); ++i) {
                g->SetValue(getIdx(i,j,k), 1);
              }
            }
            x = x_out;
            x[0] += shift*m_Dx;
            i_last = min(m_Ni-1,i2+1);
          }
          if (preserveFluid()) {
            for (int i = i_last; i <= m_Ni-1; ++i) {
              g->SetValue(getIdx(i,j,k), 0);
            }
          }
        }
      }
    }
    progress += m_Nk;
    GuiMainWindow::pointer()->setProgress(progress);
  }

  if (create_grid) {

    GuiMainWindow::pointer()->resetProgress("smoothing", m_Ni*m_Nj*m_Nk*m_NumIterations);

    // smooth image data
    int progress = 0;
    for (int iter = 1; iter <= m_NumIterations; ++iter) {
      for (int i = 1; i < m_Ni-1; ++i) {
        for (int j = 1; j < m_Nj-1; ++j) {
          for (int k = 1; k < m_Nk-1; ++k) {
            int idx = getIdx(i,j,k);
            bool preserve = false;
            if (m_PreservationType == 1 && g->GetValue(idx) > 0.999) {
              preserve = true;
            }
            if (m_PreservationType == 2 && g->GetValue(idx) < 0.001) {
              preserve = true;
            }
            if (!preserve) {
              double g_new = 0;
              g_new += g->GetValue(getIdx(i+1,j,k));
              g_new += g->GetValue(getIdx(i-1,j,k));
              g_new += g->GetValue(getIdx(i,j+1,k));
              g_new += g->GetValue(getIdx(i,j-1,k));
              g_new += g->GetValue(getIdx(i,j,k+1));
              g_new += g->GetValue(getIdx(i,j,k-1));
              g_new *= 1.0/6.0;
              g->SetValue(idx, g_new);
            }
          }
        }
        progress += m_Nj*m_Nk;
        GuiMainWindow::pointer()->setProgress(progress);
      }
    }    

    // write image data for testing and reporting purposes
    EG_VTKSP(vtkXMLImageDataWriter, vti);
    QString file_name = GuiMainWindow::pointer()->getCwd() + "/g.vti";
    vti->SetFileName(qPrintable(file_name));
    vti->SetDataModeToBinary();
    vti->SetInputData(gdata);
    vti->Write();

    gdata->GetPointData()->SetActiveScalars("g");
    EG_VTKSP(vtkContourFilter, contour);
    contour->SetInputData(gdata);
    contour->SetNumberOfContours(1);
    double g_level = 0.5;
    if (m_PreservationType == 1) {
      g_level = 0.5;
    }
    if (m_PreservationType == 2) {
      g_level = 0.5;
    }
    contour->SetValue(0, g_level);
    EG_VTKSP(vtkTriangleFilter, tri);
    tri->SetInputConnection(contour->GetOutputPort());
    EG_VTKSP(vtkDecimatePro, decimate);
    decimate->PreserveTopologyOn();
    decimate->SetTargetReduction(m_TargetReduction);
    decimate->SetFeatureAngle(GeometryTools::deg2rad(45));
    decimate->SetInputConnection(tri->GetOutputPort());
    decimate->Update();

    allocateGrid(m_Grid, decimate->GetOutput()->GetNumberOfPolys(), decimate->GetOutput()->GetNumberOfPoints());
    for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
      vec3_t x;
      decimate->GetOutput()->GetPoint(id_node, x.data());
      x[0] = m_X1[0] + x[0]*m_Dx;
      x[1] = m_X1[1] + x[1]*m_Dx;
      x[2] = m_X1[2] + x[2]*m_Dx;
      m_Grid->GetPoints()->SetPoint(id_node, x.data());
    }
    EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
    for (vtkIdType id_cell = 0; id_cell < decimate->GetOutput()->GetNumberOfPolys(); ++id_cell) {
      EG_GET_CELL(id_cell, decimate->GetOutput());
      vtkIdType id_new_cell = m_Grid->InsertNextCell(type_cell, num_pts, pts);
      cell_code->SetValue(id_new_cell, 1);
    }
  }
}
Exemple #26
0
Vector CBaseEntity::FireBulletsPlayer ( ULONG cShots, Vector vecSrc, Vector vecDirShooting, Vector vecSpread, float flDistance, int iBulletType, int iTracerFreq, int iDamage, entvars_t *pevAttacker, int shared_rand )
{
	static int tracerCount;
	TraceResult tr;
	Vector vecRight = gpGlobals->v_right;
	Vector vecUp = gpGlobals->v_up;
	float x, y, z;

	if ( pevAttacker == NULL )
		pevAttacker = pev;  // the default attacker is ourselves

	ClearMultiDamage();
	gMultiDamage.type = DMG_BULLET | DMG_NEVERGIB;

	for ( ULONG iShot = 1; iShot <= cShots; iShot++ )
	{

		int newDamage = iDamage;

		//Use player's random seed.
		// get circular gaussian spread
		x = UTIL_SharedRandomFloat( shared_rand + iShot, -0.5, 0.5 ) + UTIL_SharedRandomFloat( shared_rand + ( 1 + iShot ) , -0.5, 0.5 );
		y = UTIL_SharedRandomFloat( shared_rand + ( 2 + iShot ), -0.5, 0.5 ) + UTIL_SharedRandomFloat( shared_rand + ( 3 + iShot ), -0.5, 0.5 );
		z = x * x + y * y;



		Vector vecDir = vecDirShooting +
						x * vecSpread.x * vecRight +
						y * vecSpread.y * vecUp;
		Vector vecEnd;

		vecEnd = vecSrc + vecDir * flDistance;
		UTIL_TraceLine(vecSrc, vecEnd, dont_ignore_monsters, ENT(pev), &tr);
		
		// do damage, paint decals
		if (tr.flFraction != 1.0)
		{
			CBaseEntity *pEntity = CBaseEntity::Instance(tr.pHit);
			newDamage -= vec3_t( tr.vecEndPos - vecSrc ).Length() * 0.01;
			pEntity->TraceAttack(pevAttacker, newDamage, vecDir, &tr, DMG_BULLET | ((iDamage > 16) ? DMG_ALWAYSGIB : DMG_NEVERGIB) );
			FireBulletsWater( vecSrc, tr.vecEndPos, 0.5, 0.3 );
			TEXTURETYPE_PlaySound(&tr, vecSrc, vecEnd, iBulletType);
			DecalGunshot( &tr, iBulletType );
			
			if( cShots == 1 )
			{
				float unit = iDamage;
				while( newDamage > 0 )
				{
					if( POINT_CONTENTS( tr.vecEndPos + vecDir * unit ) == CONTENTS_SOLID )
						break;
					UTIL_TraceLine(tr.vecEndPos + vecDir * unit, vecSrc, dont_ignore_monsters, ENT(pev), &tr);
					if( tr.fAllSolid )
						break;
					TEXTURETYPE_PlaySound(&tr, vecSrc, vecEnd, iBulletType);
					DecalGunshot( &tr, iBulletType );
					newDamage /= 2;
					unit /= 2;
					vecSrc = tr.vecEndPos;
					UTIL_TraceLine(tr.vecEndPos, vecEnd, dont_ignore_monsters, ENT(pev), &tr);
					newDamage -= vec3_t( tr.vecEndPos - vecSrc ).Length() * 0.01;
					pEntity = CBaseEntity::Instance(tr.pHit);
					pEntity->TraceAttack(pevAttacker, newDamage, vecDir, &tr, DMG_BULLET | ((iDamage > 16) ? DMG_ALWAYSGIB : DMG_NEVERGIB) );
					FireBulletsWater( vecSrc, tr.vecEndPos, 0.5, 0.3 );
					TEXTURETYPE_PlaySound(&tr, vecSrc, vecEnd, iBulletType);
					DecalGunshot( &tr, iBulletType );
				}
			}
			
		}
		// make bullet trails
		//UTIL_BubbleTrail( vecSrc, tr.vecEndPos, (flDistance * tr.flFraction) / 64.0 );
	}
	ApplyMultiDamage(pev, pevAttacker);

	return Vector( x * vecSpread.x, y * vecSpread.y, 0.0 );
}
AvHBaseInfoLocation::AvHBaseInfoLocation()
{
	this->mMinExtent = this->mMaxExtent = vec3_t(0, 0, 0);
}
Exemple #28
0
// gets called every frame to draw the scene
void CRenderer::Update(const float dt, const uint32_t ticks)
{
    CObj* obj, *localctrl;
    int localctrlid;
    OBJITER iter;
    matrix_t m;
    vec3_t dir, up, side;
    CFrustum frustum;
    CWorld* world;

    localctrl = m_world->GetLocalController();
    localctrlid = m_world->GetLocalObj()->GetID();
    world = m_world->GetInterpWorld();

    const vec3_t campos = localctrl->GetOrigin();
    const quaternion_t camrot = localctrl->GetRot();

    m.SetCamTransform(campos, camrot);
    m.GetVec3Cam(&dir, &up, &side);
    dir = -dir;
    frustum.Setup(campos, dir, up, side,
                  RENDERER_FOV, (float)m_width/(float)m_height,
                  PLANE_NEAR,
                  PLANE_FAR);

    // light floating above the players head
    const vec3_t lightpos0(campos + vec3_t(0,25.0f,0));
    const quaternion_t lightrot0(quaternion_t(vec3_t::xAxis, -90.0f*lynxmath::DEGTORAD));
    const float lightpos0_4f[4] = {lightpos0.x, lightpos0.y, lightpos0.z, 1};
    glLightfv(GL_LIGHT0, GL_POSITION, lightpos0_4f);
    if(m_shaderactive)
    {
        if(m_useShadows)
        {
            glUseProgram(0); // draw shadowmap with fixed function pipeline
            PrepareShadowMap(lightpos0,
                    lightrot0,
                    world,
                    localctrlid); // the player is the light
        }
        glUseProgram(m_program); // activate shader
    }

    glMatrixMode(GL_MODELVIEW);
    glLoadMatrixf(m.pm);

    glClear(GL_DEPTH_BUFFER_BIT);
    glClear(GL_COLOR_BUFFER_BIT);

    glActiveTexture(GL_TEXTURE0); // normal texture channel

    if(m_shaderactive)
    {
        glUniform1i(m_tex, 0); // good old textures: GL_TEXTURE0
        glUniform1i(m_normalMap, 1); // normal maps are GL_TEXTURE1
        glUniform1i(m_lightmap, 2); // lightmap

        if(m_useShadows)
        {
            glUniform1i(m_shadowMapUniform, 7);
            glActiveTexture(GL_TEXTURE7); // shadow mapping texture GL_TEXTURE7
            glBindTexture(GL_TEXTURE_2D, m_depthTextureId);
            glActiveTexture(GL_TEXTURE0);
        }

#ifdef DRAW_NORMALS
        glUseProgram(0); // use fixed pipeline for this debug mode
#endif
    }

    // Main drawing
    DrawScene(frustum, world, localctrlid, false);

    if(m_shaderactive)
        glUseProgram(0); // don't use shader for particles

    // Particle Draw
    glDisable(GL_LIGHTING);
    glDepthMask(false);
    for(iter=world->ObjBegin();iter!=world->ObjEnd();++iter)
    {
        obj = (*iter).second;

        if(obj->GetMesh())
        {
            // Animate mesh is done in the particle loop
            // and not in DrawScene, because DrawScene
            // can be called multiple times per frame
            obj->GetMesh()->Animate(obj->GetMeshState(), dt);
        }

        if(obj->GetID() == localctrlid || !obj->GetParticleSystem())
            continue;

        // Update/animate the particles, depending on dt and the current position.
        obj->GetParticleSystem()->Update(dt, ticks, obj->GetOrigin());

        // Draw the particles. FIXME: this should use a frustum test
        obj->GetParticleSystem()->Render(side, up, dir);
    }
    glDepthMask(true);
    glColor4f(1,1,1,1);
    glEnable(GL_LIGHTING);

#ifdef DRAW_NORMALS
    // Draw vertex normals of level geometry (not face normals)
    if(world && world->GetBSP())
    {
        glDisable(GL_DEPTH_TEST);
        glDisable(GL_LIGHTING);
        world->GetBSP()->RenderNormals();
        glEnable(GL_LIGHTING);
        glEnable(GL_DEPTH_TEST);
    }
#endif

    // Draw weapon
    if(m_shaderactive) // use shader for weapon
        glUseProgram(m_program);

    CModelMD5* viewmodel;
    md5_state_t* viewmodelstate;
    m_world->m_hud.GetModel(&viewmodel, &viewmodelstate);
    glDisable(GL_LIGHTING);
    if(viewmodel)
    {
        glClear(GL_DEPTH_BUFFER_BIT);
        glPushMatrix();
          glLoadIdentity();
          viewmodel->Render(viewmodelstate);
          viewmodel->Animate(viewmodelstate, dt);
        glPopMatrix();
    }
    glEnable(GL_LIGHTING);

    // Draw HUD
    if(m_shaderactive)
        glUseProgram(0); // no shader for HUD

    glDisable(GL_DEPTH_TEST);
    glDisable(GL_LIGHTING);
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0, m_width, m_height, 0, 0, 1);
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();
    glColor4f(1,1,1,1);
    glBindTexture(GL_TEXTURE_2D, m_crosshair);

    // Draw center crosshair
    glBegin(GL_QUADS);
        glTexCoord2d(0,1);
        glVertex3f((m_width-m_crosshair_width)*0.5f, (m_height-m_crosshair_height)*0.5f,0.0f);
        glTexCoord2d(0,0);
        glVertex3f((m_width-m_crosshair_width)*0.5f, (m_height+m_crosshair_height)*0.5f,0.0f);
        glTexCoord2d(1,0);
        glVertex3f((m_width+m_crosshair_width)*0.5f, (m_height+m_crosshair_height)*0.5f,0.0f);
        glTexCoord2d(1,1);
        glVertex3f((m_width+m_crosshair_width)*0.5f, (m_height-m_crosshair_height)*0.5f,0.0f);
    glEnd();

    // draw HUD text: score, health...
    char hudtextbuf[64];
    sprintf(hudtextbuf, "Frags: %i", m_world->m_hud.score);
    m_font.DrawGL(10.0f, m_height - 30.0f, 0.0f, hudtextbuf);
    sprintf(hudtextbuf, "%i", m_world->m_hud.health);
    m_font.DrawGL(10.0f, m_height - 35.0f - (float)m_font.GetHeight(), 0.0f, hudtextbuf);

#ifdef DRAW_SHADOWMAP // draw a small window with the scene from the light POV
    if(m_shaderactive)
    {
        //glBindTexture(GL_TEXTURE_2D, m_depthTextureId);
        glBindTexture(GL_TEXTURE_2D, g_fboShadowCamColor);
        const float shadowmap_debug_width = 200.0f;
        const float shadowmap_debug_height = shadowmap_debug_width*(float)m_height/(float)m_width;
        glBegin(GL_QUADS);
            glTexCoord2d(0,1); // upper left
            glVertex3f(0.0f, 0.0f, 0.0f);
            glTexCoord2d(0,0); //lower left
            glVertex3f(0.0f, shadowmap_debug_height, 0.0f);
            glTexCoord2d(1,0); //lower right
            glVertex3f(shadowmap_debug_width, shadowmap_debug_height, 0.0f);
            glTexCoord2d(1,1); // upper right
            glVertex3f(shadowmap_debug_width, 0.0f, 0.0f);
        glEnd();
    }
#endif

    glBindTexture(GL_TEXTURE_2D, 0);
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
    glEnable(GL_LIGHTING);
    glEnable(GL_DEPTH_TEST);
}
Exemple #29
0
vec3_t FillPlane::toPlane(vec3_t x)
{
  x -= m_X0;
  x -= (x*m_N)*m_N;
  return vec3_t(x*m_G1, x*m_G2, 0);
}
Exemple #30
0
void CBasePlayerWeapon :: DefaultFire( CBasePlayer *m_pPlayer, int cShots, wepspread_t spread, float damage, int anim, char *sound, int genevent, int RadOfBright )
{
	if (m_iClip <= 0)
	{
		PlayEmptySound();
		m_flNextPrimaryAttack = 0.15;
		return;
	}

	if( anim >= 0 )
		SendWeaponAnim( anim );

	m_pPlayer->SetAnimation( PLAYER_ATTACK1 ); 
	m_pPlayer->m_iWeaponFlash = NORMAL_GUN_FLASH;
	m_pPlayer->m_iWeaponVolume = NORMAL_GUN_VOLUME;
	m_pPlayer->pev->effects = (int)(m_pPlayer->pev->effects) | EF_MUZZLEFLASH;
	if( sound )
		EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_WEAPON, sound, 1.0, ATTN_NORM, 0, 100 );

	cShots = min( m_iClip, cShots );
	m_iClip -= cShots;

	Vector vecSrc( m_pPlayer->GetGunPosition() );
	Vector vecAim( m_pPlayer->GetAutoaimVector( AUTOAIM_2DEGREES ) );
	Vector vecAcc( g_vecZero );
	Vector vecDir;
	if( cShots != 1 )
		vecAcc = vec3_t( spread.SpreadX / 100, spread.SpreadY / 100, 0 );
	float spead = m_pPlayer->pev->velocity.Length();
	if( m_pPlayer->pev->velocity.Length() )
		vecAcc = vecAcc + vec3_t( spread.SpreadY / 5000, spread.SpreadY / 5000, 0 ) * m_pPlayer->pev->velocity.Length();
	if( iSlot() == 2 && cShots == 1 )
		vecAcc = vecAcc / 10;
	if ( !( m_pPlayer->pev->flags & FL_ONGROUND ) )
		vecAcc = vecAcc + vec3_t( spread.SpreadY / 5000, spread.SpreadY / 5000, 0 ) * 250;

	vecDir = m_pPlayer->FireBulletsPlayer( cShots, vecSrc, vecAim, vecAcc, 8192,0, 0, damage, m_pPlayer->pev, m_pPlayer->random_seed );

	MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSrc );

		WRITE_BYTE( TE_DLIGHT );

		WRITE_COORD( vecSrc.x );
		WRITE_COORD( vecSrc.y );
		WRITE_COORD( vecSrc.z );
		WRITE_BYTE( RadOfBright );

		WRITE_BYTE( 210 );
		WRITE_BYTE( 200 );
		WRITE_BYTE( 60 );

		WRITE_BYTE( 1 );
		WRITE_BYTE( 1 );

	MESSAGE_END();

	if( !LeftSpread )
		LeftSpread = 1;

	m_pPlayer->pev->punchangle.x -= RANDOM_FLOAT( spread.SpreadY / 2, spread.SpreadY );
	m_pPlayer->pev->punchangle.y += spread.SpreadX * RANDOM_LONG( -1, 1 ) / 2;

	if( m_pPlayer->pev->punchangle.x < -spread.MaxSpreadY )
	{
		m_pPlayer->pev->punchangle.x = -spread.MaxSpreadY + RANDOM_LONG( -2, 2 );
		m_pPlayer->pev->punchangle.y += spread.SpreadX * LeftSpread;
	}

	if( m_pPlayer->pev->punchangle.y <= -spread.MaxSpreadX )
		LeftSpread = 1;
	else if( m_pPlayer->pev->punchangle.y > spread.MaxSpreadX )
		LeftSpread = -1;

	PLAYBACK_EVENT_FULL( FEV_NOTHOST, m_pPlayer->edict(), genevent, 0.0,
		(float *)&g_vecZero, (float *)&g_vecZero,
		vecDir.x, vecDir.y, 0, 0, (m_iClip ? 0 : 1), 0 );
}