本文整理汇总了C++中glm::dot方法的典型用法代码示例。如果您正苦于以下问题:C++ glm::dot方法的具体用法?C++ glm::dot怎么用?C++ glm::dot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类glm
的用法示例。
在下文中一共展示了glm::dot方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fragment
frag_color phong_shader::fragment(
const vec3& bary,
const mat3& verts,
const mat3x2& tex_coords,
const mat3& vert_norms) const
{
auto uv = bary_lerp(tex_coords[0], tex_coords[1], tex_coords[2], bary);
auto normval = normalmap.get_from_ratio(uv[0], uv[1]);
auto norm = normalize(vec3(normval.r - 127.5, normval.g - 127.5, normval.b - 127.5));
// ambient color
TGAColor ambient(5, 5, 5, 255);
// specular color
auto spec_val = specular.get_from_ratio(uv[0], uv[1]).raw[0];
auto r = normalize(reflect(light_dir(), norm));
auto spec_intensity = pow(max(0.0f, dot(r, to_cam)), spec_val);
// diffuse color
float diff_intensity = max(0.0f, dot(to_light(), norm));
auto diff_color = diffuse.get_from_ratio(uv[0], uv[1]);
diff_color.scale(diff_intensity + spec_intensity * .6);
return frag_color {ambient + diff_color, true};
}
示例2: DistancePointPlane
float Line::DistancePointPlane(vec3 Point, Line Plane)
{
float sb, sn, sd;
sn = -dot( Plane.m_directionVector, (Point - Plane.m_position));
sd = dot(Plane.m_directionVector, Plane.m_directionVector);
sb = sn / sd;
vec3 intersection = Point + sb * Plane.m_directionVector;
return DistanceTwoPoints(Point, intersection);
}
示例3: mouseMoveEvent
void GLWidget::mouseMoveEvent(QMouseEvent *event) {
last.x = event->x();
last.y = event->y();
vec3 begin = pointOnVirtualTrackball(first);
vec3 end = pointOnVirtualTrackball(last);
float dotProduct = dot(normalize(begin), normalize(end));
float angle = acos(dotProduct);
vec3 crossP = cross(begin, end);
if(length(crossP) > .00001f)
{
rotationMatrix = rotate(mat4(1.0), angle, normalize(crossP)) * rotationMatrix;
glUseProgram(cubeProg);
glUniformMatrix4fv(cubeRotationMatrixLoc, 1, false, value_ptr(rotationMatrix));
glUseProgram(gridProg);
glUniformMatrix4fv(gridRotationMatrixLoc, 1, false, value_ptr(rotationMatrix));
update();
}
first.x = last.x;
first.y = last.y;
}
示例4: operator
void operator()(Particle* p, const vec2& position, float& t1, float& t2){
const vec2 r = position - p->position;
const float norm2 = dot(r,r);
if (norm2 < kernelRadius2) {
const float tmp = cst * pow(kernelRadius2-norm2,3); // POLY 6
// const float tmp = cst * pow(kernelRadius-sqrt(norm2),3);
t1 += p->massDensity * tmp;
t2 += tmp;
}
}
示例5: ClosestPointsOnTwoLines
void Line::ClosestPointsOnTwoLines(Line l1, Line l2, vec3 &closestPointLine1, vec3 &closestPointLine2)
{
float a = dot(l1.m_directionVector, l1.m_directionVector);
float b = dot(l1.m_directionVector, l2.m_directionVector);
float e = dot(l2.m_directionVector, l2.m_directionVector);
float d = a*e - b*b;
// if lines are not parallel
if(d != 0)
{
vec3 r = l1.m_position - l2.m_position;
float c = dot(l1.m_directionVector, r);
float f = dot(l2.m_directionVector, r);
float s = (b*f - c*e) / d;
float t = (a*f - c*b) / d;
closestPointLine1 = l1.m_position + l1.m_directionVector * s;
closestPointLine2 = l2.m_position + l2.m_directionVector * t;
//std::cout << DistanceTwoPoints(closestPointLine1, closestPointLine2) << std::endl;
}
}
示例6: phillips
/*
* Phillips wave spectrum, equation 40 with modification specified in equation 41
*/
float Ocean::phillips(int n_prime, int m_prime) const
{
// Wavevector
float kx = M_PI * (2 * n_prime - _N) / _length;
float kz = M_PI * (2 * m_prime - _N) / _length;
vec2 k(kx, kz);
// Magnitude of wavevector
float k_length = glm::length(k);
// Wind speed
float w_length = glm::length(_w);
// If wavevector is very small, no need to calculate, just return zero
if (k_length < 0.000001) return 0.0;
// Precaculate k^2 and k^4
float k_length2 = k_length * k_length;
float k_length4 = k_length2 * k_length2;
// Cosine factor - eliminates waves that travel perpendicular to the wind
float k_dot_w = dot(normalize(k), normalize(_w));
float k_dot_w2 = k_dot_w * k_dot_w;
float L = w_length * w_length / _g;
float L2 = L * L;
// Something a bit extra to keep waves from exploding. Not in the paper.
float damping = 0.001;
float l2 = L2 * damping * damping;
// Phillips spectrum as described in eqn 40 with modification described in 41 to
// suppress very small waves that cause convergence problems
return _A * (exp(-1.0f / (k_length2 * L2)) / k_length4) * k_dot_w2 * exp(-k_length2 * l2);
}
示例7: LineAngle
float Line::LineAngle(Line l1, Line l2)
{
return acos( dot(l1.m_directionVector, l2.m_directionVector)/sqrt(glm::length2(l1.m_directionVector) * glm::length2(l2.m_directionVector)) );
}