本文整理汇总了C++中float3::Length方法的典型用法代码示例。如果您正苦于以下问题:C++ float3::Length方法的具体用法?C++ float3::Length怎么用?C++ float3::Length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类float3
的用法示例。
在下文中一共展示了float3::Length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CProjectile
CFireProjectile::CFireProjectile(const float3& pos,const float3& speed,CUnit* owner,int emitTtl,float emitRadius,int particleTtl,float particleSize)
: CProjectile(pos,speed,owner),
ttl(emitTtl),
emitPos(pos),
emitRadius(emitRadius),
particleTime(particleTtl),
particleSize(particleSize)
{
drawRadius=emitRadius+particleTime*speed.Length();
checkCol=false;
this->pos.y+=particleTime*speed.Length()*0.5;
ageSpeed=1.0/particleTime;
alwaysVisible=true;
castShadow=true;
}
示例2: GetCamDistOfGrassBlock
static float GetCamDistOfGrassBlock(const int x, const int y, const bool square = false)
{
float3 quadCenter = float3(x, 0.f, y) * gSSsq;
quadCenter.y = CGround::GetHeightReal(quadCenter.x, quadCenter.z, false);
const float3 dif = camera->GetPos() - quadCenter;
return (square) ? dif.SqLength() : dif.Length();
}
示例3: FitThroughPoints
/** For reference, see http://realtimecollisiondetection.net/blog/?p=20 . */
Sphere Sphere::FitThroughPoints(const float3 &a, const float3 &b, const float3 &c)
{
Sphere sphere;
float3 ab = b-a;
float3 ac = c-a;
float s, t;
bool success = FitSphereThroughPoints(ab, ac, s, t);
if (!success)
{
LOGW("Sphere::FitThroughPoints(a,b,c) failed! The three input points are collinear!");
sphere.SetDegenerate();
return sphere;
}
const float3 p = s*ab + t*ac;
// In our translated coordinate space, the origin lies on the sphere, so the distance of p from origin
// gives the radius of the sphere.
sphere.r = p.Length();
// Translate back to original coordinate space.
sphere.pos = a + p;
return sphere;
}
示例4: CWeaponProjectile
CTorpedoProjectile::CTorpedoProjectile(
const float3& pos, const float3& speed,
CUnit* owner,
float areaOfEffect, float maxSpeed,
float tracking, int ttl,
CUnit* target,
const WeaponDef* weaponDef)
: CWeaponProjectile(pos, speed, owner, target, ZeroVector, weaponDef, NULL, ttl),
tracking(tracking),
maxSpeed(maxSpeed),
areaOfEffect(areaOfEffect),
target(target),
nextBubble(4)
{
projectileType = WEAPON_TORPEDO_PROJECTILE;
curSpeed = speed.Length();
dir = speed / curSpeed;
if (target) {
AddDeathDependence(target);
}
SetRadius(0.0f);
drawRadius = maxSpeed * 8;
// const float3 camDir = (pos - camera->pos).Normalize();
texx = projectileDrawer->torpedotex->xstart - (projectileDrawer->torpedotex->xend - projectileDrawer->torpedotex->xstart) * 0.5f;
texy = projectileDrawer->torpedotex->ystart - (projectileDrawer->torpedotex->yend - projectileDrawer->torpedotex->ystart) * 0.5f;
#ifdef TRACE_SYNC
tracefile << "New projectile: ";
tracefile << pos.x << " " << pos.y << " " << pos.z << " " << speed.x << " " << speed.y << " " << speed.z << "\n";
#endif
cegID = gCEG->Load(explGenHandler, cegTag);
}
示例5: CWeaponProjectile
CLaserProjectile::CLaserProjectile(const float3& pos, const float3& speed,
CUnit* owner, float length, const float3& color, const float3& color2,
float intensity, const WeaponDef *weaponDef, int ttl GML_PARG_C)
: CWeaponProjectile(pos,speed,owner,0,ZeroVector,weaponDef,0, true, ttl GML_PARG_P),
color(color),
color2(color2),
length(length),
curLength(0),
stayTime(0),
intensity(intensity),
intensityFalloff(weaponDef?intensity*weaponDef->falloffRate:0)
{
dir=speed;
dir.Normalize();
speedf=speed.Length();
if (weaponDef) SetRadius(weaponDef->collisionSize);
drawRadius=length;
if (weaponDef)midtexx = weaponDef->visuals.texture2->xstart + (weaponDef->visuals.texture2->xend-weaponDef->visuals.texture2->xstart)*0.5f;
#ifdef TRACE_SYNC
tracefile << "New laser: ";
tracefile << pos.x << " " << pos.y << " " << pos.z << " " << speed.x << " " << speed.y << " " << speed.z << "\n";
#endif
if (cegTag.size() > 0) {
ceg.Load(explGenHandler, cegTag);
}
}
示例6: DoExplosionDamage
void CGameHelper::DoExplosionDamage(
CFeature* feature,
const float3& expPos,
float expRad,
const DamageArray& damages,
const int weaponDefID
) {
const CollisionVolume* cv = feature->collisionVolume;
if (cv) {
const float3 dif = (feature->midPos + cv->GetOffsets()) - expPos;
float expDist = std::max(dif.Length(), 0.1f);
float expMod = (expRad - expDist) / expRad;
float dmgScale = (damages.GetDefaultDamage() + damages.impulseBoost);
// always do some damage with explosive stuff
// (DDM wreckage etc. is too big to normally
// be damaged otherwise, even by BB shells)
// NOTE: this will also be only approximate
// for non-spherical volumes
if ((expRad > SQUARE_SIZE) && (expDist < (cv->GetBoundingRadius() * 1.1f)) && (expMod < 0.1f)) {
expMod = 0.1f;
}
if (expMod > 0.0f) {
const DamageArray modDamages = damages * expMod;
const float3& modImpulse = dif * (damages.impulseFactor * expMod / expDist * dmgScale);
feature->DoDamage(modDamages, modImpulse, NULL, weaponDefID);
}
}
}
示例7: GetCamDistOfGrassBlock
static float GetCamDistOfGrassBlock(const int x, const int y, const bool square = false)
{
const float qx = x * gSSsq;
const float qz = y * gSSsq;
const float3 mid = float3(qx, CGround::GetHeightReal(qx, qz, false), qz);
const float3 dif = camera->GetPos() - mid;
return (square) ? dif.SqLength() : dif.Length();
}
示例8: CWeaponProjectile
CMissileProjectile::CMissileProjectile(const float3& pos,const float3& speed,CUnit* owner,const DamageArray& damages,float areaOfEffect,float maxSpeed, int ttl,CUnit* target, WeaponDef *weaponDef,float3 targetPos)
: CWeaponProjectile(pos,speed,owner,target,ZeroVector,weaponDef,0),
damages(damages),
ttl(ttl),
maxSpeed(maxSpeed),
target(target),
dir(speed),
oldSmoke(pos),
age(0),
drawTrail(true),
numParts(0),
areaOfEffect(areaOfEffect),
decoyTarget(0),
targPos(targetPos),
wobbleTime(1),
wobbleDir(0,0,0),
wobbleDif(0,0,0),
isWobbling(weaponDef->wobble>0),
extraHeightTime(0)
{
curSpeed=speed.Length();
dir.Normalize();
oldDir=dir;
if(target)
AddDeathDependence(target);
SetRadius(0.0);
if(!weaponDef->visuals.modelName.empty()){
S3DOModel* model = modelParser->Load3DO(string("objects3d/")+weaponDef->visuals.modelName,1,0);
if(model){
SetRadius(model->radius);
}
}
drawRadius=radius+maxSpeed*8;
ENTER_MIXED;
float3 camDir=(pos-camera->pos).Normalize();
if(camera->pos.distance(pos)*0.2+(1-fabs(camDir.dot(dir)))*3000 < 200)
drawTrail=false;
ENTER_SYNCED;
castShadow=true;
#ifdef TRACE_SYNC
tracefile << "New missile: ";
tracefile << pos.x << " " << pos.y << " " << pos.z << " " << speed.x << " " << speed.y << " " << speed.z << "\n";
#endif
if(target)
target->IncomingMissile(this);
if(weaponDef->trajectoryHeight>0){
float dist=pos.distance(targPos);
extraHeight=dist*weaponDef->trajectoryHeight;
if(dist<maxSpeed)
dist=maxSpeed;
extraHeightTime=(int)(dist/*+pos.distance(targPos+UpVector*dist))*0.5*//maxSpeed);
extraHeightDecay=extraHeight/extraHeightTime;
}
}
示例9:
CFireProjectile::CFireProjectile(const float3& pos, const float3& speed, CUnit* owner, int emitTtl, float emitRadius, int particleTtl, float particleSize):
//! these are synced, but neither weapon nor piece
//! (only burning features create instances of them)
CProjectile(pos, speed, owner, true, false, false),
ttl(emitTtl),
emitPos(pos),
emitRadius(emitRadius),
particleTime(particleTtl),
particleSize(particleSize)
{
drawRadius = emitRadius + particleTime * speed.Length();
checkCol = false;
this->pos.y += particleTime * speed.Length() * 0.5f;
ageSpeed = 1.0f / particleTime;
alwaysVisible = true;
castShadow = true;
}
示例10: CWeaponProjectile
CFlameProjectile::CFlameProjectile(const float3& pos,const float3& speed,const float3& spread,CUnit* owner,const DamageArray& damages, WeaponDef *weaponDef, int ttl)
: CWeaponProjectile(pos,speed,owner,0,ZeroVector,weaponDef,damages,0),
spread(spread),
curTime(0)
{
invttl=1.0/ttl;
SetRadius(speed.Length()*0.9);
}
示例11: Init
void COrbitController::Init(const float3& p, const float3& tar)
{
CCamera* cam = camera;
const float l = (tar == ZeroVector)?
std::max(ground->LineGroundCol(p, p + cam->forward * 1024.0f), 512.0f):
(p - tar).Length();
const float3 t = (tar == ZeroVector)? (p + cam->forward * l): tar;
const float3 v = (t - p);
const float3 w = (v / v.Length()); // do not normalize v in-place
const float d = v.Length();
const float e = RAD2DEG(acos(v.Length2D() / d));
const float r = RAD2DEG(acos(w.x));
distance = cDistance = d;
elevation = cElevation = e;
rotation = cRotation = (v.z > 0.0f)? 180.0f + r: 180.0f - r;
cen = t;
}
示例12: CWeaponProjectile
CStarburstProjectile::CStarburstProjectile(const float3& pos,const float3& speed,CUnit* owner,float3 targetPos,const DamageArray& damages,float areaOfEffect,float maxSpeed,float tracking, int uptime,CUnit* target, WeaponDef *weaponDef, CWeaponProjectile* interceptTarget)
: CWeaponProjectile(pos,speed,owner,target,targetPos,weaponDef,damages,interceptTarget),
ttl(200),
maxSpeed(maxSpeed),
tracking(tracking),
dir(speed),
oldSmoke(pos),
age(0),
drawTrail(true),
numParts(0),
doturn(true),
curCallback(0),
numCallback(0),
missileAge(0),
areaOfEffect(areaOfEffect)
{
this->uptime=uptime;
ttl=(int)min(3000.f,uptime+weaponDef->range/maxSpeed+100);
maxGoodDif=cos(tracking*0.6);
curSpeed=speed.Length();
dir.Normalize();
oldSmokeDir=dir;
drawRadius=maxSpeed*8;
ENTER_MIXED;
numCallback=new int;
*numCallback=0;
float3 camDir=(pos-camera->pos).Normalize();
if(camera->pos.distance(pos)*0.2+(1-fabs(camDir.dot(dir)))*3000 < 200)
drawTrail=false;
ENTER_SYNCED;
for(int a=0;a<5;++a){
oldInfos[a]=new OldInfo;
oldInfos[a]->dir=dir;
oldInfos[a]->pos=pos;
oldInfos[a]->speedf=curSpeed;
}
castShadow=true;
#ifdef TRACE_SYNC
tracefile << "New starburst rocket: ";
tracefile << pos.x << " " << pos.y << " " << pos.z << " " << speed.x << " " << speed.y << " " << speed.z << "\n";
#endif
}
示例13: AddFallingTree
int CAdvTreeDrawer::AddFallingTree(float3 pos, float3 dir, int type)
{
GML_STDMUTEX_LOCK(tree); // AddFallingTree
FallingTree ft;
ft.pos=pos;
dir.y=0;
float s=dir.Length();
if(s>500)
return 0;
ft.dir=dir/s;
ft.speed=std::max(0.01f,s*0.0004f);
ft.type=type;
ft.fallPos=0;
fallingTrees.push_back(ft);
return 0;
}
示例14: CWeaponProjectile
CLaserProjectile::CLaserProjectile(
const float3& pos,
const float3& speed,
CUnit* owner,
float length,
const float3& color,
const float3& color2,
float intensity,
const WeaponDef* weaponDef,
int ttl):
CWeaponProjectile(pos, speed, owner, NULL, ZeroVector, weaponDef, NULL, ttl),
intensity(intensity),
color(color),
color2(color2),
length(length),
curLength(0.0f),
intensityFalloff(weaponDef ? (intensity * weaponDef->falloffRate) : 0.0f),
stayTime(0)
{
projectileType = WEAPON_LASER_PROJECTILE;
speedf = speed.Length();
dir = speed / speedf;
if (weaponDef) {
SetRadiusAndHeight(weaponDef->collisionSize, 0.0f);
midtexx =
(weaponDef->visuals.texture2->xstart +
(weaponDef->visuals.texture2->xend - weaponDef->visuals.texture2->xstart) * 0.5f);
}
drawRadius = length;
#ifdef TRACE_SYNC
tracefile << "New laser: ";
tracefile << pos.x << " " << pos.y << " " << pos.z << " " << speed.x << " " << speed.y << " " << speed.z << "\n";
#endif
cegID = gCEG->Load(explGenHandler, (weaponDef != NULL)? weaponDef->cegTag: "");
}
示例15: InView
bool CCamera::InView(const float3 &p, float radius)
{
const float3 t = (p - pos);
const float l = t.Length();
if (l < 50.0f) {
return true;
}
else if (l > gu->viewRange) {
return false;
}
if ((t.dot(rightside) > radius) ||
(t.dot(leftside) > radius) ||
(t.dot(bottom) > radius) ||
(t.dot(top) > radius)) {
return false;
}
return true;
}