本文整理汇总了C++中Vec3f::Set方法的典型用法代码示例。如果您正苦于以下问题:C++ Vec3f::Set方法的具体用法?C++ Vec3f::Set怎么用?C++ Vec3f::Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vec3f
的用法示例。
在下文中一共展示了Vec3f::Set方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rasterizeSphere
void Grid::rasterizeSphere(Vec3f center, float radius)
{
Vec3f coord;
for (int i = 0; i < num_x; ++i)
{
for (int j = 0; j < num_y; ++j)
{
for (int k = 0; k < num_z; ++k)
{
coord.Set ( min_coor[0] + (i + 0.5f) * del_x,
min_coor[1] + (j + 0.5f) * del_y,
min_coor[2] + (k + 0.5f) * del_z );
if ( (coord - center).Length() <= radius )
{
voxels[num_y * num_z * i + num_z * j + k] = true;
}
else
{
voxels[num_y * num_z * i + num_z * j + k] = false;
}
}
}
}
return;
}
示例2: QtpickColor
bool Draw::QtpickColor(Vec3f& col) {
QColor qcol = QColorDialog::getColor(getCurrColor());
if (!qcol.isValid()) return false;
col.Set(float(qcol.red())/255.,
float(qcol.green())/255.,
float(qcol.blue())/255.);
return true;
}
示例3: rayTrace
Vec3f scene::rayTrace(Vec3f eye, Vec3f dir, int recurseDepth)
{
//start with black, add color as we go
Vec3f answer(0,0,0);
//test for intersection against all our objects
float dist = myObjGroup->testIntersections(eye, dir);
//if we saw nothing, return the background color of our scene
if (dist==9999999)
return bgColor;
Vec3f textureColor;
//get the material index and normal vector(at the point we saw) of the object we saw
int matIndex = myObjGroup->getClosest()->getMatIndex();
Vec3f normal = myObjGroup->getClosest()->getNormal(eye, dir * dist);
//determine texture color
if (myMaterials.at(matIndex).texture==NULL)
//this is multiplicative, rather than additive
//so if there is no texture, just use ones
textureColor.Set(1,1,1);
else
{
//if there is a texture image, ask the object for the image coordinates (between 0 and 1)
Vec3f coords = myObjGroup->getClosest()->getTextureCoords(eye, dir * dist);
//get the color from that image location
textureColor.Set(
PIC_PIXEL(myMaterials.at(matIndex).texture,(int)(myMaterials.at(matIndex).texture->nx*coords.x()),(int)(myMaterials.at(matIndex).texture->ny*coords.y()),0),
PIC_PIXEL(myMaterials.at(matIndex).texture,(int)(myMaterials.at(matIndex).texture->nx*coords.x()),(int)(myMaterials.at(matIndex).texture->ny*coords.y()),1),
PIC_PIXEL(myMaterials.at(matIndex).texture,(int)(myMaterials.at(matIndex).texture->nx*coords.x()),(int)(myMaterials.at(matIndex).texture->ny*coords.y()),2));
textureColor = textureColor*(1/255.0);
}
// add ambient light/color to our answer
answer += multiplyColorVectors(ambLight, myMaterials.at(matIndex).diffuseCol);
// set point slightly above the actual surface, prevents
// issues with that point intersecting itself
Vec3f point = eye + (dir * dist) + (normal * .0001);
Vec3f real_point = eye + (dir * dist);
// get the diffuse color of our material
Vec3f diffuseColor = myMaterials.at(matIndex).diffuseCol;
// iterate through lights
for (int iter = 0; iter < myLights.size(); iter++) {
Vec3f lightPos = myLights.at(iter).position;
Vec3f direction= lightPos - point;
direction.Normalize();
float distance = myObjGroup->testIntersections(point, direction);
// if nothing between point and light
if (distance == 9999999) {
Vec3f color = multiplyColorVectors(diffuseColor, myLights.at(iter).color);
float nl = abs(direction.Dot3(normal));
answer += (color * nl);
// now do the specular
// we need vector that goes from point to eye
Vec3f backDir = dir * -1.0f;
Vec3f h = (backDir + direction);
h.Normalize();
Vec3f Cp = myMaterials.at(matIndex).specularCol;
float p = myMaterials.at(matIndex).shininess;
float nh = abs(normal.Dot3(h));
nh = pow(nh, p);
answer += multiplyColorVectors(myLights.at(iter).color, Cp) * nh;
}
}
//if the light can see the surface point,
//add its diffuse color to a total diffuse for the point (using our illumination model)
//use testIntersection to help decide this
//add the diffuse light times the accumulated diffuse light to our answer
if (recurseDepth < 3) {
Vec3f e = dir * -1.0f;
e.Normalize();
Vec3f r = dir + normal * 2.0f * e.Dot3(normal);
r.Normalize();
Vec3f bounced = rayTrace(point, r, recurseDepth + 1);
answer += (multiplyColorVectors(bounced, myMaterials.at(matIndex).reflectiveCol));
// refraction
Vec3f transparentColor = myMaterials.at(matIndex).transparentCol;
float transpar = transparentColor.Dot3(transparentColor);
if (transpar > 0.0f) {
float exitAngle, entryAngle;
//.........这里部分代码省略.........
示例4: initialRayMarch
void Grid::initialRayMarch(MarchingInfo &mi, const Ray &r, float tmin) const
{
Vec3f rayOri = r.getOrigin();
Vec3f rayDir = r.getDirection();
float tbottom,ttop,tfront,tback,tleft,tright,tc;
float dtx,dty,dtz;
int celli,cellj,cellk;
float tnext_x,tnext_y,tnext_z;
int signx,signy,signz;
signx = (rayDir.x()>=0) ? 1 : -1;
signy = (rayDir.y()>=0) ? 1 : -1;
signz = (rayDir.z()>=0) ? 1 : -1;
//需要求绝对值 这里rayDir.x()等于0没有处理
dtx = abs(dx / rayDir.x());
dty = abs(dy / rayDir.y());
dtz = abs(dz / rayDir.z());
Vec3f normal;
Vec3f rayOriTmin = rayOri + rayDir * tmin;
//这里临界值要注意
//inside;
if(max.x()>rayOriTmin.x()&&min.x()<rayOriTmin.x()&&max.y()>rayOriTmin.y()&&min.y()<rayOriTmin.y()&&max.z()>rayOriTmin.z()&&min.z()<rayOriTmin.z()) //忽略了tmin的作用
{
celli = (int)((rayOriTmin.x()-min.x())/dx);
cellj = (int)((rayOriTmin.y()-min.y())/dy);
cellk = (int)((rayOriTmin.z()-min.z())/dz);
if(Utility::isZero(rayDir.x()))
tnext_x = 10000;
else if(signx == -1) //如果反方向的话,求tnext不需要加signx 谢谢大师提醒
tnext_x = (min.x()+celli*dx-rayOri.x())/rayDir.x();
else
tnext_x = (min.x()+(celli+signx)*dx-rayOri.x())/rayDir.x();
if(Utility::isZero(rayDir.y()))
tnext_y = 10000;
else if(signy == -1)
tnext_y = (min.y()+cellj*dy-rayOri.y())/rayDir.y();
else
tnext_y = (min.y()+(cellj+signy)*dy-rayOri.y())/rayDir.y();
if(Utility::isZero(rayDir.z()))
tnext_z = 10000;
else if(signz == -1)
tnext_z = (min.z()+cellk*dz-rayOri.z())/rayDir.z();
else
tnext_z = (min.z()+(cellk+signz)*dz-rayOri.z())/rayDir.z();
//这里tmin如何修改
mi.Set(0,celli,cellj,cellk,tnext_x,tnext_y,tnext_z,dtx,dty,dtz,signx,signy,signz,normal);
}
else //outside
{
float t1x,t1y,t1z;
float t2x,t2y,t2z;
float tnear,tfar;
if(Utility::isZero(rayDir.x()))
{
tleft = 0;
tright = 10000;
}
else
{
tleft = (min.x()-rayOri.x())/rayDir.x();
tright = (max.x()-rayOri.x())/rayDir.x();
}
if(Utility::isZero(rayDir.y()))
{
tbottom = 0;
ttop = 10000;
}
else
{
tbottom = (min.y()-rayOri.y())/rayDir.y();
ttop = (max.y()-rayOri.y())/rayDir.y();
}
if(Utility::isZero(rayDir.z()))
{
tback = 0;
tfront = 10000;
}
else
{
tback = (min.z()-rayOri.z())/rayDir.z();
tfront = (max.z()-rayOri.z())/rayDir.z();
}
t1x = (signx == 1) ? tleft : tright;
t2x = (signx == 1) ? tright : tleft;
t1y = (signy == 1) ? tbottom : ttop;
t2y = (signy == 1) ? ttop : tbottom;
t1z = (signz == 1) ? tback : tfront;
t2z = (signz == 1) ? tfront : tback;
tnear = Utility::getMax(t1x,t1y,t1z);
tfar = Utility::getMin(t2x,t2y,t2z);
if(tnear>tfar) //miss
{}
else if(tfar<tmin) //behind
//.........这里部分代码省略.........