本文整理汇总了C++中vector3f::Length方法的典型用法代码示例。如果您正苦于以下问题:C++ vector3f::Length方法的具体用法?C++ vector3f::Length怎么用?C++ vector3f::Length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vector3f
的用法示例。
在下文中一共展示了vector3f::Length方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Render
void LOD::Render(Graphics::Renderer *renderer, const matrix4x4f &trans, RenderData *rd)
{
//figure out approximate pixel size on screen and pick a child to render
const vector3f cameraPos(-trans[12], -trans[13], -trans[14]);
const float pixrad = 0.5f * Graphics::GetScreenWidth() * rd->boundingRadius / cameraPos.Length();
assert(m_children.size() == m_pixelSizes.size());
if (m_pixelSizes.empty()) return;
unsigned int lod = m_children.size() - 1;
for (unsigned int i=m_pixelSizes.size(); i > 0; i--) {
if (pixrad < m_pixelSizes[i-1]) lod = i-1;
}
m_children[lod]->Render(renderer, trans, rd);
}
示例2: Render
void LOD::Render(const matrix4x4f &trans, const RenderData *rd)
{
//figure out approximate pixel size of object's bounding radius
//on screen and pick a child to render
const vector3f cameraPos(-trans[12], -trans[13], -trans[14]);
//fov is vertical, so using screen height
const float pixrad = Graphics::GetScreenHeight() * rd->boundingRadius / (cameraPos.Length() * Graphics::GetFovFactor());
if (m_pixelSizes.empty()) return;
unsigned int lod = m_children.size() - 1;
for (unsigned int i=m_pixelSizes.size(); i > 0; i--) {
if (pixrad < m_pixelSizes[i-1]) lod = i-1;
}
m_children[lod]->Render(trans, rd);
}
示例3: Render
void LOD::Render(const std::vector<matrix4x4f> &trans, const RenderData *rd)
{
// anything to draw?
if (m_pixelSizes.empty())
return;
// got something to draw with
Graphics::Renderer *r = GetRenderer();
if ( r!=nullptr )
{
const size_t count = m_pixelSizes.size();
const size_t tsize = trans.size();
// transformation buffers
std::vector< std::vector<matrix4x4f> > transform;
transform.resize(count);
for (Uint32 i = 0; i<count; i++) {
transform[i].reserve(tsize);
}
// seperate out the transformations
for (auto mt : trans)
{
//figure out approximate pixel size of object's bounding radius
//on screen and pick a child to render
const vector3f cameraPos(-mt[12], -mt[13], -mt[14]);
//fov is vertical, so using screen height
const float pixrad = Graphics::GetScreenHeight() * rd->boundingRadius / (cameraPos.Length() * Graphics::GetFovFactor());
unsigned int lod = m_children.size() - 1;
for (unsigned int i = m_pixelSizes.size(); i > 0; i--) {
if (pixrad < m_pixelSizes[i - 1]) {
lod = i - 1;
}
}
transform[lod].push_back(mt);
}
// now render each of the buffers for each of the lods
for (Uint32 inst = 0; inst < transform.size(); inst++) {
if (!transform[inst].empty()) {
m_children[inst]->Render(transform[inst], rd);
}
}
}
}
示例4: Draw
void Camera::Draw(Renderer *renderer, const Body *excludeBody)
{
if (!m_camFrame) return;
if (!renderer) return;
m_renderer = renderer;
glPushAttrib(GL_ALL_ATTRIB_BITS & (~GL_POINT_BIT));
m_renderer->SetPerspectiveProjection(m_fovAng, m_width/m_height, m_zNear, m_zFar);
m_renderer->SetTransform(matrix4x4f::Identity());
m_renderer->ClearScreen();
matrix4x4d trans2bg;
Frame::GetFrameRenderTransform(Pi::game->GetSpace()->GetRootFrame(), m_camFrame, trans2bg);
trans2bg.ClearToRotOnly();
// Pick up to four suitable system light sources (stars)
m_lightSources.clear();
m_lightSources.reserve(4);
position_system_lights(m_camFrame, Pi::game->GetSpace()->GetRootFrame(), m_lightSources);
if (m_lightSources.empty()) {
// no lights means we're somewhere weird (eg hyperspace). fake one
const Color col(1.f);
m_lightSources.push_back(LightSource(0, Graphics::Light(Graphics::Light::LIGHT_DIRECTIONAL, vector3f(0.f), col, col)));
}
//fade space background based on atmosphere thickness and light angle
float bgIntensity = 1.f;
if (m_camFrame->GetParent() && m_camFrame->GetParent()->IsRotFrame()) {
//check if camera is near a planet
Body *camParentBody = m_camFrame->GetParent()->GetBody();
if (camParentBody && camParentBody->IsType(Object::PLANET)) {
Planet *planet = static_cast<Planet*>(camParentBody);
const vector3f relpos(planet->GetInterpPositionRelTo(m_camFrame));
double altitude(relpos.Length());
double pressure, density;
planet->GetAtmosphericState(altitude, &pressure, &density);
if (pressure >= 0.001)
{
//go through all lights to calculate something resembling light intensity
float angle = 0.f;
for(std::vector<LightSource>::const_iterator it = m_lightSources.begin();
it != m_lightSources.end(); ++it) {
const vector3f lightDir(it->GetLight().GetPosition().Normalized());
angle += std::max(0.f, lightDir.Dot(-relpos.Normalized())) * it->GetLight().GetDiffuse().GetLuminance();
}
//calculate background intensity with some hand-tweaked fuzz applied
bgIntensity = Clamp(1.f - std::min(1.f, powf(density, 0.25f)) * (0.3f + powf(angle, 0.25f)), 0.f, 1.f);
}
}
}
Pi::game->GetSpace()->GetBackground().SetIntensity(bgIntensity);
Pi::game->GetSpace()->GetBackground().Draw(renderer, trans2bg);
{
std::vector<Graphics::Light> rendererLights;
for (size_t i = 0; i < m_lightSources.size(); i++)
rendererLights.push_back(m_lightSources[i].GetLight());
renderer->SetLights(rendererLights.size(), &rendererLights[0]);
}
for (std::list<BodyAttrs>::iterator i = m_sortedBodies.begin(); i != m_sortedBodies.end(); ++i) {
BodyAttrs *attrs = &(*i);
// explicitly exclude a single body if specified (eg player)
if (attrs->body == excludeBody)
continue;
double rad = attrs->body->GetClipRadius();
if (!m_frustum.TestPointInfinite((*i).viewCoords, rad))
continue;
// draw spikes for far objects
double screenrad = 500 * rad / attrs->camDist; // approximate pixel size
if (attrs->body->IsType(Object::PLANET) && screenrad < 2) {
// absolute bullshit
double spikerad = (7 + 1.5*log10(screenrad)) * rad / screenrad;
DrawSpike(spikerad, attrs->viewCoords, attrs->viewTransform);
}
else if (screenrad >= 2 || attrs->body->IsType(Object::STAR) ||
(attrs->body->IsType(Object::PROJECTILE) && screenrad > 0.25))
attrs->body->Render(renderer, this, attrs->viewCoords, attrs->viewTransform);
}
Sfx::RenderAll(renderer, Pi::game->GetSpace()->GetRootFrame(), m_camFrame);
m_frame->RemoveChild(m_camFrame);
delete m_camFrame;
m_camFrame = 0;
glPopAttrib();
}
示例5: DrawNearSector
void SectorView::DrawNearSector(int sx, int sy, int sz, const vector3f &playerAbsPos,const matrix4x4f &trans)
{
m_renderer->SetTransform(trans);
Sector* ps = GetCached(sx, sy, sz);
int cz = int(floor(m_pos.z+0.5f));
if (cz == sz) {
const Color darkgreen(0.f, 0.2f, 0.f, 1.f);
const vector3f vts[] = {
vector3f(0.f, 0.f, 0.f),
vector3f(0.f, Sector::SIZE, 0.f),
vector3f(Sector::SIZE, Sector::SIZE, 0.f),
vector3f(Sector::SIZE, 0.f, 0.f)
};
m_renderer->DrawLines(4, vts, darkgreen, LINE_LOOP);
}
Uint32 sysIdx = 0;
for (std::vector<Sector::System>::iterator i = ps->m_systems.begin(); i != ps->m_systems.end(); ++i, ++sysIdx) {
// calculate where the system is in relation the centre of the view...
const vector3f sysAbsPos = Sector::SIZE*vector3f(float(sx), float(sy), float(sz)) + (*i).p;
const vector3f toCentreOfView = m_pos*Sector::SIZE - sysAbsPos;
// ...and skip the system if it doesn't fall within the sphere we're viewing.
if (toCentreOfView.Length() > OUTER_RADIUS) continue;
// if the system is the current system or target we can't skip it
bool can_skip = !i->IsSameSystem(m_selected)
&& !i->IsSameSystem(m_hyperspaceTarget)
&& !i->IsSameSystem(m_current);
// if the system belongs to a faction we've chosen to temporarily hide
// then skip it if we can
m_visibleFactions.insert(i->faction);
if (m_hiddenFactions.find(i->faction) != m_hiddenFactions.end() && can_skip) continue;
// determine if system in hyperjump range or not
Sector *playerSec = GetCached(m_current.sectorX, m_current.sectorY, m_current.sectorZ);
float dist = Sector::DistanceBetween(ps, sysIdx, playerSec, m_current.systemIndex);
bool inRange = dist <= m_playerHyperspaceRange;
// don't worry about looking for inhabited systems if they're
// unexplored (same calculation as in StarSystem.cpp) or we've
// already retrieved their population.
if ((*i).population < 0 && isqrt(1 + sx*sx + sy*sy + sz*sz) <= 90) {
// only do this once we've pretty much stopped moving.
vector3f diff = vector3f(
fabs(m_posMovingTo.x - m_pos.x),
fabs(m_posMovingTo.y - m_pos.y),
fabs(m_posMovingTo.z - m_pos.z));
// Ideally, since this takes so f'ing long, it wants to be done as a threaded job but haven't written that yet.
if( (diff.x < 0.001f && diff.y < 0.001f && diff.z < 0.001f) ) {
SystemPath current = SystemPath(sx, sy, sz, sysIdx);
RefCountedPtr<StarSystem> pSS = StarSystem::GetCached(current);
(*i).population = pSS->GetTotalPop();
}
}
matrix4x4f systrans = trans * matrix4x4f::Translation((*i).p.x, (*i).p.y, (*i).p.z);
m_renderer->SetTransform(systrans);
// for out-of-range systems draw leg only if we draw label
if (m_drawSystemLegButton->GetPressed()
&& (inRange || m_drawOutRangeLabelButton->GetPressed()) || !can_skip){
const Color light(0.5f);
const Color dark(0.2f);
// draw system "leg"
float z = -(*i).p.z;
if (sz <= cz)
z = z+abs(cz-sz)*Sector::SIZE;
else
z = z-abs(cz-sz)*Sector::SIZE;
m_lineVerts->Add(systrans * vector3f(0.f, 0.f, z), light);
m_lineVerts->Add(systrans * vector3f(0.f, 0.f, z * 0.5f), dark);
m_lineVerts->Add(systrans * vector3f(0.f, 0.f, z * 0.5f), dark);
m_lineVerts->Add(systrans * vector3f(0.f, 0.f, 0.f), light);
//cross at other end
m_lineVerts->Add(systrans * vector3f(-0.1f, -0.1f, z), light);
m_lineVerts->Add(systrans * vector3f(0.1f, 0.1f, z), light);
m_lineVerts->Add(systrans * vector3f(-0.1f, 0.1f, z), light);
m_lineVerts->Add(systrans * vector3f(0.1f, -0.1f, z), light);
}
if (i->IsSameSystem(m_selected)) {
m_jumpLine.SetStart(vector3f(0.f, 0.f, 0.f));
m_jumpLine.SetEnd(playerAbsPos - sysAbsPos);
m_jumpLine.Draw(m_renderer);
}
// draw star blob itself
systrans.Rotate(DEG2RAD(-m_rotZ), 0, 0, 1);
systrans.Rotate(DEG2RAD(-m_rotX), 1, 0, 0);
//.........这里部分代码省略.........