本文整理汇总了C++中Light::GetRange方法的典型用法代码示例。如果您正苦于以下问题:C++ Light::GetRange方法的具体用法?C++ Light::GetRange怎么用?C++ Light::GetRange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Light
的用法示例。
在下文中一共展示了Light::GetRange方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CullLights
void World::CullLights(VisibleCullResult & result, Camera * cam)
{
List<Light*>::Iterator whr = mLights.Begin();
List<Light*>::Iterator end = mLights.End();
while (whr != end)
{
// current it's false
Light * light = *whr;
if (!light->IsVisible())
continue;
switch (light->GetType())
{
case LT_DIRECTIONAL:
result.lights.PushBack(light);
break;
case LT_POINT:
case LT_SPOT:
{
Sphere sph = Sphere(light->GetPosition(), light->GetRange());
if (cam->IsVisible(sph))
result.lights.PushBack(light);
}
break;
}
++whr;
}
}
示例2: Prepare
//.........这里部分代码省略.........
float fogRange = Max(fogEnd - fogStart, M_EPSILON);
Vector4 fogParams(fogEnd / farClip, farClip / fogRange, 0.0f, 0.0f);
Node* zoneNode = zone_->GetNode();
if (zone_->GetHeightFog() && zoneNode)
{
Vector3 worldFogHeightVec = zoneNode->GetWorldTransform() * Vector3(0.0f, zone_->GetFogHeight(), 0.0f);
fogParams.z_ = worldFogHeightVec.y_;
fogParams.w_ = zone_->GetFogHeightScale() / Max(zoneNode->GetWorldScale().y_, M_EPSILON);
}
graphics->SetShaderParameter(PSP_FOGPARAMS, fogParams);
}
// Set light-related shader parameters
if (lightQueue_)
{
if (graphics->NeedParameterUpdate(SP_VERTEXLIGHTS, lightQueue_) && graphics->HasShaderParameter(VS, VSP_VERTEXLIGHTS))
{
Vector4 vertexLights[MAX_VERTEX_LIGHTS * 3];
const PODVector<Light*>& lights = lightQueue_->vertexLights_;
for (unsigned i = 0; i < lights.Size(); ++i)
{
Light* vertexLight = lights[i];
Node* vertexLightNode = vertexLight->GetNode();
LightType type = vertexLight->GetLightType();
// Attenuation
float invRange, cutoff, invCutoff;
if (type == LIGHT_DIRECTIONAL)
invRange = 0.0f;
else
invRange = 1.0f / Max(vertexLight->GetRange(), M_EPSILON);
if (type == LIGHT_SPOT)
{
cutoff = Cos(vertexLight->GetFov() * 0.5f);
invCutoff = 1.0f / (1.0f - cutoff);
}
else
{
cutoff = -1.0f;
invCutoff = 1.0f;
}
// Color
float fade = 1.0f;
float fadeEnd = vertexLight->GetDrawDistance();
float fadeStart = vertexLight->GetFadeDistance();
// Do fade calculation for light if both fade & draw distance defined
if (vertexLight->GetLightType() != LIGHT_DIRECTIONAL && fadeEnd > 0.0f && fadeStart > 0.0f && fadeStart < fadeEnd)
fade = Min(1.0f - (vertexLight->GetDistance() - fadeStart) / (fadeEnd - fadeStart), 1.0f);
Color color = vertexLight->GetEffectiveColor() * fade;
vertexLights[i * 3] = Vector4(color.r_, color.g_, color.b_, invRange);
// Direction
vertexLights[i * 3 + 1] = Vector4(-(vertexLightNode->GetWorldDirection()), cutoff);
// Position
vertexLights[i * 3 + 2] = Vector4(vertexLightNode->GetWorldPosition(), invCutoff);
}
if (lights.Size())
graphics->SetShaderParameter(VSP_VERTEXLIGHTS, vertexLights[0].Data(), lights.Size() * 3 * 4);
示例3: Prepare
//.........这里部分代码省略.........
adjust.SetScale(Vector3(1.0f / boxSize.x_, 1.0f / boxSize.y_, 1.0f / boxSize.z_));
adjust.SetTranslation(Vector3(0.5f, 0.5f, 0.5f));
Matrix3x4 zoneTransform = adjust * zone_->GetInverseWorldTransform();
graphics->SetShaderParameter(VSP_ZONE, zoneTransform);
graphics->SetShaderParameter(PSP_AMBIENTCOLOR, zone_->GetAmbientColor());
graphics->SetShaderParameter(PSP_FOGCOLOR, overrideFogColorToBlack ? Color::BLACK : zone_->GetFogColor());
float farClip = camera->GetFarClip();
float fogStart = Min(zone_->GetFogStart(), farClip);
float fogEnd = Min(zone_->GetFogEnd(), farClip);
if (fogStart >= fogEnd * (1.0f - M_LARGE_EPSILON))
fogStart = fogEnd * (1.0f - M_LARGE_EPSILON);
float fogRange = Max(fogEnd - fogStart, M_EPSILON);
Vector4 fogParams(fogEnd / farClip, farClip / fogRange, 0.0f, 0.0f);
Node* zoneNode = zone_->GetNode();
if (zone_->GetHeightFog() && zoneNode)
{
Vector3 worldFogHeightVec = zoneNode->GetWorldTransform() * Vector3(0.0f, zone_->GetFogHeight(), 0.0f);
fogParams.z_ = worldFogHeightVec.y_;
fogParams.w_ = zone_->GetFogHeightScale() / Max(zoneNode->GetWorldScale().y_, M_EPSILON);
}
graphics->SetShaderParameter(PSP_FOGPARAMS, fogParams);
}
// Set light-related shader parameters
if (lightQueue_)
{
if (light && graphics->NeedParameterUpdate(SP_LIGHT, lightQueue_))
{
Node* lightNode = light->GetNode();
float atten = 1.0f / Max(light->GetRange(), M_EPSILON);
Vector3 lightDir(lightNode->GetWorldRotation() * Vector3::BACK);
Vector4 lightPos(lightNode->GetWorldPosition(), atten);
graphics->SetShaderParameter(VSP_LIGHTDIR, lightDir);
graphics->SetShaderParameter(VSP_LIGHTPOS, lightPos);
if (graphics->HasShaderParameter(VSP_LIGHTMATRICES))
{
switch (light->GetLightType())
{
case LIGHT_DIRECTIONAL:
{
Matrix4 shadowMatrices[MAX_CASCADE_SPLITS];
unsigned numSplits = Min(MAX_CASCADE_SPLITS, lightQueue_->shadowSplits_.Size());
for (unsigned i = 0; i < numSplits; ++i)
CalculateShadowMatrix(shadowMatrices[i], lightQueue_, i, renderer);
graphics->SetShaderParameter(VSP_LIGHTMATRICES, shadowMatrices[0].Data(), 16 * numSplits);
}
break;
case LIGHT_SPOT:
{
Matrix4 shadowMatrices[2];
CalculateSpotMatrix(shadowMatrices[0], light);
bool isShadowed = shadowMap && graphics->HasTextureUnit(TU_SHADOWMAP);
if (isShadowed)
CalculateShadowMatrix(shadowMatrices[1], lightQueue_, 0, renderer);
graphics->SetShaderParameter(VSP_LIGHTMATRICES, shadowMatrices[0].Data(), isShadowed ? 32 : 16);
示例4: main
int main(){
try{
ILogger::Init();
Settings::Call().Parse();
ResourceManager::Call().AddPath("Data/shaders", "Shader");
ResourceManager::Call().AddPath("Data/textures", "Image");
{
Window myWindow;
Image Crate;
Texture CrateTexture;
Text FPSText, MousePosText;
Clock FrameClock, FpsClock;
Input myInput;
myInput.Init(myWindow);
Renderer& myRenderer = Renderer::Call();
myRenderer.Init(myWindow);
Crate.LoadFromFile("crate.jpg");
CrateTexture.LoadFromImage(Crate);
Light l;
l.SetPosition(Vector3F(1,3,1.5));
l.SetDiffuse(Color(1.f,1.f,1.f));
l.SetRange(8);
Shader ColorShader;
ColorShader.Compile("shaderColor.vs", "shaderColor.fs");
ColorShader.Bind();
ColorShader.SendColor("ambientColor", myRenderer.GetSpecifications().mAmbientColor);
ColorShader.SendFloat("constantAtt", l.GetAttenuationConstant());
ColorShader.SendFloat("linearAtt", l.GetAttenuationLinear());
ColorShader.SendFloat("quadraticAtt", l.GetAttenuationQuadratic());
ColorShader.SendFloat("range", l.GetRange());
ColorShader.SendVector3("lightPosition", l.GetPosition());
ColorShader.SendColor("lightColor", l.GetDiffuse());
ColorShader.UnBind();
Object obj1;
obj1.MakeCube("cube", ColorShader);
obj1.GetMaterial().mAmbient = Color(0.f, 0.08f, 0.08f);
obj1.GetMaterial().mDiffuse = Color(0.f, 0.8f, 0.8f);
obj1.GetMaterial().mSpecular = Color(0.0f, 0.5f, 0.5f);
obj1.GetMaterial().mShininess = 50.f;
Camera cam;
cam.LookAt(Vector3F(0.5f,0,1), Vector3F(-2.5f,2,4));
FPSText.SetSize(12);
FPSText.SetPosition(10,10);
MousePosText.SetSize(12);
MousePosText.SetPosition(10,22);
while(myWindow.IsOpened()){
ElapsedTime = FrameClock.GetElapsedTime();
FrameClock.Reset();
if(FpsClock.GetElapsedTime() > 1.f){
FPSText.SetText(String(1.f/ElapsedTime));
FpsClock.Reset();
}
while(myInput.GetEvent()){
if(myInput.GetEventType() == sf::Event::Closed)
myWindow.Close();
if(myInput.IsKeyHit(Space))
if(!paused){
paused = true;
FrameClock.Pause();
}else{
paused = false;
FrameClock.Resume();
}
}
MousePosText.SetText(String("X : ")+myInput.GetMouseX()+" Y : "+myInput.GetMouseY());
MousePosText.Draw();
FPSText.Draw();
obj1.Draw();
myRenderer.BeginScene(myRenderer.GetSpecifications().mAmbientColor);
myRenderer.Render();
myRenderer.EndScene();
}
}
}catch(Exception e){
std::cout << e.what() << std::endl;
system("PAUSE");
}
Renderer::Kill();
ResourceManager::Kill();
Settings::Kill();
ILogger::Kill();
//.........这里部分代码省略.........
示例5: GetVisibleLights
void World::GetVisibleLights(Node * node, List<Light*> & lights)
{
profile_code();
lights.Clear();
List<Light*>::Iterator iter;
List<Light*>::Iterator end;
iter = mLights.Begin();
end = mLights.End();
Light * light;
while (iter != end)
{
light = *iter;
if (light->IsVisible())
{
LIGHT_TYPE type = light->GetType();
if (type == LT_DIRECTIONAL)
{
lights.PushBack(light);
}
else if (type == LT_POINT)
{
const Sphere & sph = node->GetWorldBoundingSphere();
float len = Math::VecLength(light->GetPosition() - sph.center);
if (len - sph.radius < light->GetRange())
lights.PushBack(light);
}
else if (type == LT_SPOT)
{
Aabb aabb;
Vec3 ltf, lbf, rtf, rbf;
Vec3 ltb, lbb, rtb, rbb;
Vec3 lp;
float sq1, sq2, sq3, sq4;
float sq5, sq6, sq7, sq8;
float rsq;
Vec3 d1, d2, d3, d4;
Vec3 d5, d6, d7, d8;
Vec3 ld;
float dt1, dt2, dt3, dt4;
float dt5, dt6, dt7, dt8;
float mdt;
aabb = node->GetWorldAabb();
ltf = aabb.GetLeftTopFrontPoint();
lbf = aabb.GetLeftBottomFrontPoint();
rtf = aabb.GetRightTopFrontPoint();
rbf = aabb.GetRightBottomFrontPoint();
ltb = aabb.GetLeftTopBackPoint();
lbb = aabb.GetLeftBottomBackPoint();
rtb = aabb.GetRightTopBackPoint();
rbb = aabb.GetRightBottomBackPoint();
lp = light->GetPosition();
rsq = light->GetRange() * light->GetRange();
sq1 = Math::VecDistanceSq(lp, ltf);
sq2 = Math::VecDistanceSq(lp, lbf);
sq3 = Math::VecDistanceSq(lp, rtf);
sq4 = Math::VecDistanceSq(lp, rbf);
sq5 = Math::VecDistanceSq(lp, ltb);
sq6 = Math::VecDistanceSq(lp, lbb);
sq7 = Math::VecDistanceSq(lp, rtb);
sq8 = Math::VecDistanceSq(lp, rbb);
if (sq1 < rsq || sq2 < rsq || sq3 < rsq || sq4 < rsq ||
sq5 < rsq || sq6 < rsq || sq7 < rsq || sq8 < rsq)
{
ld = light->GetDirection();
mdt = light->GetOuter();
d1 = ltf - lp;
d2 = lbf - lp;
d3 = rtf - lp;
d4 = rbf - lp;
d5 = ltb - lp;
d6 = lbb - lp;
d7 = rtb - lp;
d8 = rbb - lp;
Math::VecNormalize(d1, d1);
Math::VecNormalize(d2, d2);
Math::VecNormalize(d3, d3);
Math::VecNormalize(d4, d4);
Math::VecNormalize(d5, d5);
Math::VecNormalize(d6, d6);
Math::VecNormalize(d7, d7);
Math::VecNormalize(d8, d8);
//.........这里部分代码省略.........