本文整理汇总了C++中Vec3f函数的典型用法代码示例。如果您正苦于以下问题:C++ Vec3f函数的具体用法?C++ Vec3f怎么用?C++ Vec3f使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Vec3f函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
UNNAMESPACE_BEGIN
UNNAMESPACE_END
NAMESPACE_BEGIN
/*==============================================================================
CLASS ParametricPatch
==============================================================================*/
#define APPROX4
//------------------------------------------------------------------------------
//!
void
ParametricPatch::init( MetaSurface::Patch& p )
{
const uint MAX_VALENCE = 64;
Vec3f f[4][MAX_VALENCE];
Vec3f vring[MAX_VALENCE];
Vec3f vdiag[MAX_VALENCE];
float creases[MAX_VALENCE];
int creasesID[MAX_VALENCE];
Vec3f vlim[4];
Vec3f t0[4];
Vec3f t1[4];
float cn[4];
float sn[4];
int val[4];
// Compute per vertex parameters.
for( uint c = 0; c < 4; ++c )
{
// Retrieve ring vertices and compute valence.
int n = 0;
int cc = c;
int crnum = 0;
MetaSurface::Patch* cp = &p;
do {
//creases[n] = MetaSurface::crease( *cp, cc ) == 0 ? 2.0f/3.0f : 0.0f;
if( MetaSurface::crease( *cp, cc ) == 0 )
{
creases[n] = 2.0f/3.0f;
}
else
{
creasesID[crnum++] = n;
creases[n] = 0.0f;
}
vring[n] = *cp->_controlPts[(cc+1)%4];
vdiag[n++] = *cp->_controlPts[(cc+2)%4];
int ne = (cc+3)%4;
cc = MetaSurface::neighborEdge( *cp, ne );
cp = MetaSurface::neighborPatch( *cp, ne );
} while( cp != &p );
val[c] = n;
Vec3f& v = *p._controlPts[c];
#ifdef APPROX4
if( crnum == 0 )
{
// Compute limite vertex and face vertex.
vlim[c] = Vec3f(0.0f);
for( int i = 0; i < n; ++i )
{
// Face vertex.
f[c][i] = v*(4.0f/9.0f) + (vring[i]+vring[(i+1)%n])*(2.0f/9.0f) + vdiag[i]*(1.0f/9.0f);
// Corner vertex.
vlim[c] += f[c][i];
}
vlim[c] = ( vlim[c]*9.0f/(float)n + v*(float(n)-4.0f) )*(1.0f/(float(n)+5.0f));
// Compute t0 and t1.
Vec3f e0(0.0f);
Vec3f e1(0.0f);
for( int i = 0; i < n; ++i )
{
float angle = CGConstf::pi2()*(float)i/float(n);
Vec3f e = (f[c][i]+f[c][(i-1+n)%n])*0.5f;
e0 += e * CGM::cos(angle);
e1 += e * CGM::sin(angle);
}
cn[c] = CGM::cos( CGConstf::pi2()/float(n) );
sn[c] = CGM::sin( CGConstf::pi2()/float(n) );
float lambda = n == 4 ? 0.5f : ( cn[c] + 5.0f + CGM::sqrt((cn[c]+9.0f)*(cn[c]+1.0f)) ) / 16.0f;
float k = 1.0f/(lambda*float(n));
e0 *= k;
e1 *= k;
t0[c] = vlim[c] + e0;
t1[c] = vlim[c] + e0*cn[c] + e1*sn[c];
}
else
{
// Face and corner vertices.
vlim[c] = Vec3f(0.0f);
for( int i = 0; i < n; ++i )
{
//.........这里部分代码省略.........
示例2: Vec3f
#include <QFile>
#include <QString>
#include <QDebug>
#include <QBuffer>
StelTextureSP Nebula::texCircle;
StelTextureSP Nebula::texGalaxy;
StelTextureSP Nebula::texOpenCluster;
StelTextureSP Nebula::texGlobularCluster;
StelTextureSP Nebula::texPlanetaryNebula;
StelTextureSP Nebula::texDiffuseNebula;
StelTextureSP Nebula::texOpenClusterWithNebulosity;
float Nebula::circleScale = 1.f;
float Nebula::hintsBrightness = 0;
Vec3f Nebula::labelColor = Vec3f(0.4,0.3,0.5);
Vec3f Nebula::circleColor = Vec3f(0.8,0.8,0.1);
Nebula::Nebula() :
M_nb(0),
NGC_nb(0),
IC_nb(0),
C_nb(0)
{
nameI18 = "";
angularSize = -1;
}
Nebula::~Nebula()
{
}
示例3: CubeExample
CubeExample(void)
: cube_instr(make_cube.Instructions())
, cube_indices(make_cube.Indices())
, projection_matrix(prog, "ProjectionMatrix")
, camera_matrix(prog, "CameraMatrix")
, model_matrix(prog, "ModelMatrix")
{
namespace se = oglplus::smart_enums;
// Set the vertex shader source
vs.Source(
"#version 330\n"
"uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;"
"in vec4 Position;"
"in vec3 Normal;"
"in vec2 TexCoord;"
"out vec3 vertNormal;"
"out vec3 vertLight;"
"out vec2 vertTexCoord;"
"uniform vec3 LightPos;"
"void main(void)"
"{"
" vertNormal = mat3(ModelMatrix)*Normal;"
" gl_Position = ModelMatrix * Position;"
" vertLight = LightPos - gl_Position.xyz;"
" vertTexCoord = TexCoord;"
" gl_Position = ProjectionMatrix * CameraMatrix * gl_Position;"
"}"
);
// compile it
vs.Compile();
// set the fragment shader source
fs.Source(
"#version 330\n"
"uniform sampler2D TexUnit;"
"in vec3 vertNormal;"
"in vec3 vertLight;"
"in vec2 vertTexCoord;"
"out vec4 fragColor;"
"void main(void)"
"{"
" float l = length(vertLight);"
" float d = l > 0 ? dot(vertNormal, normalize(vertLight)) / l : 0.0;"
" float i = 0.3 + 2.0*max(d, 0.0);"
" vec4 t = texture(TexUnit, vertTexCoord);"
" fragColor = vec4(t.rgb*i, 1.0);"
"}"
);
// compile it
fs.Compile();
// attach the shaders to the program
prog.AttachShader(vs);
prog.AttachShader(fs);
// link and use it
prog.Link();
prog.Use();
// bind the VAO for the cube
cube.Bind();
verts.Bind(se::Array());
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_cube.Positions(data);
Buffer::Data(se::Array(), data);
(prog|"Position").Setup(n_per_vertex, se::Float()).Enable();
}
normals.Bind(se::Array());
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_cube.Normals(data);
Buffer::Data(se::Array(), data);
(prog|"Normal").Setup(n_per_vertex, se::Float()).Enable();
}
texcoords.Bind(se::Array());
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_cube.TexCoordinates(data);
Buffer::Data(se::Array(), data);
(prog|"TexCoord").Setup(n_per_vertex, se::Float()).Enable();
}
// setup the texture
{
auto bound_tex = Bind(tex, se::_2D());
bound_tex.Image2D(images::LoadTexture("concrete_block"));
bound_tex.MinFilter(se::Linear());
bound_tex.MagFilter(se::Linear());
bound_tex.WrapS(se::Repeat());
bound_tex.WrapT(se::Repeat());
}
// set the uniform values
(prog/"TexUnit") = 0;
(prog/"LightPos") = Vec3f(1.0f, 2.0f, 3.0f);
//
gl.ClearColor(0.1f, 0.1f, 0.1f, 0.0f);
gl.ClearDepth(1.0f);
//.........这里部分代码省略.........
示例4: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
TutorialKeyListener TheKeyListener;
TutorialWindow->addKeyListener(&TheKeyListener);
TutorialMouseListener TheTutorialMouseListener;
TutorialMouseMotionListener TheTutorialMouseMotionListener;
TutorialWindow->addMouseListener(&TheTutorialMouseListener);
TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);
// Create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// Tell the Manager what to manage
mgr->setWindow(TutorialWindow);
//Particle System Material
LineChunkRefPtr PSLineChunk = LineChunk::create();
PSLineChunk->setWidth(1.0f);
BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
MaterialChunkRefPtr PSMaterialChunk = MaterialChunk::create();
PSMaterialChunk->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f));
PSMaterialChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
PSMaterialChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f));
PSMaterialChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);
PSMaterialChunk->setLit(false);
ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
PSMaterial->addChunk(PSLineChunk);
PSMaterial->addChunk(PSMaterialChunk);
PSMaterial->addChunk(PSBlendChunk);
//Particle System
ParticleSystemRefPtr ExampleParticleSystem = ParticleSystem::create();
ExampleParticleSystem->attachUpdateListener(TutorialWindow);
//Create the particles
UInt32 NumParticlesToGenerate(2500);
Distribution3DRefPtr PositionDistribution = createPositionDistribution();
Distribution3DRefPtr NormalDistribution = createNormalDistribution();
Distribution3DRefPtr ColorDistribution = createColorDistribution();
Distribution3DRefPtr SizeDistribution = createSizeDistribution();
Distribution1DRefPtr LifespanDistribution = createLifespanDistribution();
Distribution3DRefPtr VelocityDistribution = createVelocityDistribution();
Distribution3DRefPtr AccelerationDistribution = createAccelerationDistribution();
Pnt3f PositionReturnValue;
Vec3f NormalReturnValue = Vec3f(0.0,0.0f,1.0f);
Color4f ColorReturnValue = Color4f(1.0,1.0f,1.0f, 1.0f);
Vec3f SizeReturnValue;
Time LifespanReturnValue = -1;
Vec3f VelocityReturnValue;
Vec3f AccelerationReturnValue;
for(UInt32 i(0) ; i< NumParticlesToGenerate ; ++i)
{
if(PositionDistribution != NULL)
{
PositionReturnValue.setValue(PositionDistribution->generate().getValues());
}
if(ColorDistribution != NULL)
{
Vec3f ColorRGB = ColorDistribution->generate();
ColorReturnValue.setValuesRGBA(ColorRGB[0],ColorRGB[1],ColorRGB[2],1.0f);
}
if(SizeDistribution != NULL)
{
SizeReturnValue = SizeDistribution->generate();
}
if(LifespanDistribution != NULL)
{
LifespanReturnValue = LifespanDistribution->generate();
}
if(VelocityDistribution != NULL)
{
VelocityReturnValue = VelocityDistribution->generate();
}
ExampleParticleSystem->addParticle(PositionReturnValue,
//.........这里部分代码省略.........
示例5: Vec3f
bool Cylinder::InitAverage(const MiscLib::Vector< Vec3f > &samples)
{
if(samples.size() < 4)
return false;
// estimate axis from covariance of normal vectors
MiscLib::Vector< GfxTL::Vector3Df > normals;
size_t c = samples.size() / 2;
for(size_t i = c; i < samples.size(); ++i)
{
normals.push_back(GfxTL::Vector3Df(samples[i]));
normals.push_back(GfxTL::Vector3Df(-samples[i]));
}
GfxTL::MatrixXX< 3, 3, float > cov, eigenVectors;
GfxTL::Vector3Df eigenValues;
GfxTL::CovarianceMatrix(GfxTL::Vector3Df(0, 0, 0),
normals.begin(), normals.end(), &cov);
GfxTL::Jacobi(cov, &eigenValues, &eigenVectors);
// find the minimal eigenvalue and corresponding vector
float minEigVal = eigenValues[0];
unsigned int minEigIdx = 0;
for(unsigned int i = 1; i < 3; ++i)
if(eigenValues[i] < minEigVal)
{
minEigVal = eigenValues[i];
minEigIdx = i;
}
m_axisDir = Vec3f(eigenVectors[minEigIdx]);
// get a point on the axis from all pairs
m_axisPos = Vec3f(0, 0, 0);
m_radius = 0;
size_t pointCount = 0;
size_t pairCount = 0;
for(size_t i = 0; i < c - 1; ++i)
for(size_t j = i + 1; j < c; ++j)
{
// project first normal into plane
float l = m_axisDir.dot(samples[i + c]);
Vec3f xdir = samples[i + c] - l * m_axisDir;
xdir.normalize();
Vec3f ydir = m_axisDir.cross(xdir);
ydir.normalize();
// xdir is the x axis in the plane (y = 0) samples[i] is the origin
float lineBnx = ydir.dot(samples[j + c]);
if(abs(lineBnx) < .05f)
continue;
float lineBny = -xdir.dot(samples[j + c]);
// origin of lineB
Vec3f originB = samples[j] - samples[i];
float lineBOx = xdir.dot(originB);
float lineBOy = ydir.dot(originB);
float lineBd = lineBnx * lineBOx + lineBny * lineBOy;
// lineB in the plane complete
// point of intersection is y = 0 and x = lineBd / lineBnx
float radius = lineBd / lineBnx;
m_axisPos += samples[i] + radius * xdir;
m_radius += abs(radius);
m_radius += std::sqrt((radius - lineBOx) * (radius - lineBOx) + lineBOy * lineBOy);
++pointCount;
}
if(!pointCount)
return false;
m_axisPos /= pointCount;
m_radius /= pointCount * 2;
if(m_radius > 1e6)
return false;
// find point on axis closest to origin
float lambda = m_axisDir.dot(-m_axisPos);
m_axisPos = m_axisPos + lambda * m_axisDir;
m_hcs.FromNormal(m_axisDir);
m_angularRotatedRadians = 0;
return true;
}
示例6:
Strip::Strip(std::vector<unsigned int> && i)
{
m_indexbuffer.reserve(i.size());
for (auto it=i.begin(),end=i.end() ; it!=end ; ++it)
m_indexbuffer.push_back(std::make_pair<>(*it,Vec3f()));
}
示例7: main
// Initialize GLUT & OpenSG and set up the rootNode
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindowEventProducer = createDefaultWindowEventProducer();
WindowPtr MainWindow = TutorialWindowEventProducer->initWindow();
TutorialWindowEventProducer->setDisplayCallback(display);
TutorialWindowEventProducer->setReshapeCallback(reshape);
TutorialKeyListener TheKeyListener;
TutorialWindowEventProducer->addKeyListener(&TheKeyListener);
TutorialMouseListener TheTutorialMouseListener;
TutorialMouseMotionListener TheTutorialMouseMotionListener;
TutorialWindowEventProducer->addMouseListener(&TheTutorialMouseListener);
TutorialWindowEventProducer->addMouseMotionListener(&TheTutorialMouseMotionListener);
// Create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// Tell the Manager what to manage
mgr->setWindow(TutorialWindowEventProducer->getWindow());
//Make Torus Node
TriGeometryBase = makeTorus(.55, 1.5, 16, 16);
//Make Main Scene Node
NodePtr scene = makeCoredNode<Group>();
setName(scene, "scene");
rootNode = Node::create();
setName(rootNode, "rootNode");
ComponentTransformPtr Trans;
Trans = ComponentTransform::create();
beginEditCP(rootNode, Node::CoreFieldMask | Node::ChildrenFieldMask);
rootNode->setCore(Trans);
// add the torus as a child
rootNode->addChild(scene);
endEditCP (rootNode, Node::CoreFieldMask | Node::ChildrenFieldMask);
//Setup Physics Scene
physicsWorld = PhysicsWorld::create();
beginEditCP(physicsWorld, PhysicsWorld::WorldContactSurfaceLayerFieldMask |
PhysicsWorld::AutoDisableFlagFieldMask |
PhysicsWorld::AutoDisableTimeFieldMask |
PhysicsWorld::WorldContactMaxCorrectingVelFieldMask |
PhysicsWorld::GravityFieldMask);
physicsWorld->setWorldContactSurfaceLayer(0.005);
physicsWorld->setAutoDisableFlag(1);
physicsWorld->setAutoDisableTime(0.75);
physicsWorld->setWorldContactMaxCorrectingVel(100.0);
physicsWorld->setGravity(Vec3f(0.0, 0.0, -9.81));
endEditCP(physicsWorld, PhysicsWorld::WorldContactSurfaceLayerFieldMask |
PhysicsWorld::AutoDisableFlagFieldMask |
PhysicsWorld::AutoDisableTimeFieldMask |
PhysicsWorld::WorldContactMaxCorrectingVelFieldMask |
PhysicsWorld::GravityFieldMask);
//Create the Collision Space
physicsSpace = PhysicsHashSpace::create();
//Setup the default collision parameters
CollisionContactParametersPtr DefaultCollisionParams = CollisionContactParameters::createEmpty();
beginEditCP(DefaultCollisionParams);
DefaultCollisionParams->setMode(dContactApprox1);
DefaultCollisionParams->setMu(0.3);
DefaultCollisionParams->setMu2(0.0);
DefaultCollisionParams->setBounce(0.0);
DefaultCollisionParams->setBounceSpeedThreshold(0.0);
DefaultCollisionParams->setSoftCFM(0.1);
DefaultCollisionParams->setSoftERP(0.2);
DefaultCollisionParams->setMotion1(0.0);
DefaultCollisionParams->setMotion2(0.0);
DefaultCollisionParams->setMotionN(0.0);
DefaultCollisionParams->setSlip1(0.0);
DefaultCollisionParams->setSlip2(0.0);
endEditCP(DefaultCollisionParams);
beginEditCP(physicsSpace, PhysicsSpace::DefaultCollisionParametersFieldMask);
physicsSpace->setDefaultCollisionParameters(DefaultCollisionParams);
endEditCP(physicsSpace, PhysicsSpace::DefaultCollisionParametersFieldMask);
//Bouncy Sphere collision parameters
CollisionContactParametersPtr BouncySphereCollisionParams = CollisionContactParameters::createEmpty();
beginEditCP(BouncySphereCollisionParams);
BouncySphereCollisionParams->setMode(dContactApprox1 | dContactBounce);
BouncySphereCollisionParams->setMu(0.3);
BouncySphereCollisionParams->setMu2(0.0);
BouncySphereCollisionParams->setBounce(0.8);
BouncySphereCollisionParams->setBounceSpeedThreshold(0.1);
BouncySphereCollisionParams->setSoftCFM(0.1);
BouncySphereCollisionParams->setSoftERP(0.2);
BouncySphereCollisionParams->setMotion1(0.0);
BouncySphereCollisionParams->setMotion2(0.0);
BouncySphereCollisionParams->setMotionN(0.0);
BouncySphereCollisionParams->setSlip1(0.0);
//.........这里部分代码省略.........
示例8: AddFlare
void AddFlare(const Vec2s & pos, float sm, short typ, Entity * io, bool bookDraw) {
long i;
for(i = 0; i < MAX_FLARES; i++) {
if(!magicFlares[i].exist) {
break;
}
}
if(i >= MAX_FLARES) {
return;
}
FLARES * fl = &magicFlares[i];
fl->exist = 1;
flarenum++;
if(!bookDraw)
fl->bDrawBitmap = 0;
else
fl->bDrawBitmap = 1;
fl->io = io;
if(io) {
fl->flags = 1;
io->flarecount++;
} else {
fl->flags = 0;
}
fl->x = float(pos.x) - rnd() * 4.f;
fl->y = float(pos.y) - rnd() * 4.f - 50.f;
fl->tv.rhw = fl->v.rhw = 1.f;
fl->tv.specular = fl->v.specular = 1;
if(!bookDraw) {
EERIE_CAMERA ka = *Kam;
ka.angle = Anglef(360.f, 360.f, 360.f) - ka.angle;
EERIE_CAMERA * oldcam = ACTIVECAM;
SetActiveCamera(&ka);
PrepareCamera(&ka);
fl->v.p += ka.orgTrans.pos;
EE_RTP(&fl->tv, &fl->v);
fl->v.p += ka.orgTrans.pos;
float vx = -(fl->x - subj.center.x) * 0.2173913f;
float vy = (fl->y - subj.center.y) * 0.1515151515151515f;
if(io) {
fl->v.p.x = io->pos.x - EEsin(radians(MAKEANGLE(io->angle.getPitch() + vx))) * 100.f;
fl->v.p.y = io->pos.y + EEsin(radians(MAKEANGLE(io->angle.getYaw() + vy))) * 100.f - 150.f;
fl->v.p.z = io->pos.z + EEcos(radians(MAKEANGLE(io->angle.getPitch() + vx))) * 100.f;
} else {
fl->v.p.x = float(pos.x - (g_size.width() / 2)) * 150.f / float(g_size.width());
fl->v.p.y = float(pos.y - (g_size.height() / 2)) * 150.f / float(g_size.width());
fl->v.p.z = 75.f;
ka = *oldcam;
SetActiveCamera(&ka);
PrepareCamera(&ka);
float temp = (fl->v.p.y * -ka.orgTrans.xsin) + (fl->v.p.z * ka.orgTrans.xcos);
fl->v.p.y = (fl->v.p.y * ka.orgTrans.xcos) - (-fl->v.p.z * ka.orgTrans.xsin);
fl->v.p.z = (temp * ka.orgTrans.ycos) - (-fl->v.p.x * ka.orgTrans.ysin);
fl->v.p.x = (temp * -ka.orgTrans.ysin) + (fl->v.p.x * ka.orgTrans.ycos);
fl->v.p += oldcam->orgTrans.pos;
}
fl->tv.p = fl->v.p;
SetActiveCamera(oldcam);
PrepareCamera(oldcam);
} else {
fl->tv.p = Vec3f(fl->x, fl->y, 0.001f);
}
switch(PIPOrgb) {
case 0: {
fl->rgb = Color3f(rnd() * (2.f/3) + .4f, rnd() * (2.f/3), rnd() * (2.f/3) + .4f);
break;
}
case 1: {
fl->rgb = Color3f(rnd() * .625f + .5f, rnd() * .625f + .5f, rnd() * .55f);
break;
}
case 2: {
fl->rgb = Color3f(rnd() * (2.f/3) + .4f, rnd() * .55f, rnd() * .55f);
break;
}
}
if(typ == -1) {
float zz = (EERIEMouseButton & 1) ? 0.29f : ((sm > 0.5f) ? rnd() : 1.f);
if(zz < 0.2f) {
fl->type = 2;
fl->size = rnd() * 42.f + 42.f;
fl->tolive = (800.f + rnd() * 800.f) * FLARE_MUL;
} else if(zz < 0.5f) {
fl->type = 3;
fl->size = rnd() * 52.f + 16.f;
fl->tolive = (800.f + rnd() * 800.f) * FLARE_MUL;
} else {
fl->type = 1;
fl->size = (rnd() * 24.f + 32.f) * sm;
fl->tolive = (1700.f + rnd() * 500.f) * FLARE_MUL;
}
//.........这里部分代码省略.........
示例9: Vec3f
//没用 weight
Vec3f RayTracer::traceRay(Ray &ray, float tmin, int bounces, float indexOfRefraction, Hit &hit, Grid *grid) const
{
if(bounces >= max_bounces)
return Vec3f(0,0,0);
RayTracingStats::IncrementNumNonShadowRays();
//Group *group = s->getGroup();
//group->intersect(ray,hit,tmin); 这里是没用grid的代码
grid->intersect(ray,hit,tmin);
if(hit.getMaterial()==NULL)
return s->getBackgroundColor();
else
{
RayTracingStats::IncrementNumShadowRays();
Vec3f col(0,0,0);
Vec3f hitPoint = hit.getIntersectionPoint();
Vec3f tempAmb;
Vec3f::MultRow(tempAmb,s->getAmbientLight(),hit.getMaterial()->getDiffuse(hitPoint)); //Kd La
col += tempAmb;
int lightNumber = s->getNumLights();
Light *light;
for(int i=0; i<lightNumber; i++)
{
light = s->getLight(i);
Vec3f lightColor;
Vec3f dirToLight;
//Vec3f interPoint = hit.getIntersectionPoint();
float distanceToLight;
light->getIllumination(hitPoint,dirToLight,lightColor,distanceToLight);
if(!castShadowRayGrid(hitPoint-ray.getDirection()*EPSILON,dirToLight,distanceToLight,grid))
{
Vec3f tempShade = hit.getMaterial()->Shade(ray,hit,dirToLight,lightColor); //diffuse specular
col += tempShade;
}
}
if(hit.getMaterial()->isReflect(hitPoint))
{
Ray rayReflect(mirrorDirection(hit.getNormal(),ray.getDirection()),hitPoint);
Vec3f tempRefl;
Hit hit2(1000,NULL,Vec3f(1,1,1));
Vec3f::MultRow(tempRefl,hit.getMaterial()->getReflect(hitPoint),traceRay(rayReflect,tmin,bounces+1,indexOfRefraction,hit2,grid)); //weight,indexOfRefrection
col += tempRefl;
}
if(hit.getMaterial()->isTransparent(hitPoint))
{
bool notTotalReflective;
Vec3f transmittedDir;
if(ray.getDirection().Dot3(hit.getNormal())>0) //ray is inside the object
{
notTotalReflective = transmittedDirection(hit.getNormal()*(-1.0f),ray.getDirection(),hit.getMaterial()->getIndexOfRefrac(hitPoint),indexOfRefraction,transmittedDir);
}
else //outside
{
notTotalReflective = transmittedDirection(hit.getNormal(),ray.getDirection(),indexOfRefraction,hit.getMaterial()->getIndexOfRefrac(hitPoint),transmittedDir);
}
if(notTotalReflective)
{
Ray rayTransparent(transmittedDir,hitPoint);
Vec3f tempTrans;
Hit hit3(10000,NULL,Vec3f(1,1,1));
Vec3f::MultRow(tempTrans,hit.getMaterial()->getTrans(hitPoint),traceRay(rayTransparent,tmin,bounces+1,indexOfRefraction,hit3,grid));
col += tempTrans;
}
else
{
Vec3f tempTotalTrans;
Vec3f::MultRow(tempTotalTrans,hit.getMaterial()->getTrans(hitPoint),hit.getMaterial()->getDiffuse(hitPoint));
col += tempTotalTrans;
}
}
return col;
}
}
示例10: r
//grid castShadowRay
bool RayTracer::castShadowRayGrid(Vec3f point, Vec3f lightDir, float distanceToLight, Grid *grid) const
{
Ray r(lightDir,point);
Hit hit(distanceToLight,NULL,Vec3f(1,1,1));
return grid->shadowIntersect(r,hit,EPSILON); //又是因为这里没加EPSILON,又出现了影子的乱点情况
}
示例11: inputWindowMins
//---------------------------------------------------------------------------
void DeveloperConsole::RenderConsole( const unsigned int shaderProgramID )
{
float inputBoxOffset = 5.f;
Vertex3D vertices[ 8 ];
Vec2f inputWindowMins( 0.f, 0.f );
Vec2f inputWindowMaxes( GAME_WINDOW_X, m_fontCellHeight + inputBoxOffset );
Vec2f logWindowMins( 0.f, m_fontCellHeight + inputBoxOffset * 2.f );
Vec2f logWindowMaxes( GAME_WINDOW_X, GAME_WINDOW_Y );
Rgba windowColor( 0, 0, 0, 125 );
Rgba commandTextColor( Colors::WHITE );
// g_theRenderer->VennLoadIdentity();
// g_theRenderer->VennOrtho( 0.f, GAME_WINDOW_X, 0.f, GAME_WINDOW_Y, 0.f, 1.f );
// g_theRenderer->ApplyOrthoProjection( 0.f, GAME_WINDOW_X, 0.f, GAME_WINDOW_Y, 0.f, 1.f );
// the input window
vertices[ 0 ].m_position = Vec3f( inputWindowMins.x, inputWindowMins.y, 0.f );
vertices[ 0 ].m_color = windowColor;
vertices[ 1 ].m_position = Vec3f( inputWindowMins.x, inputWindowMaxes.y, 0.f );
vertices[ 1 ].m_color = windowColor;
vertices[ 2 ].m_position = Vec3f( inputWindowMaxes.x, inputWindowMaxes.y, 0.f );
vertices[ 2 ].m_color = windowColor;
vertices[ 3 ].m_position = Vec3f( inputWindowMaxes.x, inputWindowMins.y, 0.f );
vertices[ 3 ].m_color = windowColor;
// render the log window
vertices[ 4 ].m_position = Vec3f( logWindowMins.x, logWindowMins.y, 0.f );
vertices[ 4 ].m_color = windowColor;
vertices[ 5 ].m_position = Vec3f( logWindowMins.x, logWindowMaxes.y, 0.f );
vertices[ 5 ].m_color = windowColor;
vertices[ 6 ].m_position = Vec3f( logWindowMaxes.x, logWindowMaxes.y, 0.f );
vertices[ 6 ].m_color = windowColor;
vertices[ 7 ].m_position = Vec3f( logWindowMaxes.x, logWindowMins.y, 0.f );
vertices[ 7 ].m_color = windowColor;
// g_theRenderer->VennEnableClientState( V_VERTEX_ARRAY );
// g_theRenderer->VennEnableClientState( V_COLOR_ARRAY );
//
// g_theRenderer->VennVertexPointer( 3, V_FLOAT, sizeof( Vertex3D ), &vertices[0].m_position );
// g_theRenderer->VennColorPointer( 4, V_FLOAT, sizeof( Vertex3D ), &vertices[0].m_color );
//
// g_theRenderer->VennDrawArrays( V_QUADS, 0, 8 );
//
// g_theRenderer->VennDisableClientState( V_VERTEX_ARRAY );
// g_theRenderer->VennDisableClientState( V_COLOR_ARRAY );
RenderVertexArrayWithShader( vertices, 8, shaderProgramID, V_QUADS );
// render current command string
m_textRenderer->RenderText2D( m_currentConsoleCommandString.c_str(), m_fontCellHeight, Vec2f( inputWindowMins.x, inputWindowMins.y ), commandTextColor, shaderProgramID );
// render log lines
for ( unsigned int index = m_logLines.size(); index > 0; --index )
{
if ( logWindowMins.y >= GAME_WINDOW_Y ) break;
CommandLogLine& currentLine = m_logLines[ index - 1 ];
m_textRenderer->RenderText2D( currentLine.m_text.c_str(), m_fontCellHeight, logWindowMins, currentLine.m_color, shaderProgramID );
logWindowMins.y += m_fontCellHeight + inputBoxOffset;
}
}
示例12:
TestGrouping::TestGrouping()
{
m_aabb.SetCenter(Vec3f(0.0f, 16.0f, 0.0f));
m_aabb.SetHalfDims(Vec3f(100.0f, 0.1f, 100.0f));
}
示例13: Vec3f
template<> Vec3f CoronaLoader::load<Vec3f>(const Ref<XML>& xml) {
if (xml->body.size() < 3) THROW_RUNTIME_ERROR(xml->loc.str()+": wrong float3 body");
return Vec3f(xml->body[0].Float(),xml->body[1].Float(),xml->body[2].Float());
}
示例14: CubeExample
//.........这里部分代码省略.........
"void main(void)"
"{"
" vertNormal = ("
" ModelMatrix *"
" vec4(-Normal, 0.0)"
" ).xyz;"
" vertLight = ("
" vec4(LightPos, 0.0)-"
" ModelMatrix * Position"
" ).xyz;"
" vertTexCoord = "
" TexProjectionMatrix *"
" ModelMatrix *"
" Position;"
" gl_Position = "
" ProjectionMatrix *"
" CameraMatrix *"
" ModelMatrix *"
" Position;"
"}"
);
// compile it
vs.Compile();
// set the fragment shader source
fs.Source(
"#version 330\n"
"uniform sampler2D TexUnit;"
"in vec3 vertNormal;"
"in vec3 vertLight;"
"in vec4 vertTexCoord;"
"out vec4 fragColor;"
"void main(void)"
"{"
" float l = length(vertLight);"
" float d = l != 0.0 ? dot("
" vertNormal, "
" normalize(vertLight)"
" ) / l : 0.0;"
" float i = 0.1 + 4.2*max(d, 0.0);"
" vec2 coord = vertTexCoord.st/vertTexCoord.q;"
" vec4 t = texture(TexUnit, coord*0.5 + 0.5);"
" fragColor = vec4(t.rgb*i*sqrt(1.0-t.a), 1.0);"
"}"
);
// compile it
fs.Compile();
// attach the shaders to the program
prog.AttachShader(vs);
prog.AttachShader(fs);
// link and use it
prog.Link();
prog.Use();
// bind the VAO for the cube
cube.Bind();
verts.Bind(Buffer::Target::Array);
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_cube.Positions(data);
Buffer::Data(Buffer::Target::Array, data);
VertexArrayAttrib attr(prog, "Position");
attr.Setup<GLfloat>(n_per_vertex);
attr.Enable();
}
normals.Bind(Buffer::Target::Array);
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_cube.Normals(data);
Buffer::Data(Buffer::Target::Array, data);
VertexArrayAttrib attr(prog, "Normal");
attr.Setup<GLfloat>(n_per_vertex);
attr.Enable();
}
// setup the texture
gl.Direct(Texture::Target::_2D, tex)
.Image2D(images::LoadTexture("flower_glass"))
.GenerateMipmap()
.BorderColor(Vec4f(1.0f, 1.0f, 1.0f, 0.0f))
.MinFilter(TextureMinFilter::LinearMipmapLinear)
.MagFilter(TextureMagFilter::Linear)
.WrapS(TextureWrap::ClampToBorder)
.WrapT(TextureWrap::ClampToBorder)
.Bind();
UniformSampler(prog, "TexUnit").Set(0);
Uniform<Mat4f>(prog, "CameraMatrix").Set(
CamMatrixf::LookingAt(Vec3f(0.0f, 1.0f, 2.0f), Vec3f())
);
gl.ClearColor(0.1f, 0.1f, 0.1f, 0.0f);
gl.ClearDepth(1.0f);
gl.Enable(Capability::DepthTest);
gl.Enable(Capability::CullFace);
gl.FrontFace(make_cube.FaceWinding());
}
示例15: Vec3f
void IgnitSpell::Launch()
{
m_duration = 500;
if(m_hand_group != -1) {
m_srcPos = m_hand_pos;
} else {
m_srcPos = m_caster_pos - Vec3f(0.f, 50.f, 0.f);
}
LightHandle id = GetFreeDynLight();
if(lightHandleIsValid(id)) {
EERIE_LIGHT * light = lightHandleGet(id);
light->intensity = 1.8f;
light->fallend = 450.f;
light->fallstart = 380.f;
light->rgb = Color3f(1.f, 0.75f, 0.5f);
light->pos = m_srcPos;
light->duration = 300;
}
float fPerimeter = 400.f + m_level * 30.f;
m_lights.clear();
m_elapsed = 0;
CheckForIgnition(m_srcPos, fPerimeter, 1, 1);
for(size_t ii = 0; ii < MAX_LIGHTS; ii++) {
EERIE_LIGHT * light = GLight[ii];
if(!light || !(light->extras & EXTRAS_EXTINGUISHABLE)) {
continue;
}
if(m_caster == PlayerEntityHandle && (light->extras & EXTRAS_NO_IGNIT)) {
continue;
}
if(!(light->extras & EXTRAS_SEMIDYNAMIC)
&& !(light->extras & EXTRAS_SPAWNFIRE)
&& !(light->extras & EXTRAS_SPAWNSMOKE)) {
continue;
}
if(light->m_ignitionStatus) {
continue;
}
if(!fartherThan(m_srcPos, light->pos, fPerimeter)) {
T_LINKLIGHTTOFX entry;
entry.iLightNum = ii;
entry.poslight = light->pos;
entry.idl = GetFreeDynLight();
if(lightHandleIsValid(entry.idl)) {
EERIE_LIGHT * light = lightHandleGet(entry.idl);
light->intensity = 0.7f + 2.f * rnd();
light->fallend = 400.f;
light->fallstart = 300.f;
light->rgb = Color3f(1.f, 1.f, 1.f);
light->pos = entry.poslight;
}
m_lights.push_back(entry);
}
}
for(size_t n = 0; n < MAX_SPELLS; n++) {
SpellBase * spell = spells[SpellHandle(n)];
if(!spell) {
continue;
}
if(spell->m_type == SPELL_FIREBALL) {
CSpellFx * pCSpellFX = spell->m_pSpellFx;
if(pCSpellFX) {
CFireBall * pCF = (CFireBall *)pCSpellFX;
float radius = std::max(m_level * 2.f, 12.f);
if(closerThan(m_srcPos, pCF->eCurPos,
fPerimeter + radius)) {
spell->m_level += 1;
}
}
}
}
}