本文整理汇总了C++中vec3::normalize方法的典型用法代码示例。如果您正苦于以下问题:C++ vec3::normalize方法的具体用法?C++ vec3::normalize怎么用?C++ vec3::normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vec3
的用法示例。
在下文中一共展示了vec3::normalize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setRay
void setRay() {
vert = vec3(0, 1, 0);
hori = vert ^ dir;
dir = dir.normalize();
vert = vert.normalize();
hori = hori.normalize();
hori = hori * ( dir.length() * Tan(Fangle/2) / (Rw/2) );
vert = vert * ( dir.length() * Tan(Fangle/2) / (Rh/2) );
dir = dir - Rw/2 * hori + Rh/2 * vert;
///cout << dir[0] << ", " << dir[1] << ", " << dir[2] << endl;
}
示例2: setup
void EarthquakeApp::setup()
{
gl::Texture earthDiffuse = gl::Texture( loadImage( loadResource( RES_EARTHDIFFUSE ) ) );
gl::Texture earthNormal = gl::Texture( loadImage( loadResource( RES_EARTHNORMAL ) ) );
gl::Texture earthMask = gl::Texture( loadImage( loadResource( RES_EARTHMASK ) ) );
earthDiffuse.setWrap( GL_REPEAT, GL_REPEAT );
earthNormal.setWrap( GL_REPEAT, GL_REPEAT );
earthMask.setWrap( GL_REPEAT, GL_REPEAT );
mStars = gl::Texture( loadImage( loadResource( RES_STARS_PNG ) ) );
mEarthShader = gl::GlslProg( loadResource( RES_PASSTHRU_VERT ), loadResource( RES_EARTH_FRAG ) );
mQuakeShader = gl::GlslProg( loadResource( RES_QUAKE_VERT ), loadResource( RES_QUAKE_FRAG ) );
mCounter = 0.0f;
mCurrentFrame = 0;
mSaveFrames = false;
mShowEarth = true;
mShowText = true;
mShowQuakes = true;
mLightDir = vec3( 0.025f, 0.25f, 1.0f );
mLightDir.normalize();
mPov = POV( this, ci::vec3( 0.0f, 0.0f, 1000.0f ), ci::vec3( 0.0f, 0.0f, 0.0f ) );
mEarth = Earth( earthDiffuse, earthNormal, earthMask );
parseEarthquakes( "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.geojson" );
mEarth.setQuakeLocTip();
}
示例3: dot
bool triangle3<T>::is_front_facing(const vec3<T>& lookDirection) const
{
const vec3<T> n = get_normal();
n.normalize();
const T d = dot(n, lookDirection);
return F32_LOWER_EQUAL_0(d);
}
示例4: randomCirclePoint
vec3 randomCirclePoint(vec3 normal) {
//generate random sphere points and then change the z components so that the
//points are perpendicular to the normal
normal.normalize();
vec3 point = randomSpherePoint();
point[2] = -(point[0]*normal[0] + point[1]*normal[1]) / normal[2];
return point;
}
示例5:
Triangle::Triangle(vec3 v1,vec3 v2, vec3 v3, vec3 n1, vec3 n2, vec3 n3, Material material, Transformation& transformation) {
this->transform = transformation.transform;
this->transformI = transformation.transformI;
this->transformTI = transformation.transformTI;
this->v1 = v1;
this->v2 = v2;
this->v3 = v3;
this->material = material;
this->isSphere=false;
this->n1 = n1.normalize();
this->n2 = n2.normalize();
this->n3 = n3.normalize();
}
示例6:
void draw_stuff(const controls& c, float density)
{
float mx = c.m_mouse_x - 500.0f;
float my = 500.0f - c.m_mouse_y;
vec3 mouse_pos(mx, my, 0);
if (c.m_mouse_right)
{
// Re-compute light direction.
s_light_direction = mouse_pos - s_light_arrow_spot;
s_light_direction.normalize();
// Direction perpendicular to the light.
s_light_right = vec3(s_light_direction.y, -s_light_direction.x, 0);
// Draw a white line to the mouse, so the user can see
// what they're orbiting around.
glColor3f(1, 1, 1);
draw_segment(s_light_arrow_spot, mouse_pos);
}
if (c.m_mouse_left_click)
{
// Add or delete an occluder.
// If we're on an occluder, then delete it.
bool deleted = false;
for (int i = 0; i < s_occluders.size(); i++)
{
if (s_occluders[i].hit(mouse_pos))
{
// Remove this guy.
s_occluders[i] = s_occluders.back();
s_occluders.resize(s_occluders.size() - 1);
deleted = true;
break;
}
}
if (!deleted)
{
// If we didn't delete, then the user want to
// add an occluder.
s_occluders.push_back(occluder(mouse_pos, 20));
}
}
draw_light_arrow();
draw_light_rays(density);
draw_occluders();
// Draw a line at the "near clip plane".
glColor3f(0, 0, 1);
draw_segment(vec3(-1000, s_viewer_y, 0), vec3(1000, s_viewer_y, 0));
draw_frustum();
}
示例7: sample
color sample(PosNormal point)
{
vec3 n = point.n;
n.normalize();
direction.normalize();
float k = n.x*direction.x + n.y*direction.y + n.z*direction.z;
k = k < 0.0f ? 0.0f : k;
return{ col.r*k, col.g*k, col.b*k, 1.0f };
}
示例8: Rotate
void Model::Rotate( float angle, vec3 vector) {
vector.normalize();
float d=sqrt(vector.y*vector.y+vector.z*vector.z);
Matrix m1, m2, m3, m4;
m1.init(), m2.init(), m3.init(), m4.init();
if(d>=1e-10) {
m4.mat[5]=vector.z/d;
m4.mat[6]=vector.y/d;
m4.mat[9]=-vector.y/d;
m4.mat[10]=vector.z/d;
m3.mat[0]=d;
m3.mat[2]=vector.x;
m3.mat[8]=-vector.x;
m3.mat[10]=d;
m1.mat[5]=m4.mat[5];
m1.mat[6]=-m4.mat[6];
m1.mat[9]=-m4.mat[9];
m1.mat[10]=m4.mat[10];
m2.mat[0]=m3.mat[0];
m2.mat[2]=-m3.mat[2];
m2.mat[8]=-m3.mat[8];
m2.mat[10]=m3.mat[10];
m3.MultiMatrix(m4);
m1.MultiMatrix(m2);
m2.init();
m2.mat[0]=cos(angle);
m2.mat[4]=-sin(angle);
m2.mat[1]=sin(angle);
m2.mat[5]=cos(angle);
m1.MultiMatrix(m2);
m1.MultiMatrix(m3);
md_mat.MultiMatrix(m1);
}
else {
m3.mat[0]=d;
m3.mat[2]=vector.x;
m3.mat[8]=-vector.x;
m3.mat[10]=d;
m1.mat[0]=m3.mat[0];
m1.mat[2]=-m3.mat[2];
m1.mat[8]=-m3.mat[8];
m1.mat[10]=m3.mat[10];
m2.mat[0]=cos(angle);
m2.mat[4]=-sin(angle);
m2.mat[1]=sin(angle);
m2.mat[5]=cos(angle);
m1.MultiMatrix(m2);
m1.MultiMatrix(m3);
md_mat.MultiMatrix(m1);
}
}
示例9: get_target_dir
//--------------------------------------------------------------------------------
// get target look at
//--------------------------------------------------------------------------------
bool zz_camera_follow::get_target_dir (vec3& dir)
{
if (!target_) {
dir.set(0, 1, 0);
return false;
}
dir = target_->get_look_at();
dir.normalize();
return true;
}
示例10: getConjugate
// Multiplying a quaternion q with a vector v applies the q-rotation to v
vec3 tgQuaternion::operator* (vec3 v){
v.normalize();
tgQuaternion vecQuat, resQuat;
vecQuat.x = v.x;
vecQuat.y = v.y;
vecQuat.z = v.z;
vecQuat.w = 0.0f;
resQuat = vecQuat * getConjugate();
resQuat = *this * resQuat;
return (vec3(resQuat.x, resQuat.y, resQuat.z));
}
示例11:
void
tgPose::RotateAxis (vec3 r)
{
// tgQuaternion q2;
// q2.fromEuler(rot.x,rot.y,rot.z);
// q = q2 * q;
// q.normalise();
tgQuaternion q2;
float a = r.length ();
r.normalize ();
q2.fromAxis (r, a);
q = q2 * q;
q.normalise ();
}
示例12: getRotationMatrix
// Use Rodriques formula
mat3 getRotationMatrix(vec3 axis, double angle)
{
mat3 R = mat3(vec3(1,0,0),vec3(0,1,0),vec3(0,0,1));
axis = axis.normalize();
for (int i = 0; i < 3; ++i)
{
vec3 currCol = R.col(i);
//currCol = (currCol * cos(angle)) + (mAxis.cross(currCol) * sin(angle)) + (Mat(mAxis_t * currCol).at<double>(0,0) * (1 - cos(angle)) * mAxis);
currCol = (currCol * cos(angle)) + ((axis ^ currCol) * sin(angle)) + ((axis * currCol) * (1 - cos(angle)) * axis);
R[0][i] = currCol[0];
R[1][i] = currCol[1];
R[2][i] = currCol[2];
}
return R;
}
示例13: cos
void mat4::createRotation(vec3 axis, float rad)
{
axis.normalize();
float cosine = cos(rad);
float sine = sin(rad);
elements[0] = cosine + pow(axis.x, 2)*(1-cosine);
elements[1] = axis.x*axis.y*(1 - cosine) - axis.z*sine;
elements[2] = axis.x*axis.z*(1 - cosine) + axis.y*sine;
elements[4] = axis.y*axis.x*(1 - cosine) + axis.z*sine;
elements[5] = cosine + pow(axis.y, 2)*(1 - cosine);
elements[6] = axis.z*axis.y*(1 - cosine) - axis.x*sine;
elements[8] = axis.x*axis.z*(1 - cosine) - axis.y*sine;
elements[9] = axis.z*axis.y*(1 - cosine) + axis.x*sine;
elements[10] = cosine + pow(axis.z, 2)*(1 - cosine);
elements[15] = 1.0f;
}
示例14: intersect
bool World::intersect(Ray & r, double & bestT, vec3 &outn, MaterialInfo &outm) {
double thisT;
Ray w2mRay;
bestT = numeric_limits<double>::infinity();
for (vector<Sphere>::iterator it = _spheres.begin();it != _spheres.end();it++) {
w2mRay = Ray(r);
w2mRay.transform(it->w2m());
thisT = it->intersect(w2mRay);
if (thisT<bestT && thisT>=0){
vec4 p = w2mRay.getPos(thisT);
outn = vec3(it->w2m().transpose() * it->calculateNormal(p),VW);
outn.normalize();
outm = it->getMaterial();
bestT = thisT;
}
}
return bestT < numeric_limits<double>::infinity();
}
示例15: getMatrix
mat33 getMatrix(vec3 vec, double alpha)
{
mat33 res;
mat33 I;
for(int i=0;i<3;++i){
for(int j=0;j<3;++j){
I(i,j)=(i==j)?1.0:.0;
}
}
vec.normalize();
mat33 E=crossProductMat(vec);
//print(E);
//print(I);
//std::cout<<vec.transpose()<<"\n";
res=cos(alpha)*I+(1-cos(alpha))*vec*vec.transpose()-sin(alpha)*E;
return res;
}