本文整理汇总了C++中Fvector::square_magnitude方法的典型用法代码示例。如果您正苦于以下问题:C++ Fvector::square_magnitude方法的具体用法?C++ Fvector::square_magnitude怎么用?C++ Fvector::square_magnitude使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fvector
的用法示例。
在下文中一共展示了Fvector::square_magnitude方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ConeSphereIntersection
////////////////////////////////////////////////////////////////////////////////////////////////
// Функция ConeSphereIntersection
// Пересечение конуса (не ограниченного) со сферой
// Необходима для определения пересечения копыта плоти с баунд-сферой крысы
// Параметры: ConeVertex - вершина конуса, ConeAngle - угол конуса (между поверхностью и высотой)
// ConeDir - направление конуса, SphereCenter - центр сферы, SphereRadius - радиус сферы
bool CAI_Flesh::ConeSphereIntersection(Fvector ConeVertex, float ConeAngle, Fvector ConeDir, Fvector SphereCenter, float SphereRadius)
{
float fInvSin = 1.0f/_sin(ConeAngle);
float fCosSqr = _cos(ConeAngle)*_cos(ConeAngle);
Fvector kCmV; kCmV.sub(SphereCenter,ConeVertex);
Fvector kD = kCmV;
Fvector tempV = ConeDir;
tempV.mul (SphereRadius* fInvSin);
kD.add (tempV);
float fDSqrLen = kD.square_magnitude();
float fE = kD.dotproduct(ConeDir);
if ( fE > 0.0f && fE*fE >= fDSqrLen*fCosSqr ) {
float fSinSqr = _sin(ConeAngle)*_sin(ConeAngle);
fDSqrLen = kCmV.square_magnitude();
fE = -kCmV.dotproduct(ConeDir);
if ( fE > 0.0f && fE*fE >= fDSqrLen*fSinSqr ) {
float fRSqr = SphereRadius*SphereRadius;
return fDSqrLen <= fRSqr;
} else return true;
}
return false;
}
示例2: SqrDistancePointToSegment
float SqrDistancePointToSegment(const Fvector& pt, const Fvector& orig, const Fvector& dir)
{
Fvector diff; diff.sub(pt,orig);
float fT = diff.dotproduct(dir);
if ( fT <= 0.0f ){
fT = 0.0f;
}else{
float fSqrLen= dir.square_magnitude();
if ( fT >= fSqrLen ){
fT = 1.0f;
diff.sub(dir);
}else{
fT /= fSqrLen;
diff.sub(Fvector().mul(dir,fT));
}
}
return diff.square_magnitude();
}
示例3: PathDIrPoint
void CPHMovementControl::PathDIrPoint(const xr_vector<DetailPathManager::STravelPathPoint> &path, int index, float distance, float precesition, Fvector &dir )
{
Fvector to_path_point;
Fvector corrected_path_dir;CorrectPathDir(GetPathDir(),path,index,corrected_path_dir);
to_path_point.sub(vPathPoint,vPosition); //_new position
float mag=to_path_point.magnitude();
if(mag<EPS) //near the point
{
if(0==index||m_path_size-1==index) //on path eidge
{
dir.set(corrected_path_dir);//??
return;
}
dir.sub(path[index].position,path[index-1].position);
dir.normalize_safe();
dir.add(corrected_path_dir);
dir.normalize_safe();
}
to_path_point.mul(1.f/mag);
if(m_path_size-1==index)//on_path_edge
{
dir.set(to_path_point);
return;
}
if(mag<EPS||fis_zero(dXZMag(to_path_point),EPS))
{
dir.set(corrected_path_dir);
return;//mean dir
}
Fvector tangent;
tangent.crossproduct(Fvector().set(0,1,0),to_path_point);
VERIFY(!fis_zero(tangent.magnitude()));
tangent.normalize();
if(dir.square_magnitude()>EPS)
{
if(tangent.dotproduct(dir)<0.f)tangent.invert();
}
else
{
if(tangent.dotproduct(corrected_path_dir)<0.f)tangent.invert();
}
if(mag>FootRadius())to_path_point.mul(precesition);
else to_path_point.mul(mag*precesition);
dir.add(tangent,to_path_point);
dir.normalize_safe();
}
示例4:
void CAI_Stalker::can_kill_entity (const Fvector &position, const Fvector &direction, float distance, collide::rq_results& rq_storage)
{
VERIFY (!fis_zero(direction.square_magnitude()));
collide::ray_defs ray_defs(position,direction,distance,CDB::OPT_CULL,collide::rqtBoth);
VERIFY (!fis_zero(ray_defs.dir.square_magnitude()));
ray_query_param params(this,memory().visual().transparency_threshold(),distance);
Level().ObjectSpace.RayQuery (rq_storage,ray_defs,ray_query_callback,¶ms,NULL,this);
m_can_kill_enemy = m_can_kill_enemy || params.m_can_kill_enemy;
m_can_kill_member = m_can_kill_member || params.m_can_kill_member;
m_pick_distance = _max(m_pick_distance,params.m_pick_distance);
}
示例5: direction
Fvector CDetailPathManager::direction() const
{
if ((m_path.size() < 2) || (m_path.size() <= m_current_travel_point + 1))
return (Fvector().set(0,0,1));
Fvector direction;
direction.sub (m_path[m_current_travel_point + 1].position, m_path[m_current_travel_point].position);
if (direction.square_magnitude() < EPS_L)
direction.set (0.f,0.f,1.f);
else
direction.normalize ();
return (direction);
}
示例6:
void CPHMovementControl::TraceBorder(const Fvector &prev_position)
{
const Fvector &from_pos =prev_position ;
const Fvector &to_position =vPosition ;
Fvector dir; dir .sub(to_position,from_pos) ;
float sq_mag = dir.square_magnitude() ;
if(sq_mag==0.f) return ;
float mag=_sqrt(sq_mag) ;
dir.mul(1.f/mag) ;
collide::ray_defs RD (from_pos,dir,mag,0,collide::rqtStatic) ;
VERIFY (!fis_zero(RD.dir.square_magnitude())) ;
STraceBorderQParams p(this,dir);
storage.r_clear ();
g_pGameLevel->ObjectSpace.RayQuery(storage,RD,BorderTraceCallback,&p,NULL,static_cast<CObject*>(m_character->PhysicsRefObject()));
}
示例7:
void CDrawUtilities::DrawPlane (const Fvector& p, const Fvector& n, const Fvector2& scale, u32 clr_s, u32 clr_w, BOOL bCull, BOOL bSolid, BOOL bWire)
{
if (n.square_magnitude()<EPS_S) return;
// build final rotation / translation
Fvector L_dir,L_up=n,L_right;
L_dir.set (0,0,1); if (_abs(L_up.dotproduct(L_dir))>.99f) L_dir.set(1,0,0);
L_right.crossproduct(L_up,L_dir); L_right.normalize ();
L_dir.crossproduct (L_right,L_up); L_dir.normalize ();
Fmatrix mR;
mR.i = L_right; mR._14 = 0;
mR.j = L_up; mR._24 = 0;
mR.k = L_dir; mR._34 = 0;
mR.c = p; mR._44 = 1;
// fill VB
_VertexStream* Stream = &RCache.Vertex;
u32 vBase;
if (bSolid){
DU_DRAW_SH(dxRenderDeviceRender::Instance().m_SelectionShader);
FVF::L* pv = (FVF::L*)Stream->Lock(5,vs_L->vb_stride,vBase);
pv->set (-scale.x, 0, -scale.y, clr_s); mR.transform_tiny(pv->p); pv++;
pv->set (-scale.x, 0, +scale.y, clr_s); mR.transform_tiny(pv->p); pv++;
pv->set (+scale.x, 0, +scale.y, clr_s); mR.transform_tiny(pv->p); pv++;
pv->set (+scale.x, 0, -scale.y, clr_s); mR.transform_tiny(pv->p); pv++;
pv->set (*(pv-4));
Stream->Unlock(5,vs_L->vb_stride);
if (!bCull) DU_DRAW_RS(D3DRS_CULLMODE,D3DCULL_NONE);
DU_DRAW_DP (D3DPT_TRIANGLEFAN,vs_L,vBase,2);
if (!bCull) DU_DRAW_RS(D3DRS_CULLMODE,D3DCULL_CCW);
}
if (bWire){
DU_DRAW_SH(dxRenderDeviceRender::Instance().m_WireShader);
FVF::L* pv = (FVF::L*)Stream->Lock(5,vs_L->vb_stride,vBase);
pv->set (-scale.x, 0, -scale.y, clr_w); mR.transform_tiny(pv->p); pv++;
pv->set (+scale.x, 0, -scale.y, clr_w); mR.transform_tiny(pv->p); pv++;
pv->set (+scale.x, 0, +scale.y, clr_w); mR.transform_tiny(pv->p); pv++;
pv->set (-scale.x, 0, +scale.y, clr_w); mR.transform_tiny(pv->p); pv++;
pv->set (*(pv-4));
Stream->Unlock(5,vs_L->vb_stride);
DU_DRAW_DP (D3DPT_LINESTRIP,vs_L,vBase,4);
}
}
示例8: DefaultMovingProcess
bool __fastcall TUI_CustomControl::DefaultMovingProcess(TShiftState Shift, Fvector& amount){
if (Shift.Contains(ssLeft)||Shift.Contains(ssRight)){
amount.mul( m_MovingXVector, UI->m_MouseSM * UI->m_DeltaCpH.x );
amount.mad( amount, m_MovingYVector, -UI->m_MouseSM * UI->m_DeltaCpH.y );
if( Tools->GetSettings(etfMSnap) ){
CHECK_SNAP(m_MovingReminder.x,amount.x,Tools->m_MoveSnap);
CHECK_SNAP(m_MovingReminder.y,amount.y,Tools->m_MoveSnap);
CHECK_SNAP(m_MovingReminder.z,amount.z,Tools->m_MoveSnap);
}
if (!(etAxisX==Tools->GetAxis())&&!(etAxisZX==Tools->GetAxis())) amount.x = 0.f;
if (!(etAxisZ==Tools->GetAxis())&&!(etAxisZX==Tools->GetAxis())) amount.z = 0.f;
if (!(etAxisY==Tools->GetAxis())) amount.y = 0.f;
return (amount.square_magnitude()>EPS_S);
}
return false;
}
示例9: UpdateOnFrame
void SArtefactDetectorsSupport::UpdateOnFrame()
{
if(m_currPatrolPath && !m_parent->getVisible())
{
if(m_parent->Position().distance_to(m_destPoint) < 2.0f)
{
CPatrolPath::const_iterator b,e;
m_currPatrolPath->begin(m_currPatrolVertex,b,e);
if(b!=e)
{
std::advance(b, ::Random.randI(s32(e-b)));
m_currPatrolVertex = m_currPatrolPath->vertex((*b).vertex_id());
m_destPoint = m_currPatrolVertex->data().position();
}
}
float cos_et = _cos(deg2rad(45.f));
Fvector dir;
dir.sub (m_destPoint, m_parent->Position()).normalize_safe();
Fvector v;
m_parent->PHGetLinearVell(v);
float cosa = v.dotproduct(dir);
if(v.square_magnitude() < (0.7f*0.7f) || (cosa<cos_et) )
{
Fvector power = dir;
power.y += 1.0f;
power.mul (m_path_moving_force);
m_parent->m_pPhysicsShell->applyGravityAccel(power);
}
}
if(m_parent->getVisible() && m_parent->GetAfRank()!=0 && m_switchVisTime+5000 < Device.dwTimeGlobal)
SetVisible(false);
u32 dwDt = 2*3600*1000/10; //2 hour of game time
if(!m_parent->getVisible() && m_switchVisTime+dwDt < Device.dwTimeGlobal)
{
m_switchVisTime = Device.dwTimeGlobal;
if(m_parent->Position().distance_to(Device.vCameraPosition)>40.0f)
Blink ();
}
}
示例10: TestPassEffect
float CExplosive::TestPassEffect(const Fvector &source_p, const Fvector &dir,float range,float ef_radius,collide::rq_results& storage, CObject* blasted_obj)
{
float sq_ef_radius=ef_radius*ef_radius;
float dist_factor = sq_ef_radius/(range*range*(exp_dist_extinction_factor-1.f)+sq_ef_radius);
float shoot_factor=1.f;
if(range>EPS_L)
{
VERIFY(!fis_zero(dir.square_magnitude()));
collide::ray_defs RD (source_p,dir,range,CDB::OPT_CULL,collide::rqtBoth);
VERIFY (!fis_zero(RD.dir.square_magnitude()));
#ifdef DEBUG
SExpQParams ep (source_p,dir);
#else
SExpQParams ep;
#endif
g_pGameLevel->ObjectSpace.RayQuery(storage,RD,grenade_hit_callback,&ep,NULL,blasted_obj);
shoot_factor=ep.shoot_factor;
}
else return dist_factor;
return shoot_factor*dist_factor;
}
示例11: SetFirePointLookAngles
void CSightManager::SetFirePointLookAngles(const Fvector &tPosition, float &yaw, float &pitch, const CGameObject *object)
{
Fvector tTemp;
if (object && object->use_center_to_aim()) {
m_object->Center(tTemp);
#if 1
//. hack is here, just because our actor model is animated with 20cm shift
m_object->XFORM().transform_tiny(tTemp,Fvector().set(.2f,tTemp.y - m_object->Position().y,0.f));
#else
const CEntityAlive *entity_alive = smart_cast<const CEntityAlive*>(object);
if (!entity_alive || entity_alive->g_Alive()) {
tTemp.x = m_object->Position().x;
tTemp.z = m_object->Position().z;
}
#endif
tTemp.sub (tPosition,Fvector(tTemp));
if (fis_zero(tTemp.square_magnitude()))
tTemp.set (0.f,0.f,1.f);
}
else {
Fvector my_position;
if (m_object->eye_matrix.c.distance_to_xz_sqr(tPosition) < .1f)
my_position = m_object->Position();
else
my_position = m_object->eye_matrix.c;
tTemp.sub (tPosition,my_position);
}
tTemp.getHP (yaw,pitch);
VERIFY (_valid(yaw));
VERIFY (_valid(pitch));
yaw *= -1;
pitch *= -1;
}
示例12: g_fireParams
void CAI_Stalker::g_fireParams(const CHudItem* pHudItem, Fvector& P, Fvector& D)
{
//. VERIFY (inventory().ActiveItem());
if (!inventory().ActiveItem()) {
#ifdef DEBUG
Msg ("! CAI_Stalker::g_fireParams() : VERIFY(inventory().ActiveItem())");
#endif // DEBUG
P = Position();
D = Fvector().set(0.f,0.f,1.f);
return;
}
CWeapon *weapon = smart_cast<CWeapon*>(inventory().ActiveItem());
if (!weapon) {
CMissile *missile = smart_cast<CMissile*>(inventory().ActiveItem());
if (missile) {
update_throw_params ();
P = m_throw_position;
D = m_throw_direction;
VERIFY (!fis_zero(D.square_magnitude()));
return;
}
P = eye_matrix.c;
D = eye_matrix.k;
if (weapon_shot_effector().IsActive())
D = weapon_shot_effector_direction(D);
VERIFY (!fis_zero(D.square_magnitude()));
return;
}
if (!g_Alive()) {
P = weapon->get_LastFP();
D = weapon->get_LastFD();
VERIFY (!fis_zero(D.square_magnitude()));
return;
}
switch (movement().body_state()) {
case eBodyStateStand : {
if (movement().movement_type() == eMovementTypeStand) {
P = eye_matrix.c;
D = eye_matrix.k;
if (weapon_shot_effector().IsActive())
D = weapon_shot_effector_direction(D);
VERIFY (!fis_zero(D.square_magnitude()));
}
else {
D.setHP (-movement().m_head.current.yaw,-movement().m_head.current.pitch);
if (weapon_shot_effector().IsActive())
D = weapon_shot_effector_direction(D);
Center (P);
P.mad (D,.5f);
P.y += .50f;
// P = weapon->get_LastFP();
// D = weapon->get_LastFD();
VERIFY (!fis_zero(D.square_magnitude()));
}
return;
}
case eBodyStateCrouch : {
P = eye_matrix.c;
D = eye_matrix.k;
if (weapon_shot_effector().IsActive())
D = weapon_shot_effector_direction(D);
VERIFY (!fis_zero(D.square_magnitude()));
return;
}
default : NODEFAULT;
}
#ifdef DEBUG
P = weapon->get_LastFP();
D = weapon->get_LastFD();
VERIFY (!fis_zero(D.square_magnitude()));
#endif
}
示例13: CheckPointInIdentitySphere
IC bool CheckPointInIdentitySphere(const Fvector& point) {
return (point.square_magnitude() <= 1);
}
示例14: render_selected
void CGlowManager::render_selected()
{
// 2. Sort by shader
std::sort (Selected.begin(),Selected.end(),glow_compare);
FVF::LIT *pv;
u32 pos = 0, count;
ref_shader T;
Fplane NP;
NP.build (Device.vCameraPosition,Device.vCameraDirection);
float dlim2 = MAX_GlowsDist2;
for (;pos<Selected.size();)
{
T = ((CGlow*)Selected[pos]._get())->shader;
count = 0;
while ((pos+count<Selected.size()) && (((CGlow*)Selected[pos+count]._get())->shader==T)) count++;
u32 vOffset;
u32 end = pos+count;
FVF::LIT* pvs = pv = (FVF::LIT*) RCache.Vertex.Lock(count*4,hGeom->vb_stride,vOffset);
for (; pos<end; pos++)
{
// Cull invisible
CGlow& G = *( (CGlow*)Selected[pos]._get() );
if (G.fade<=1.f) continue;
// Now perform dotproduct if need it
float scale = 1.f, dist_sq;
Fvector dir;
dir.sub (Device.vCameraPosition,G.position);
dist_sq = dir.square_magnitude();
if (G.direction.square_magnitude()>EPS) {
dir.div (_sqrt(dist_sq));
scale = dir.dotproduct(G.direction);
}
if (G.fade*scale<=1.f) continue;
// near fade
float dist_np = NP.distance(G.position)-VIEWPORT_NEAR;
float snear = dist_np/0.15f; clamp (snear,0.f,1.f);
scale *= snear;
if (G.fade*scale<=1.f) continue;
u32 C = iFloor(G.fade*scale*(1-(dist_sq/dlim2)));
u32 clr = color_rgba(C,C,C,C);
Fvector gp ;
gp.mad (G.position,dir,G.radius*scale);
FillSprite (pv,G.position,G.radius,clr);
}
int vCount = int(pv-pvs);
RCache.Vertex.Unlock (vCount,hGeom->vb_stride);
if (vCount) {
RCache.set_Shader (T);
RCache.set_Geometry (hGeom);
RCache.Render (D3DPT_TRIANGLELIST,vOffset,0,vCount,0,vCount/2);
}
}
Selected.clear_not_free ();
}