本文整理汇总了C++中Fvector::distance_to方法的典型用法代码示例。如果您正苦于以下问题:C++ Fvector::distance_to方法的具体用法?C++ Fvector::distance_to怎么用?C++ Fvector::distance_to使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fvector
的用法示例。
在下文中一共展示了Fvector::distance_to方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: operator
bool operator() (const CGameObject *tpObject1, const CGameObject *tpObject2) const
{
float dist1 = monster_pos.distance_to(tpObject1->Position());
float dist2 = enemy_pos.distance_to(tpObject2->Position());
float dist3 = enemy_pos.distance_to(monster_pos);
return ((dist1 < dist3) && (dist2 > dist3));
};
示例2:
IC float Area (Fvector& v0, Fvector& v1, Fvector& v2)
{
float e1 = v0.distance_to(v1);
float e2 = v0.distance_to(v2);
float e3 = v1.distance_to(v2);
float p = (e1+e2+e3)/2.f;
return _sqrt( p*(p-e1)*(p-e2)*(p-e3) );
}
示例3: mark_nodes_in_direction
float CLevelGraph::mark_nodes_in_direction(u32 start_vertex_id, const Fvector &start_point, const Fvector &finish_point, xr_vector<u32> &tpaStack, xr_vector<bool> *tpaMarks) const
{
SContour _contour;
const_iterator I,E;
int saved_index, iPrevIndex = -1, iNextNode;
Fvector temp_point = start_point;
float fDistance = start_point.distance_to(finish_point), fCurDistance = 0.f;
u32 dwCurNode = start_vertex_id;
while (!inside(vertex(dwCurNode),finish_point) && (fCurDistance < (fDistance + EPS_L))) {
begin (dwCurNode,I,E);
saved_index = -1;
contour (_contour,dwCurNode);
for ( ; I != E; ++I) {
iNextNode = value(dwCurNode,I);
if (valid_vertex_id(iNextNode) && (iPrevIndex != iNextNode))
choose_point(start_point,finish_point,_contour, iNextNode,temp_point,saved_index);
}
if (saved_index > -1) {
fCurDistance = start_point.distance_to_xz(temp_point);
iPrevIndex = dwCurNode;
dwCurNode = saved_index;
}
else
return(fCurDistance);
if (tpaMarks)
(*tpaMarks)[dwCurNode] = true;
tpaStack.push_back (dwCurNode);
}
return (fCurDistance);
}
示例4: is_faced
bool CMonsterEnemyManager::is_faced(const CEntityAlive *object0, const CEntityAlive *object1)
{
if (object0->Position().distance_to(object1->Position()) > object0->ffGetRange())
{
return false;
}
float yaw1, pitch1, yaw2, pitch2, fYawFov, fPitchFov, fRange;
Fvector tPosition = object0->Position();
yaw1 = object0->Orientation().yaw;
pitch1 = object0->Orientation().pitch;
fYawFov = angle_normalize_signed(object0->ffGetFov()*PI/180.f);
fRange = object0->ffGetRange();
fYawFov = angle_normalize_signed((_abs(fYawFov) + _abs(atanf(1.f/tPosition.distance_to(object1->Position()))))/2.f);
fPitchFov = angle_normalize_signed(fYawFov*1.f);
tPosition.sub (object1->Position());
tPosition.mul (-1);
tPosition.getHP (yaw2,pitch2);
yaw1 = angle_normalize_signed(yaw1);
pitch1 = angle_normalize_signed(pitch1);
yaw2 = angle_normalize_signed(yaw2);
pitch2 = angle_normalize_signed(pitch2);
if ((angle_difference(yaw1,yaw2) <= fYawFov) && (angle_difference(pitch1,pitch2) <= fPitchFov))
return (true);
return (false);
}
示例5: SelectLightsForObject
void ESceneLightTools::SelectLightsForObject(CCustomObject* obj)
{
for (u32 i=0; i<frame_light.size(); i++){
CLight* l = frame_light[i];
// if (obj->IsDynamic()&&!l->m_Flags.is(CLight::flAffectDynamic)) continue;
// if (!obj->IsDynamic()&&!l->m_Flags.is(CLight::flAffectStatic)) continue;
Fbox bb; obj->GetBox(bb);
Fvector C; float R; bb.getsphere(C,R);
float d = C.distance_to(l->PPosition) - l->m_Range - R;
Device.LightEnable(i,(d<0));
}
}
示例6: at_mid_home
bool CMonsterHome::at_mid_home(const Fvector &pos)
{
if (!m_path) return true;
// check every point and distance to it
for (u32 i=0; i<m_path->vertex_count(); i++) {
const CPatrolPath::CVertex *vertex = m_path->vertex(i);
float dist = pos.distance_to(ai().level_graph().vertex_position(vertex->data().level_vertex_id()));
if (dist < m_radius_middle) return true;
}
return false;
}
示例7: feel_sound_new
void CBaseMonster::feel_sound_new(CObject* who, int eType, CSound_UserDataPtr user_data, const Fvector &Position, float power)
{
if (!g_Alive()) return;
// ignore my sounds
if (this == who) return;
if (user_data)
user_data->accept (sound_user_data_visitor());
// ignore unknown sounds
if (eType == 0xffffffff) return;
// ignore distant sounds
Fvector center;
Center (center);
float dist = center.distance_to(Position);
if (dist > db().m_max_hear_dist) return;
// ignore sounds if not from enemies and not help sounds
CEntityAlive* entity = smart_cast<CEntityAlive*> (who);
// ignore sound if enemy drop a weapon on death
if (!entity && ((eType & SOUND_TYPE_ITEM_HIDING) == SOUND_TYPE_ITEM_HIDING)) return;
if (entity && (!EnemyMan.is_enemy(entity))) {
SoundMemory.check_help_sound(eType, entity->ai_location().level_vertex_id());
return;
}
if ((eType & SOUND_TYPE_WEAPON_SHOOTING) == SOUND_TYPE_WEAPON_SHOOTING) power = 1.f;
if (((eType & SOUND_TYPE_WEAPON_BULLET_HIT) == SOUND_TYPE_WEAPON_BULLET_HIT) && (dist < 2.f))
HitMemory.add_hit(who,eSideFront);
// execute callback
sound_callback (who,eType,Position,power);
// register in sound memory
if (power >= db().m_fSoundThreshold) {
SoundMemory.HearSound(who,eType,Position,power,Device.dwTimeGlobal);
}
}
示例8:
void CLightShadows::set_object (IRenderable* O)
{
if (0==O) current = 0;
else
{
if (!O->renderable_ShadowGenerate() || RImplementation.val_bHUD || ((CROS_impl*)O->renderable_ROS())->shadow_gen_frame==Device.dwFrame)
{
current = 0;
return;
}
Fvector C; O->renderable.xform.transform_tiny (C,O->renderable.visual->vis.sphere.P);
float R = O->renderable.visual->vis.sphere.R;
float D = C.distance_to(Device.vCameraPosition)+R;
// D=0 -> P=0;
// R<S_ideal_size -> P=max, R>S_ideal_size -> P=min
float _priority = (D/S_distance)*(S_ideal_size/(R+EPS));
if (_priority<1.f) current = O;
else current = 0;
if (current)
{
((CROS_impl*)O->renderable_ROS())->shadow_gen_frame = Device.dwFrame;
// alloc
caster* cs = NULL;
if (casters_pool.empty()) cs = xr_new<caster> ();
else {
cs = casters_pool.back ();
casters_pool.pop_back ();
}
//
casters.push_back (cs);
cs->O = current;
cs->C = C;
cs->D = D;
cs->nodes.clear ();
}
}
}
示例9: check_actor_visibility
bool check_actor_visibility (const Fvector trace_from,
const Fvector trace_to,
CObject* object)
{
const float dist = trace_from.distance_to(trace_to);
Fvector trace_dir;
trace_dir.sub(trace_to, trace_from);
//DBG().level_info(this).add_item (trace_from,trace_to,D3DCOLOR_XRGB(0,150,150));
collide::rq_result l_rq;
l_rq.O = NULL;
Level().ObjectSpace.RayPick(trace_from,
trace_dir,
dist,
collide::rqtBoth,
l_rq,
object);
return l_rq.O == Actor();
}
示例10: evaluate_cover
void CCoverEvaluator::evaluate_cover(const CCoverPoint *cover_point, float weight)
{
#ifdef DEBUG
//DBG().level_info(this).add_item(cover_point->position(), D3DCOLOR_XRGB(0,255,0));
#endif
CMonsterSquad *squad = monster_squad().get_squad(m_object);
if (squad->is_locked_cover(cover_point->level_vertex_id())) return;
if (fis_zero(weight))
return;
float dest_distance = m_dest_position.distance_to(cover_point->position());
if ((dest_distance <= m_min_distance) && (m_current_distance > dest_distance))
return;
if((dest_distance >= m_max_distance) && (m_current_distance < dest_distance))
return;
Fvector direction;
float y,p;
direction.sub (m_dest_position,cover_point->position());
direction.getHP (y,p);
float high_cover_value = ai().level_graph().high_cover_in_direction(y,cover_point->level_vertex_id());
float low_cover_value = ai().level_graph().low_cover_in_direction(y,cover_point->level_vertex_id());
float cover_value = _min(high_cover_value, low_cover_value);
float value = cover_value;
if (ai().level_graph().neighbour_in_direction(direction,cover_point->level_vertex_id()))
value += 10.f;
value /= weight;
if (value >= m_best_value)
return;
m_selected = cover_point;
m_best_value = value;
}
示例11:
void CLightProjector::set_object (IRenderable* O)
{
if ((0==O) || (receivers.size()>=P_o_count)) current = 0;
else
{
if (!O->renderable_ShadowReceive() || RImplementation.val_bInvisible || ((CROS_impl*)O->renderable_ROS())->shadow_recv_frame==Device.dwFrame)
{
current = 0;
return;
}
const vis_data &vis = O->renderable.visual->getVisData();
Fvector C; O->renderable.xform.transform_tiny (C,vis.sphere.P);
float R = vis.sphere.R;
float D = C.distance_to (Device.vCameraPosition)+R;
if (D < clipD(R)) current = O;
else current = 0;
if (current) {
ISpatial* spatial = dynamic_cast<ISpatial*> (O);
if (0==spatial) current= 0;
else {
spatial->spatial_updatesector ();
if (0==spatial->spatial.sector) {
CObject* obj = dynamic_cast<CObject*>(O);
if (obj) Msg ("! Invalid object '%s' position. Outside of sector structure.",obj->cName().c_str());
current = 0;
}
}
}
if (current) {
CROS_impl* LT = (CROS_impl*)current->renderable_ROS ();
LT->shadow_recv_frame = Device.dwFrame;
receivers.push_back (current);
}
}
}
示例12:
bool CAI_Stalker::too_far_to_kill_enemy (const Fvector &position)
{
#if 1
return (false);
#else
VERIFY (memory().enemy().selected());
VERIFY (best_weapon());
int weapon_type = best_weapon()->object().ef_weapon_type();
float distance = position.distance_to(Position());
switch (weapon_type) {
// pistols
case 5 : return (distance > 10.f);
// shotguns
case 9 : return (distance > 5.f);
// sniper rifles
case 11 :
case 12 :
return (distance > 70.f);
default: return (distance > 5.f);
}
#endif
}
示例13: farthest_vertex_in_direction
float CLevelGraph::farthest_vertex_in_direction(u32 start_vertex_id, const Fvector &start_point, const Fvector &finish_point, u32 &finish_vertex_id, xr_vector<bool> *tpaMarks, bool check_accessability) const
{
SContour _contour;
const_iterator I,E;
int saved_index, iPrevIndex = -1, iNextNode;
Fvector temp_point = start_point;
float fDistance = start_point.distance_to(finish_point), fCurDistance = 0.f;
u32 dwCurNode = start_vertex_id;
while (!inside(vertex(dwCurNode),finish_point) && (fCurDistance < (fDistance + EPS_L))) {
begin (dwCurNode,I,E);
saved_index = -1;
contour (_contour,dwCurNode);
for ( ; I != E; ++I) {
iNextNode = value(dwCurNode,I);
if (valid_vertex_id(iNextNode) && (iPrevIndex != iNextNode))
choose_point(start_point,finish_point,_contour, iNextNode,temp_point,saved_index);
}
if (saved_index > -1) {
if (check_accessability && !is_accessible(saved_index))
return (fCurDistance);
fCurDistance = start_point.distance_to_xz(temp_point);
iPrevIndex = dwCurNode;
dwCurNode = saved_index;
}
else
return (fCurDistance);
if (tpaMarks)
(*tpaMarks)[dwCurNode] = true;
finish_vertex_id = dwCurNode;
}
return (fCurDistance);
}
示例14: BuildNodes
int ESceneAIMapTool::BuildNodes(const Fvector& pos, int sz, bool bIC)
{
// Align emitter
Fvector Pos = pos;
SnapXZ (Pos,m_Params.fPatchSize);
Pos.y += 1;
Fvector Dir; Dir.set(0,-1,0);
int cnt = 0;
if (m_CFModel)
cnt=Scene->RayQuery(PQ,Pos,Dir,3,CDB::OPT_ONLYNEAREST|CDB::OPT_CULL,m_CFModel);
else
cnt=Scene->RayQuery(PQ,Pos,Dir,3,CDB::OPT_ONLYNEAREST|CDB::OPT_CULL,GetSnapList());
if (0==cnt) {
ELog.Msg (mtInformation,"Can't align position.");
return 0;
} else {
Pos.y = Pos.y - PQ.r_begin()->range;
}
// Build first node
int oldcount = m_Nodes.size();
SAINode* start = BuildNode(Pos,Pos,bIC);
if (!start) return 0;
// Estimate nodes
float estimated_nodes = (2*sz-1)*(2*sz-1);
SPBItem* pb = 0;
if (estimated_nodes>1024) pb = UI->ProgressStart(1, "Building nodes...");
float radius = sz*m_Params.fPatchSize-EPS_L;
// General cycle
for (int k=0; k<(int)m_Nodes.size(); k++){
SAINode* N = m_Nodes[k];
// left
if (0==N->n1){
Pos.set (N->Pos);
Pos.x -= m_Params.fPatchSize;
if (Pos.distance_to(start->Pos)<=radius)
N->n1 = BuildNode(N->Pos,Pos,bIC);
}
// fwd
if (0==N->n2){
Pos.set (N->Pos);
Pos.z += m_Params.fPatchSize;
if (Pos.distance_to(start->Pos)<=radius)
N->n2 = BuildNode(N->Pos,Pos,bIC);
}
// right
if (0==N->n3){
Pos.set (N->Pos);
Pos.x += m_Params.fPatchSize;
if (Pos.distance_to(start->Pos)<=radius)
N->n3 = BuildNode(N->Pos,Pos,bIC);
}
// back
if (0==N->n4){
Pos.set (N->Pos);
Pos.z -= m_Params.fPatchSize;
if (Pos.distance_to(start->Pos)<=radius)
N->n4 = BuildNode(N->Pos,Pos,bIC);
}
if (estimated_nodes>1024){
if (k%128==0) {
float p1 = float(k)/float(m_Nodes.size());
float p2 = float(m_Nodes.size())/estimated_nodes;
float p = 0.1f*p1+0.9f*p2;
clamp (p,0.f,1.f);
pb->Update(p);
// check need abort && redraw
if (UI->NeedAbort()) break;
}
}
}
if (estimated_nodes>1024) UI->ProgressEnd(pb);
return oldcount-m_Nodes.size();
}
示例15: export_ogf
void xrMU_Reference::export_ogf()
{
xr_vector<u32> generated_ids;
// Export nodes
{
for (xrMU_Model::v_subdivs_it it=model->m_subdivs.begin(); it!=model->m_subdivs.end(); it++)
{
OGF_Reference* pOGF = xr_new<OGF_Reference> ();
b_material* M = &(pBuild->materials[it->material]); // and it's material
R_ASSERT (M);
// Common data
pOGF->Sector = sector;
pOGF->material = it->material;
// Collect textures
OGF_Texture T;
TRY(T.name = pBuild->textures[M->surfidx].name);
TRY(T.pSurface = &(pBuild->textures[M->surfidx]));
TRY(pOGF->textures.push_back(T));
// Special
pOGF->model = it->ogf;
pOGF->vb_id = it->vb_id;
pOGF->vb_start = it->vb_start;
pOGF->ib_id = it->ib_id;
pOGF->ib_start = it->ib_start;
pOGF->xform.set (xform);
pOGF->c_scale = c_scale;
pOGF->c_bias = c_bias;
pOGF->sw_id = it->sw_id;
pOGF->CalcBounds ();
generated_ids.push_back ((u32)g_tree.size());
g_tree.push_back (pOGF);
}
}
// Now, let's fuck with LODs
if (u16(-1) == model->m_lod_ID) return;
{
// Create Node and fill it with information
b_lod& LOD = pBuild->lods [model->m_lod_ID];
OGF_LOD* pNode = xr_new<OGF_LOD> (1,sector);
pNode->lod_Material = LOD.dwMaterial;
for (int lf=0; lf<8; lf++)
{
b_lod_face& F = LOD.faces[lf];
OGF_LOD::_face& D = pNode->lod_faces[lf];
for (int lv=0; lv<4; lv++)
{
xform.transform_tiny(D.v[lv].v,F.v[lv]);
D.v[lv].t = F.t[lv];
D.v[lv].c_rgb_hemi = 0xffffffff;
D.v[lv].c_sun = 0xff;
}
}
// Add all 'OGFs' with such LOD-id
for (u32 o=0; o<generated_ids.size(); o++)
pNode->AddChield(generated_ids[o]);
// Register node
R_ASSERT (pNode->chields.size());
pNode->CalcBounds ();
g_tree.push_back (pNode);
// Calculate colors
const float sm_range = 5.f;
for (int lf=0; lf<8; lf++)
{
OGF_LOD::_face& F = pNode->lod_faces[lf];
for (int lv=0; lv<4; lv++)
{
Fvector ptPos = F.v[lv].v;
base_color_c _C;
float _N = 0;
for (u32 v_it=0; v_it<model->m_vertices.size(); v_it++)
{
// get base
Fvector baseP; xform.transform_tiny (baseP,model->m_vertices[v_it]->P);
base_color_c baseC; color[v_it]._get(baseC);
base_color_c vC;
float oD = ptPos.distance_to (baseP);
float oA = 1/(1+100*oD*oD);
vC = (baseC);
vC.mul (oA);
_C.add (vC);
_N += oA;
}
float s = 1/(_N+EPS);
_C.mul (s);
F.v[lv].c_rgb_hemi = color_rgba(u8_clr(_C.rgb.x),u8_clr(_C.rgb.y),u8_clr(_C.rgb.z),u8_clr(_C.hemi));
F.v[lv].c_sun = u8_clr (_C.sun);
}
//.........这里部分代码省略.........