本文整理汇总了C++中float3类的典型用法代码示例。如果您正苦于以下问题:C++ float3类的具体用法?C++ float3怎么用?C++ float3使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了float3类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: CheckForCollision
void CHoverAirMoveType::UpdateAirPhysics()
{
float3& pos = owner->pos;
float3& speed = owner->speed;
if (!((gs->frameNum + owner->id) & 3)) {
CheckForCollision();
}
const float yspeed = speed.y;
speed.y = 0.0f;
const float3 delta = wantedSpeed - speed;
const float deltaDotSpeed = (speed != ZeroVector)? delta.dot(speed): 1.0f;
if (deltaDotSpeed == 0.0f) {
// we have the wanted speed
} else if (deltaDotSpeed > 0.0f) {
// accelerate
const float sqdl = delta.SqLength();
if (sqdl < Square(accRate)) {
speed = wantedSpeed;
} else {
speed += delta / math::sqrt(sqdl) * accRate;
}
} else {
// break
const float sqdl = delta.SqLength();
if (sqdl < Square(decRate)) {
speed = wantedSpeed;
} else {
speed += delta / math::sqrt(sqdl) * decRate;
}
}
float minH = 0.0f; // minimum altitude at (pos.x, pos.z)
float curH = 0.0f; // current altitude at (pos.x, pos.z)
if (UseSmoothMesh()) {
minH = owner->unitDef->canSubmerge?
smoothGround->GetHeight(pos.x, pos.z):
smoothGround->GetHeightAboveWater(pos.x, pos.z);
} else {
minH = owner->unitDef->canSubmerge?
ground->GetHeightReal(pos.x, pos.z):
ground->GetHeightAboveWater(pos.x, pos.z);
}
speed.y = yspeed;
pos.y = std::max(pos.y, minH);
curH = pos.y - minH;
if (curH < 4.0f) {
speed.x *= 0.95f;
speed.z *= 0.95f;
}
float wh = wantedHeight;
if (lastColWarningType == 2) {
const float3 dir = lastColWarning->midPos - owner->midPos;
const float3 sdir = lastColWarning->speed - speed;
if (speed.dot(dir + sdir * 20.0f) < 0.0f) {
if (lastColWarning->midPos.y > owner->pos.y) {
wh -= 30.0f;
} else {
wh += 50.0f;
}
}
}
float ws = 0.0f;
if (curH < wh) {
ws = altitudeRate;
if (speed.y > 0.0001f && (wh - curH) / speed.y * accRate * 1.5f < speed.y) {
ws = 0.0f;
}
} else {
ws = -altitudeRate;
if (speed.y < -0.0001f && (wh - curH) / speed.y * accRate * 0.7f < -speed.y) {
ws = 0.0f;
}
}
if (fabs(wh - curH) > 2.0f) {
if (speed.y > ws) {
speed.y = std::max(ws, speed.y - accRate * 1.5f);
} else if (!owner->beingBuilt) {
// let them accelerate upward faster if close to ground
speed.y = std::min(ws, speed.y + accRate * (curH < 20.0f? 2.0f: 0.7f));
}
} else {
speed.y = speed.y * 0.95;
}
if (modInfo.allowAirPlanesToLeaveMap || (pos + speed).CheckInBounds()) {
pos += speed;
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:
示例2: IsInPositiveDirection
bool Plane::IsInPositiveDirection(const float3 &directionVector) const
{
assume(directionVector.IsNormalized());
return normal.Dot(directionVector) >= 0.f;
}
开发者ID:Ilikia,项目名称:naali,代码行数:5,代码来源:Plane.cpp
示例3:
Plane::Plane(const Line &line, const float3 &normal)
{
float3 perpNormal = normal - normal.ProjectToNorm(line.dir);
Set(line.pos, perpNormal.Normalized());
}
开发者ID:Ilikia,项目名称:naali,代码行数:5,代码来源:Plane.cpp
示例4: CShieldPartProjectile
void CPlasmaRepulser::Update(void)
{
const int defHitFrames = weaponDef->visibleShieldHitFrames;
const bool couldBeVisible = (weaponDef->visibleShield || (defHitFrames > 0));
if (startShowingShield) {
startShowingShield = false;
if (couldBeVisible) {
// 32 parts
for (int y = 0; y < 16; y += 4) {
for (int x = 0; x < 32; x += 4) {
visibleShieldParts.push_back(
SAFE_NEW CShieldPartProjectile(owner->pos, x, y, radius,
weaponDef->shieldBadColor,
weaponDef->shieldAlpha,
weaponDef->visuals.texture1, owner)
);
}
}
}
}
if (isEnabled && (curPower < weaponDef->shieldPower)) {
if (owner->UseEnergy(weaponDef->shieldPowerRegenEnergy * (1.0f / 30.0f))) {
curPower += weaponDef->shieldPowerRegen * (1.0f / 30.0f);
}
}
weaponPos = owner->pos + (owner->frontdir * relWeaponPos.z)
+ (owner->updir * relWeaponPos.y)
+ (owner->rightdir * relWeaponPos.x);
if (couldBeVisible) {
float drawAlpha = 0.0f;
const int oldFrames = hitFrames;
if (hitFrames > 0) {
drawAlpha += float(hitFrames) / float(defHitFrames);
hitFrames--;
}
if ((isEnabled != wasEnabled) ||
(hitFrames != oldFrames) ||
(curPower != lastPower)) {
if (weaponDef->visibleShield) {
drawAlpha += 1.0f;
}
drawAlpha = min(1.0f, drawAlpha * weaponDef->shieldAlpha);
const float colorMix = min(1.0f, curPower / max(1.0f, weaponDef->shieldPower));
const float3 color = (weaponDef->shieldGoodColor * colorMix) +
(weaponDef->shieldBadColor * (1.0f - colorMix));
std::list<CShieldPartProjectile*>::iterator si;
for (si = visibleShieldParts.begin(); si != visibleShieldParts.end(); ++si) {
(*si)->centerPos = weaponPos;
(*si)->color = color;
if (isEnabled) {
(*si)->baseAlpha = drawAlpha;
} else {
(*si)->baseAlpha = 0.0f;
}
}
}
}
if (isEnabled) {
for (std::list<CWeaponProjectile*>::iterator pi=incoming.begin();pi!=incoming.end();++pi) {
const float3 dif = (*pi)->pos-owner->pos;
if ((*pi)->checkCol && dif.SqLength()<sqRadius && curPower > (*pi)->weaponDef->damages[0]) {
if (gs->Team(owner->team)->energy > weaponDef->shieldEnergyUse) {
if (weaponDef->shieldRepulser) {
// bounce the projectile
const int type = (*pi)->ShieldRepulse(this, weaponPos,
weaponDef->shieldForce,
weaponDef->shieldMaxSpeed);
if (type == 0) {
continue;
}
else if (type == 1) {
owner->UseEnergy(weaponDef->shieldEnergyUse);
if (weaponDef->shieldPower != 0) {
curPower -= (*pi)->weaponDef->damages[0];
}
}
else {
owner->UseEnergy(weaponDef->shieldEnergyUse / 30.0f);
if (weaponDef->shieldPower != 0) {
curPower -= (*pi)->weaponDef->damages[0] / 30.0f;
}
}
if (weaponDef->visibleShieldRepulse) {
if (hasGfx.find(*pi) == hasGfx.end()) {
hasGfx.insert(*pi);
const float colorMix = min(1.0f, curPower / max(1.0f, weaponDef->shieldPower));
const float3 color = (weaponDef->shieldGoodColor * colorMix) +
(weaponDef->shieldBadColor * (1.0f - colorMix));
SAFE_NEW CRepulseGfx(owner, *pi, radius, color);
}
}
if (defHitFrames > 0) {
//.........这里部分代码省略.........
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:101,代码来源:PlasmaRepulser.cpp
示例5: assert
/**
* @brief Causes this CMobileCAI to execute the attack order c
*/
void CMobileCAI::ExecuteAttack(Command &c)
{
assert(owner->unitDef->canAttack);
// limit how far away we fly
if (tempOrder && (owner->moveState < 2) && orderTarget
&& LinePointDist(ClosestPointOnLine(commandPos1, commandPos2, owner->pos),
commandPos2, orderTarget->pos)
> (500 * owner->moveState + owner->maxRange)) {
StopMove();
FinishCommand();
return;
}
// check if we are in direct command of attacker
if (!inCommand) {
// don't start counting until the owner->AttackGround() order is given
owner->commandShotCount = -1;
if (c.params.size() == 1) {
const int targetID = int(c.params[0]);
const bool legalTarget = (targetID >= 0 && targetID < MAX_UNITS);
CUnit* targetUnit = (legalTarget)? uh->units[targetID]: 0x0;
// check if we have valid target parameter and that we aren't attacking ourselves
if (legalTarget && targetUnit != 0x0 && targetUnit != owner) {
float3 fix = targetUnit->pos + owner->posErrorVector * 128;
float3 diff = float3(fix - owner->pos).Normalize();
if (owner->moveState > 0 || !tempOrder) {
SetGoal(fix - diff * targetUnit->radius, owner->pos);
}
orderTarget = targetUnit;
AddDeathDependence(orderTarget);
inCommand = true;
} else {
// unit may not fire on itself, cancel order
StopMove();
FinishCommand();
return;
}
}
else {
// user gave force-fire attack command
float3 pos(c.params[0], c.params[1], c.params[2]);
SetGoal(pos, owner->pos);
inCommand = true;
}
}
else if ((c.params.size() == 3) && (owner->commandShotCount > 0) && (commandQue.size() > 1)) {
// the trailing CMD_SET_WANTED_MAX_SPEED in a command pair does not count
if ((commandQue.size() > 2) || (commandQue.back().id != CMD_SET_WANTED_MAX_SPEED)) {
StopMove();
FinishCommand();
return;
}
}
// if our target is dead or we lost it then stop attacking
// NOTE: unit should actually just continue to target area!
if (targetDied || (c.params.size() == 1 && UpdateTargetLostTimer(int(c.params[0])) == 0)) {
// cancel keeppointingto
StopMove();
FinishCommand();
return;
}
// user clicked on enemy unit (note that we handle aircrafts slightly differently)
if (orderTarget) {
//bool b1 = owner->AttackUnit(orderTarget, c.id == CMD_DGUN);
bool b2 = false;
bool b3 = false;
bool b4 = false;
float edgeFactor = 0.f; // percent offset to target center
float3 diff = owner->pos - orderTarget->midPos;
if (owner->weapons.size() > 0) {
if (!(c.options & ALT_KEY) && SkipParalyzeTarget(orderTarget)) {
StopMove();
FinishCommand();
return;
}
CWeapon* w = owner->weapons.front();
// if we have at least one weapon then check if we
// can hit target with our first (meanest) one
b2 = w->TryTargetRotate(orderTarget, c.id == CMD_DGUN);
b3 = Square(w->range - (w->relWeaponPos).Length())
> (orderTarget->pos.SqDistance(owner->pos));
b4 = w->TryTargetHeading(GetHeadingFromVector(-diff.x, -diff.z),
orderTarget->pos, orderTarget != NULL);
edgeFactor = fabs(w->targetBorder);
}
double diffLength2d = diff.Length2D();
//.........这里部分代码省略.........
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:101,代码来源:MobileCAI.cpp
示例6: Explosion
void CBasicMapDamage::Explosion(const float3& pos, float strength, float radius)
{
if (!pos.IsInMap()) {
return;
}
if (strength < 10.0f || radius < 8.0f) {
return;
}
Explo* e = new Explo;
e->pos = pos;
e->strength = strength;
e->ttl = 10;
e->x1 = Clamp<int>((pos.x - radius) / SQUARE_SIZE, 1, mapDims.mapxm1);
e->x2 = Clamp<int>((pos.x + radius) / SQUARE_SIZE, 1, mapDims.mapxm1);
e->y1 = Clamp<int>((pos.z - radius) / SQUARE_SIZE, 1, mapDims.mapym1);
e->y2 = Clamp<int>((pos.z + radius) / SQUARE_SIZE, 1, mapDims.mapym1);
e->squares.reserve((e->y2 - e->y1 + 1) * (e->x2 - e->x1 + 1));
const float* curHeightMap = readMap->GetCornerHeightMapSynced();
const float* orgHeightMap = readMap->GetOriginalHeightMapSynced();
const unsigned char* typeMap = readMap->GetTypeMapSynced();
const float baseStrength = -math::pow(strength, 0.6f) * 3 / mapHardness;
const float invRadius = 1.0f / radius;
for (int y = e->y1; y <= e->y2; ++y) {
for (int x = e->x1; x <= e->x2; ++x) {
const CSolidObject* so = groundBlockingObjectMap->GroundBlockedUnsafe(y * mapDims.mapx + x);
// do not change squares with buildings on them here
if (so && so->blockHeightChanges) {
e->squares.push_back(0.0f);
continue;
}
// calculate the distance and normalize it
const float expDist = pos.distance2D(float3(x * SQUARE_SIZE, 0, y * SQUARE_SIZE));
const float relDist = std::min(1.0f, expDist * invRadius);
const unsigned int tableIdx = relDist * CRATER_TABLE_SIZE;
float dif = baseStrength;
dif *= craterTable[tableIdx];
dif *= invHardness[typeMap[(y / 2) * mapDims.hmapx + x / 2]];
// FIXME: compensate for flattened ground under dead buildings
const float prevDif =
curHeightMap[y * mapDims.mapxp1 + x] -
orgHeightMap[y * mapDims.mapxp1 + x];
if (prevDif * dif > 0.0f) {
dif /= math::fabs(prevDif) * 0.1f + 1;
}
e->squares.push_back(dif);
if (dif < -0.3f && strength > 200.0f) {
grassDrawer->RemoveGrass(float3(x * SQUARE_SIZE, 0.0f, y * SQUARE_SIZE));
}
}
}
// calculate how much to offset the buildings in the explosion radius with
// (while still keeping the ground below them flat)
const std::vector<CUnit*>& units = quadField->GetUnitsExact(pos, radius);
for (const CUnit* unit: units) {
if (!unit->blockHeightChanges) { continue; }
if (!unit->IsBlocking()) { continue; }
float totalDif = 0.0f;
for (int z = unit->mapPos.y; z < unit->mapPos.y + unit->zsize; z++) {
for (int x = unit->mapPos.x; x < unit->mapPos.x + unit->xsize; x++) {
// calculate the distance and normalize it
const float expDist = pos.distance2D(float3(x * SQUARE_SIZE, 0, z * SQUARE_SIZE));
const float relDist = std::min(1.0f, expDist * invRadius);
const unsigned int tableIdx = relDist * CRATER_TABLE_SIZE;
float dif =
baseStrength * craterTable[tableIdx] *
invHardness[typeMap[(z / 2) * mapDims.hmapx + x / 2]];
const float prevDif =
curHeightMap[z * mapDims.mapxp1 + x] -
orgHeightMap[z * mapDims.mapxp1 + x];
if (prevDif * dif > 0.0f) {
dif /= math::fabs(prevDif) * 0.1f + 1;
}
totalDif += dif;
}
}
totalDif /= (unit->xsize * unit->zsize);
if (totalDif != 0.0f) {
ExploBuilding eb;
eb.id = unit->id;
eb.dif = totalDif;
eb.tx1 = unit->mapPos.x;
eb.tx2 = unit->mapPos.x + unit->xsize;
//.........这里部分代码省略.........
开发者ID:amitamitamitamit,项目名称:spring,代码行数:101,代码来源:BasicMapDamage.cpp
示例7: targSpeed
void CMissileProjectile::Update()
{
if (--ttl > 0) {
if (!luaMoveCtrl) {
if (curSpeed < maxSpeed) {
curSpeed += weaponDef->weaponacceleration;
}
float3 targSpeed(ZeroVector);
if (weaponDef->tracks && target) {
CSolidObject* so = dynamic_cast<CSolidObject*>(target);
CWeaponProjectile* po = dynamic_cast<CWeaponProjectile*>(target);
targetPos = target->pos;
if (so) {
targetPos = so->aimPos;
targSpeed = so->speed;
if (owner()) {
CUnit* u = dynamic_cast<CUnit*>(so);
if (u) {
targetPos = CGameHelper::GetUnitErrorPos(u, owner()->allyteam, true);
}
}
} if (po) {
targSpeed = po->speed;
}
}
if (isWobbling) {
--wobbleTime;
if (wobbleTime == 0) {
float3 newWob = gs->randVector();
wobbleDif = (newWob - wobbleDir) * (1.0f / 16);
wobbleTime = 16;
}
wobbleDir += wobbleDif;
dir += wobbleDir * weaponDef->wobble * (owner()? (1.0f - owner()->limExperience * 0.5f): 1);
dir.Normalize();
}
if (isDancing) {
--danceTime;
if (danceTime <= 0) {
danceMove = gs->randVector() * weaponDef->dance - danceCenter;
danceCenter += danceMove;
danceTime = 8;
}
pos += danceMove;
}
const float3 orgTargPos = targetPos;
const float3 targetDir = (targetPos - pos).SafeNormalize();
const float dist = pos.distance(targetPos) + 0.1f;
if (extraHeightTime > 0) {
extraHeight -= extraHeightDecay;
--extraHeightTime;
targetPos.y += extraHeight;
if (dir.y <= 0.0f) {
// missile has reached apex, smoothly transition
// to targetDir (can still overshoot when target
// is too close or height difference too large)
const float horDiff = (targetPos - pos).Length2D() + 0.01f;
const float verDiff = (targetPos.y - pos.y) + 0.01f;
const float dirDiff = math::fabs(targetDir.y - dir.y);
const float ratio = math::fabs(verDiff / horDiff);
dir.y -= (dirDiff * ratio);
} else {
// missile is still ascending
dir.y -= (extraHeightDecay / dist);
}
}
float3 dif = (targetPos + targSpeed * (dist / maxSpeed) * 0.7f - pos).SafeNormalize();
float3 dif2 = dif - dir;
if (dif2.SqLength() < Square(weaponDef->turnrate)) {
dir = dif;
} else {
dif2 -= (dir * (dif2.dot(dir)));
dif2.SafeNormalize();
dir += (dif2 * weaponDef->turnrate);
dir.SafeNormalize();
}
targetPos = orgTargPos;
speed = dir * curSpeed;
}
gCEG->Explosion(cegID, pos, ttl, areaOfEffect, NULL, 0.0f, NULL, dir);
//.........这里部分代码省略.........
开发者ID:AlexDiede,项目名称:spring,代码行数:101,代码来源:MissileProjectile.cpp
示例8: glActiveTexture
void CAdvTreeDrawer::DrawShadowPass()
{
const float treeDistance = oldTreeDistance;
const int activeFarTex = (camera->forward.z < 0.0f)? treeGen->farTex[0] : treeGen->farTex[1];
const bool drawDetailed = (treeDistance >= 4.0f);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, activeFarTex);
glEnable(GL_TEXTURE_2D);
glEnable(GL_ALPHA_TEST);
glDisable(GL_CULL_FACE);
glPolygonOffset(1, 1);
glEnable(GL_POLYGON_OFFSET_FILL);
CAdvTreeSquareDrawer_SP drawer;
const int cx = drawer.cx = (int)(camera->pos.x / (SQUARE_SIZE * TREE_SQUARE_SIZE));
const int cy = drawer.cy = (int)(camera->pos.z / (SQUARE_SIZE * TREE_SQUARE_SIZE));
drawer.drawDetailed = drawDetailed;
drawer.td = this;
drawer.treeDistance = treeDistance * SQUARE_SIZE * TREE_SQUARE_SIZE;
Shader::IProgramObject* po = NULL;
GML_STDMUTEX_LOCK(tree); // DrawShadowPass
// draw with extraSize=1
readmap->GridVisibility(camera, TREE_SQUARE_SIZE, drawer.treeDistance * 2.0f, &drawer, 1);
if (drawDetailed) {
const int xstart = std::max( 0, cx - 2);
const int xend = std::min(gs->mapx / TREE_SQUARE_SIZE - 1, cx + 2);
const int ystart = std::max( 0, cy - 2);
const int yend = std::min(gs->mapy / TREE_SQUARE_SIZE - 1, cy + 2);
glBindTexture(GL_TEXTURE_2D, treeGen->barkTex);
glEnable(GL_TEXTURE_2D);
po = shadowHandler->GetShadowGenProg(CShadowHandler::SHADOWGEN_PROGRAM_TREE_NEAR);
po->Enable();
if (globalRendering->haveGLSL) {
po->SetUniform3fv(1, &camera->right[0]);
po->SetUniform3fv(2, &camera->up[0]);
} else {
po->SetUniformTarget(GL_VERTEX_PROGRAM_ARB);
po->SetUniform4f(13, camera->right.x, camera->right.y, camera->right.z, 0.0f);
po->SetUniform4f(9, camera->up.x, camera->up.y, camera->up.z, 0.0f);
po->SetUniform4f(11, 1.0f, 1.0f, 1.0f, 0.85f );
po->SetUniform4f(12, 0.0f, 0.0f, 0.0f, 0.20f * (1.0f / MAX_TREE_HEIGHT)); // w = alpha/height modifier
}
glAlphaFunc(GL_GREATER, 0.5f);
glEnable(GL_ALPHA_TEST);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
CVertexArray* va = GetVertexArray();
va->Initialize();
static FadeTree fadeTrees[3000];
FadeTree* pFT = fadeTrees;
for (TreeSquareStruct* pTSS = trees + (ystart * treesX); pTSS <= trees + (yend * treesX); pTSS += treesX) {
for (TreeSquareStruct* tss = pTSS + xstart; tss <= pTSS + xend; ++tss) {
tss->lastSeen = gs->frameNum;
va->EnlargeArrays(12 * tss->trees.size(), 0, VA_SIZE_T); //!alloc room for all tree vertexes
for (std::map<int, TreeStruct>::iterator ti = tss->trees.begin(); ti != tss->trees.end(); ++ti) {
const TreeStruct* ts = &ti->second;
const float3 pos(ts->pos);
if (!camera->InView(pos + float3(0, MAX_TREE_HEIGHT / 2, 0), MAX_TREE_HEIGHT / 2 + 150)) {
continue;
}
const float camDist = (pos - camera->pos).SqLength();
int type = ts->type;
float dy = 0.0f;
unsigned int dispList;
if (type < 8) {
dy = 0.5f;
dispList = treeGen->pineDL + type;
} else {
type -= 8;
dy = 0;
dispList = treeGen->leafDL + type;
}
if (camDist < SQUARE_SIZE * SQUARE_SIZE * 110 * 110) {
po->SetUniform3f((globalRendering->haveGLSL? 3: 10), pos.x, pos.y, pos.z);
glCallList(dispList);
} else if (camDist < SQUARE_SIZE * SQUARE_SIZE * 125 * 125) {
const float relDist = (pos.distance(camera->pos) - SQUARE_SIZE * 110) / (SQUARE_SIZE * 15);
glAlphaFunc(GL_GREATER, 0.8f + relDist * 0.2f);
po->SetUniform3f((globalRendering->haveGLSL? 3: 10), pos.x, pos.y, pos.z);
glCallList(dispList);
glAlphaFunc(GL_GREATER, 0.5f);
//.........这里部分代码省略.........
开发者ID:DarksidedStudios,项目名称:spring,代码行数:101,代码来源:AdvTreeDrawer.cpp
示例9: ALVecToVec
float3 ALVecToVec(float3 const & v)
{
return float3(v.x(), v.y(), -v.z());
}
开发者ID:zsnake1209,项目名称:KlayGE,代码行数:4,代码来源:OALAudioEngine.cpp
示例10: Initialize
void CFeature::Initialize(const float3& _pos, const FeatureDef* _def, short int _heading,
int facing, int _team, int _allyteam, const UnitDef* _udef, const float3& speed, int _smokeTime)
{
def = _def;
udef = _udef;
defID = def->id;
heading = _heading;
buildFacing = facing;
team = _team;
allyteam = _allyteam;
emitSmokeTime = _smokeTime;
mass = def->mass;
crushResistance = def->crushResistance;
health = def->maxHealth;
blocking = def->blocking;
xsize = ((facing & 1) == 0) ? def->xsize : def->zsize;
zsize = ((facing & 1) == 1) ? def->xsize : def->zsize;
noSelect = def->noSelect;
if (def->drawType == DRAWTYPE_MODEL) {
if ((model = def->LoadModel()) == NULL) {
LOG_L(L_ERROR, "Features: Couldn't load model for %s", def->name.c_str());
} else {
SetMidAndAimPos(model->relMidPos, model->relMidPos, true);
SetRadiusAndHeight(model->radius, model->height);
}
} else {
if (def->drawType >= DRAWTYPE_TREE) {
// LoadFeaturesFromMap() doesn't set a scale for trees
SetMidAndAimPos(UpVector * TREE_RADIUS, UpVector * TREE_RADIUS, true);
SetRadiusAndHeight(TREE_RADIUS, TREE_RADIUS * 2.0f);
}
}
// note: gets deleted in ~CSolidObject
collisionVolume = new CollisionVolume(def->collisionVolume, radius);
Move3D(_pos.cClampInMap(), false);
UpdateMidAndAimPos();
CalculateTransform();
featureHandler->AddFeature(this);
qf->AddFeature(this);
// maybe should not be here, but it prevents crashes caused by team = -1
ChangeTeam(team);
if (blocking) {
Block();
}
if (def->floating) {
finalHeight = ground->GetHeightAboveWater(pos.x, pos.z);
} else {
finalHeight = ground->GetHeightReal(pos.x, pos.z);
}
if (speed != ZeroVector) {
deathSpeed = speed;
}
reachedFinalPos = (speed == ZeroVector && pos.y == finalHeight);
}
开发者ID:Finkky,项目名称:spring,代码行数:67,代码来源:Feature.cpp
示例11: glEnable
//.........这里部分代码省略.........
if (globalRendering->haveGLSL) {
treeShader->SetUniform3fv(0, &camera->right[0]);
treeShader->SetUniform3fv(1, &camera->up[0]);
treeShader->SetUniform2f(5, 0.20f * (1.0f / MAX_TREE_HEIGHT), 0.85f);
} else {
treeShader->SetUniformTarget(GL_VERTEX_PROGRAM_ARB);
treeShader->SetUniform3f(13, camera->right.x, camera->right.y, camera->right.z);
treeShader->SetUniform3f( 9, camera->up.x, camera->up.y, camera->up.z );
treeShader->SetUniform4f(11, light.groundSunColor.x, light.groundSunColor.y, light.groundSunColor.z, 0.85f);
treeShader->SetUniform4f(14, light.groundAmbientColor.x, light.groundAmbientColor.y, light.groundAmbientColor.z, 0.85f);
treeShader->SetUniform4f(12, 0.0f, 0.0f, 0.0f, 0.20f * (1.0f / MAX_TREE_HEIGHT)); // w = alpha/height modifier
}
glAlphaFunc(GL_GREATER, 0.5f);
glDisable(GL_BLEND);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
CVertexArray* va = GetVertexArray();
va->Initialize();
static FadeTree fadeTrees[3000];
FadeTree* pFT = fadeTrees;
for (TreeSquareStruct* pTSS = trees + (ystart * treesX); pTSS <= trees + (yend * treesX); pTSS += treesX) {
for (TreeSquareStruct* tss = pTSS + xstart; tss <= (pTSS + xend); ++tss) {
tss->lastSeen = gs->frameNum;
va->EnlargeArrays(12 * tss->trees.size(), 0, VA_SIZE_T); //!alloc room for all tree vertexes
for (std::map<int, TreeStruct>::iterator ti = tss->trees.begin(); ti != tss->trees.end(); ++ti) {
const TreeStruct* ts = &ti->second;
const float3 pos(ts->pos);
if (!camera->InView(pos + float3(0.0f, MAX_TREE_HEIGHT / 2.0f, 0.0f), MAX_TREE_HEIGHT / 2.0f)) {
continue;
}
const float camDist = (pos - camera->pos).SqLength();
int type = ts->type;
float dy = 0.0f;
unsigned int dispList;
if (type < 8) {
dy = 0.5f;
dispList = treeGen->pineDL + type;
} else {
type -= 8;
dy = 0.0f;
dispList = treeGen->leafDL + type;
}
if (camDist < (SQUARE_SIZE * SQUARE_SIZE * 110 * 110)) {
// draw detailed near-distance tree (same as mid-distance trees without alpha)
treeShader->SetUniform3f(((globalRendering->haveGLSL)? 2: 10), pos.x, pos.y, pos.z);
glCallList(dispList);
} else if (camDist < (SQUARE_SIZE * SQUARE_SIZE * 125 * 125)) {
// draw mid-distance tree
const float relDist = (pos.distance(camera->pos) - SQUARE_SIZE * 110) / (SQUARE_SIZE * 15);
treeShader->SetUniform3f(((globalRendering->haveGLSL)? 2: 10), pos.x, pos.y, pos.z);
glAlphaFunc(GL_GREATER, 0.8f + relDist * 0.2f);
glCallList(dispList);
glAlphaFunc(GL_GREATER, 0.5f);
开发者ID:DarksidedStudios,项目名称:spring,代码行数:67,代码来源:AdvTreeDrawer.cpp
示例12: FireInternal
void CBeamLaser::FireInternal(float3 dir, bool sweepFire)
{
float rangeMod = 1.0f;
if (dynamic_cast<CBuilding*>(owner) == NULL) {
// help units fire while chasing
rangeMod = 1.3f;
}
if (owner->directControl) {
rangeMod = 0.95f;
}
float maxLength = range * rangeMod;
float curLength = 0.0f;
float3 curPos = weaponMuzzlePos;
float3 hitPos;
dir += gs->randVector() * sprayAngle * (1 - owner->limExperience * 0.7f);
dir.ANormalize();
bool tryAgain = true;
// unit at the end of the beam
CUnit* hit = 0;
// increase range if targets are searched for in a cylinder
if (cylinderTargetting > 0.01f) {
// const float3 up(0, owner->radius*cylinderTargetting, 0);
// const float uplen = up.dot(dir);
const float uplen = owner->radius * cylinderTargetting * dir.y;
maxLength = streflop::sqrtf(maxLength * maxLength + uplen * uplen);
}
// increase range if targetting edge of hitsphere
if (targetType == Target_Unit && targetUnit && targetBorder != 0) {
maxLength += targetUnit->radius * targetBorder;
}
for (int tries = 0; tries < 5 && tryAgain; ++tries) {
tryAgain = false;
hit = 0;
float length = helper->TraceRay(
curPos,
dir,
maxLength - curLength,
weaponDef->damages[0],
owner,
hit,
collisionFlags
);
if (hit && hit->allyteam == owner->allyteam && sweepFire) {
// never damage friendlies with sweepfire
lastFireFrame = 0;
return;
}
float3 newDir;
CPlasmaRepulser* shieldHit = 0;
const float shieldLength = interceptHandler.AddShieldInterceptableBeam(this, curPos, dir, length, newDir, shieldHit);
if (shieldLength < length) {
length = shieldLength;
if (shieldHit->BeamIntercepted(this, damageMul)) {
// repulsed
tryAgain = true;
}
}
hitPos = curPos + dir * length;
const float baseAlpha = weaponDef->intensity * 255.0f;
const float startAlpha = (1.0f - (curLength ) / (range * 1.3f)) * baseAlpha;
const float endAlpha = (1.0f - (curLength + length) / (range * 1.3f)) * baseAlpha;
if (weaponDef->largeBeamLaser) {
new CLargeBeamLaserProjectile(curPos, hitPos, color, weaponDef->visuals.color2, owner, weaponDef);
} else {
new CBeamLaserProjectile(
curPos, hitPos,
startAlpha, endAlpha,
color, weaponDef->visuals.color2,
owner,
weaponDef->thickness,
weaponDef->corethickness,
weaponDef->laserflaresize,
weaponDef,
weaponDef->visuals.beamttl,
weaponDef->visuals.beamdecay
);
}
curPos = hitPos;
curLength += length;
dir = newDir;
}
//.........这里部分代码省略.........
开发者ID:SocietalEclipse,项目名称:spring-Societal,代码行数:101,代码来源:BeamLaser.cpp
示例13: IsDegenerate
bool Triangle::IsDegenerate(const float3 &a, const float3 &b, const float3 &c, float epsilon)
{
return a.Equals(b, epsilon) || a.Equals(c, epsilon) || b.Equals(c, epsilon);
}
开发者ID:d0n3val,项目名称:Edu-Game-Engine,代码行数:4,代码来源:Triangle.cpp
示例14: ExecuteStop
bool CHoverAirMoveType::Update()
{
float3& pos = owner->pos;
float3& speed = owner->speed;
AAirMoveType::Update();
if (owner->stunned || owner->beingBuilt) {
wantedSpeed = ZeroVector;
wantToStop = true;
}
// Allow us to stop if wanted
if (wantToStop) {
ExecuteStop();
}
const float3 lastSpeed = speed;
if (owner->fpsControlPlayer != NULL) {
SetState(AIRCRAFT_FLYING);
const FPSUnitController& con = owner->fpsControlPlayer->fpsController;
const float3 forward = con.viewDir;
const float3 right = forward.cross(UpVector);
const float3 nextPos = pos + speed;
float3 flatForward = forward;
flatForward.y = 0.0f;
flatForward.Normalize();
wantedSpeed = ZeroVector;
if (con.forward) wantedSpeed += flatForward;
if (con.back ) wantedSpeed -= flatForward;
if (con.right ) wantedSpeed += right;
if (con.left ) wantedSpeed -= right;
wantedSpeed.Normalize();
wantedSpeed *= maxSpeed;
if (!nextPos.IsInBounds()) {
speed = ZeroVector;
}
UpdateAirPhysics();
wantedHeading = GetHeadingFromVector(flatForward.x, flatForward.z);
} else {
if (reservedPad != NULL) {
MoveToRepairPad();
if (padStatus >= 1) {
flyState = FLY_LANDING;
}
}
// Main state handling
switch (aircraftState) {
case AIRCRAFT_LANDED:
UpdateLanded();
break;
case AIRCRAFT_TAKEOFF:
UpdateTakeoff();
break;
case AIRCRAFT_FLYING:
UpdateFlying();
break;
case AIRCRAFT_LANDING:
UpdateLanding();
break;
case AIRCRAFT_HOVERING:
UpdateHovering();
break;
case AIRCRAFT_CRASHING:
break;
}
}
// Banking requires deltaSpeed.y = 0
deltaSpeed = speed - lastSpeed;
deltaSpeed.y = 0.0f;
// Turn and bank and move; update dirs
UpdateHeading();
UpdateBanking(aircraftState == AIRCRAFT_HOVERING);
return (HandleCollisions());
}
开发者ID:,项目名称:,代码行数:90,代码来源:
示例15: AddExplosion
void CGroundDecalHandler::AddExplosion(float3 pos, float damage, float radius)
{
if(decalLevel==0)
return;
float height=pos.y-ground->GetHeight2(pos.x,pos.z);
if(height>=radius)
return;
pos.y-=height;
radius-=height;
if(radius<5)
return;
if(damage>radius*30)
damage=radius*30;
damage*=(radius)/(radius+height);
if(radius>damage*0.25)
radius=damage*0.25;
if(damage>400)
damage=400+sqrt(damage-399);
pos.CheckInBounds();
Scar* s=new Scar;
s->pos=pos;
s->radius=radius*1.4;
s->creationTime=gs->frameNum;
s->startAlpha=max(50.f,min(255.f,damage));
float lifeTime=decalLevel*(damage)*3;
s->alphaFalloff=s->startAlpha/(lifeTime);
s->lifeTime=(int)(gs->frameNum+lifeTime);
s->texOffsetX=(gu->usRandInt()&128)?0:0.5f;
s->texOffsetY=(gu->usRandInt()&128)?0:0.5f;
s->x1=(int)max(0.f,(pos.x-radius)/16.0f);
s->x2=(int)min(float(gs->hmapx-1),(pos.x+radius)/16.0f+1);
s->y1=(int)max(0.f,(pos.z-radius)/16.0f);
s->y2=(int)min(float(gs->hmapy-1),(pos.z+radius)/16.0f+1);
s->basesize=(s->x2-s->x1)*(s->y2-s->y1);
s->overdrawn=0;
s->lastTest=0;
TestOverlaps(s);
int x1=s->x1/16;
int x2=min(scarFieldX-1,s->x2/16);
int y1=s->y1/16;
int y2=min(scarFieldY-1,s->y2/16);
for(int y=y1;y<=y2;++y){
for(int x=x1;x<=x2;++x){
std::set<Scar*>* quad=&scarField[y*scarFieldX+x];
quad->insert(s);
}
}
scars.push_back(s);
}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:63,代码来源:GroundDecalHandler.cpp
示例16: CShieldPartProjectile
void CPlasmaRepulser::Update(void)
{
const int defHitFrames = weaponDef->visibleShieldHitFrames;
const bool couldBeVisible = (weaponDef->visibleShield || (defHitFrames > 0));
const int defRechargeDelay = weaponDef->shieldRechargeDelay;
rechargeDelay -= (rechargeDelay > 0) ? 1 : 0;
if (startShowingShield) {
// one-time iteration when shield first goes online
// (adds the projectile parts, this assumes owner is
// not mobile)
startShowingShield = false;
if (couldBeVisible) {
// 32 parts
for (int y = 0; y < 16; y += 4) {
for (int x = 0; x < 32; x += 4) {
visibleShieldParts.push_back(
new CShieldPartProjectile(owner->pos, x, y, radius,
weaponDef->shieldBadColor,
weaponDef->shieldAlpha,
weaponDef->visuals.texture1, owner)
);
}
}
}
}
if (isEnabled && (curPower < weaponDef->shieldPower) && rechargeDelay <= 0) {
if (owner->UseEnergy(weaponDef->shieldPowerRegenEnergy * (1.0f / 30.0f))) {
curPower += weaponDef->shieldPowerRegen * (1.0f / 30.0f);
}
}
weaponPos = owner->pos + (owner->frontdir * relWeaponPos.z)
+ (owner->updir * relWeaponPos.y)
+ (owner->rightdir * relWeaponPos.x);
if (couldBeVisible) {
float drawAlpha = 0.0f;
if (hitFrames > 0) {
drawAlpha += float(hitFrames) / float(defHitFrames);
hitFrames--;
}
if (weaponDef->visibleShield) {
drawAlpha += 1.0f;
}
drawAlpha = std::min(1.0f, drawAlpha * weaponDef->shieldAlpha);
const bool drawMe = (drawAlpha > 0.0f);
if (drawMe || wasDrawn) {
const float colorMix = std::min(1.0f, curPower / std::max(1.0f, weaponDef->shieldPower));
const float3 color = (weaponDef->shieldGoodColor * colorMix) +
(weaponDef->shieldBadColor * (1.0f - colorMix));
std::list<CShieldPartProjectile*>::iterator si;
for (si = visibleShieldParts.begin(); si != visibleShieldParts.end(); ++si) {
CShieldPartProjectile* part = *si;
part->centerPos = weaponPos;
part->color = color;
if (isEnabled) {
part->baseAlpha = drawAlpha;
} else {
part->baseAlpha = 0.0f;
}
}
}
wasDrawn = drawMe;
}
if (isEnabled) {
for (std::list<CWeaponProjectile*>::iterator pi=incoming.begin();pi!=incoming.end();++pi) {
const float3 dif = (*pi)->pos-owner->pos;
if ((*pi)->checkCol && dif.SqLength()<sqRadius && curPower > (*pi)->weaponDef->damages[0]) {
if (teamHandler->Team(owner->team)->energy > weaponDef->shieldEnergyUse) {
rechargeDelay = defRechargeDelay;
if (weaponDef->shieldRepulser) {
// bounce the projectile
const int type = (*pi)->ShieldRepulse(this, weaponPos,
weaponDef->shieldForce,
weaponDef->shieldMaxSpeed);
if (type == 0) {
continue;
}
else if (type == 1) {
owner->UseEnergy(weaponDef->shieldEnergyUse);
if (weaponDef->shieldPower != 0) {
curPower -= (*pi)->weaponDef->damages[0];
}
}
else {
owner->UseEnergy(weaponDef->shieldEnergyUse / 30.0f);
if (weaponDef->shieldPower != 0) {
curPower -= (*pi)->weaponDef->damages[0] / 30.0f;
}
}
if (weaponDef->visibleShieldRepulse) {
std::list<CWeaponProjectile*>::iterator i;
for (i=hasGfx.begin();i!=hasGfx.end();i++)
if (*i==*pi) {
break;
//.........这里部分代码省略.........
开发者ID:achoum,项目名称:spring,代码行数:101,代码来源:PlasmaRepulser.cpp
示例17: IntersectLineAABB_CPP
bool AABB::IntersectLineAABB_CPP(const float3 &linePos, const float3 &lineDir, float &tNear, float &tFar) const
{
assume2(lineDir.IsNormalized(), lineDir, lineDir.LengthSq());
assume2(tNear <= tFar && "AABB::IntersectLineAABB: User gave a degenerate line as input for the intersection test!", tNear, tFar);
// The user should have inputted values for tNear and tFar to specify the desired subrange [tNear, tFar] of the line
// for this intersection test.
// For a Line-AABB test, pass in
// tNear = -FLOAT_INF;
// tFar = FLOAT_INF;
// For a Ray-AABB test, pass in
// tNear = 0.f;
// tFar = FLOAT_INF;
// For a LineSegment-AABB test, pass in
// tNear = 0.f;
// tFar = LineSegment.Length();
// Test each cardinal plane (X, Y and Z) in turn.
if (!EqualAbs(lineDir.x, 0.f))
{
float recipDir = RecipFast(lineDir.x);
float t1 = (minPoint.x - linePos.x) * recipDir;
float t2 = (maxPoint.x - linePos.x) * recipDir;
// tNear tracks distance to intersect (enter) the AABB.
// tFar tracks the distance to exit the AABB.
if (t1 < t2)
tNear = Max(t1, tNear), tFar = Min(t2, tFar);
else // Swap t1 and t2.
tNear = Max(t2, tNear), tFar = Min(t1, tFar);
if (tNear > tFar)
return false; // Box is missed since we "exit" before entering it.
}
else if (linePos.x < minPoint.x || linePos.x > maxPoint.x)
return false; // The ray can't possibly enter the box, abort.
if (!EqualAbs(lineDir.y, 0.f))
{
float recipDir = RecipFast(lineDir.y);
float t1 = (minPoint.y - linePos.y) * recipDir;
float t2 = (maxPoint.y - linePos.y) * recipDir;
if (t1 < t2)
tNear = Max(t1, tNear), tFar = Min(t2, tFar);
else // Swap t1 and t2.
tNear = Max(t2, tNear), tFar = Min(t1, tFar);
if (tNear > tFar)
return false; // Box is missed since we "exit" before entering it.
}
else if (linePos.y < minPoint.y || linePos.y > maxPoint.y)
return false; // The ray can't possibly enter the box, abort.
if (!EqualAbs(lineDir.z, 0.f)) // ray is parallel to plane in question
{
float recipDir = RecipFast(lineDir.z);
float t1 = (minPoint.z - linePos.z) * recipDir;
float t2 = (maxPoint.z - linePos.z) * recipDir;
if (t1 < t2)
tNear = Max(t1, tNear), tFar = Min(t2, tFar);
else // Swap t1 and t2.
tNear = Max(t2, tNear), tFar = Min(t1, tFar);
}
else if (linePos.z < minPoint.z || linePos.z > maxPoint.z)
return false; // The ray can't possibly enter the box, abort.
return tNear <= tFar;
}
开发者ID:chengzg,项目名称:MathGeoLib,代码行数:69,代码来源:AABB.cpp
示例18: Update
void CInterceptHandler::Update(bool forced) {
if (((gs->frameNum % UNIT_SLOWUPDATE_RATE) != 0) && !forced)
return;
std::list<CWeapon*>::iterator wit;
std::map<int, CWeaponProjectile*>::const_iterator pit;
for (wit = interceptors.begin(); wit != interceptors.end(); ++wit) {
CWeapon* w = *wit;
const WeaponDef* wDef = w->weaponDef;
const CUnit* wOwner = w->owner;
// const float3& wOwnerPos = wOwner->pos;
const float3& wPos = w->weaponPos;
for (pit = interceptables.begin(); pit != interceptables.end(); ++pit) {
CWeaponProjectile* p = pit->second;
const WeaponDef* pDef = p->weaponDef;
if ((pDef->targetable & wDef->interceptor) == 0)
continue;
if (w->incomingProjectiles.find(p->id) != w->incomingProjectiles.end())
continue;
const CUnit* pOwner = p->owner();
const int pAllyTeam = (pOwner != NULL)? pOwner->allyteam: -1;
if (pAllyTeam != -1 && teamHandler->Ally(wOwner->allyteam, pAllyTeam))
continue;
// there are four cases when an interceptor <w> should fire at a projectile <p>:
// 1. p's target position inside w's interception circle (w's owner can move!)
// 2. p's current position inside w's interception circle
// 3. p's projected impact position inside w's interception circle
// 4. p's trajectory intersects w's interception circle
//
// these checks all need to be evaluated periodically, not just
// when a projectile is created and handed to AddInterceptTarget
const float interceptDist = (w->weaponPos - p->pos).Length();
const float impactDist = ground->LineGroundCol(p->pos, p->pos + p->dir * interceptDist);
const float3& pFlightPos = p->pos;
const float3& pImpactPos = p->pos + p->dir * impactDist;
const float3& pTarget
|
请发表评论