本文整理汇总了C++中Point::Normalize方法的典型用法代码示例。如果您正苦于以下问题:C++ Point::Normalize方法的具体用法?C++ Point::Normalize怎么用?C++ Point::Normalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Point
的用法示例。
在下文中一共展示了Point::Normalize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
void
CameraDirector::Chase(double seconds)
{
double step = 1;
if (requested_mode == MODE_COCKPIT)
step = transition;
else if (requested_mode == MODE_CHASE)
step = 1 - transition;
camera.Clone(ship->Cam());
Point velocity = camera.vpn();
if (ship->Velocity().length() > 10) {
velocity = ship->Velocity();
velocity.Normalize();
velocity *= 0.25;
velocity += camera.vpn() * 2;
velocity.Normalize();
}
Point chase = ship->ChaseLocation();
Point bridge = ship->BridgeLocation();
Point cpos = camera.Pos() +
camera.vrt() * bridge.x * (1-step) +
camera.vpn() * bridge.y * (1-step) +
camera.vup() * bridge.z * (1-step) +
velocity * chase.y * step +
camera.vup() * chase.z * step;
camera.MoveTo(cpos);
}
示例2: Point
Matrix& Matrix::ComputeAxisMatrix(Point& axis, float angle)
{
MakeIdentity();
float length = axis.Magnitude();
// Normalize the z basis vector3
axis /= length;
// Get the dot product, and calculate the projection of the z basis
// vector3 onto the up vector3. The projection is the y basis vector3.
float dotProduct = Point(0, 1, 0) | axis;
Point Up = Point(0, 1, 0) - dotProduct * axis;
// This is to prevent bogus view matrix (up view vector3 equals to axis)
if (Up.Magnitude() < 1e-6f) {
Up = Point(0, 0, 1);
}
else {
// Normalize the y basis vector3
Up /= length;
Up.Normalize();
}
// The x basis vector3 is found simply with the cross product of the y
// and z basis vectors
Point Right = Up ^ axis;
SetCol( 0, Right );
SetCol( 1, Up );
SetCol( 2, axis );
Transpose();
return *this;
}
示例3: Point
void
QuantumFlash::UpdateVerts(const Point& cam_pos)
{
if (length < radius) {
length += radius/80;
width += 1;
}
for (int i = 0; i < npolys; i++) {
Matrix& m = beams[i];
m.Yaw(0.05);
Point vpn = Point(m(2,0), m(2,1), m(2,2));
Point head = loc;
Point tail = loc - vpn * length;
Point vtail = tail - head;
Point vcam = cam_pos - loc;
Point vtmp = vcam.cross(vtail);
vtmp.Normalize();
Point vlat = vtmp * -width;
verts->loc[4*i+0] = head + vlat;
verts->loc[4*i+1] = tail + vlat * 8;
verts->loc[4*i+2] = tail - vlat * 8;
verts->loc[4*i+3] = head - vlat;
DWORD color = D3DCOLOR_RGBA((BYTE) (255*shade), (BYTE) (255*shade), (BYTE) (255*shade), 255);
for (int n = 0; n < 4; n++) {
verts->diffuse[4*i+n] = color;
}
}
}
示例4: IntersectSphere
bool Triangle::IntersectSphere(const Point& center, const double radius) const
{
Point p[3], e[3];
p[0] = p0 - center;
p[1] = p1 - center;
p[2] = p2 - center;
double radius2 = radius*radius;
for(int i=0; i<3; i++)
if( p[i].Norm2() < radius2)
return true;
// This is the buggy part
for(int i=0; i<3; i++)
{
e[i] = p[i] - p[(i+1)%3];
double n2 = e[i].Norm2();
double d = (p[i] | e[i]);
if(d > 0 && -d < n2 && p[i].Norm2() - d*d/n2 < radius2 )
return true;
}
Point n = e[0]^e[1];
n = n.Normalize();
double d = (p[0]|n);
if( abs(d) >= radius)
return false;
n = d*n;
int sign01 = SignMask(e[0]^(p[0] - n));
int sign12 = SignMask(e[1]^(p[1] - n));
int sign20 = SignMask(e[2]^(p[2] - n));
return (sign01 & sign12 & sign20) != 0;
}
示例5: GetBothAxes
// GetSecondAngleAxis looks for the axis defined by the pointer finger
// And the left base
bool GloveType::GetBothAxes(int i) {
if (!GetFirstAxis(i)) return false;
if (axis_points2_.size() == 2) {
// Check the first Axis validity
if (base_left_->current_ == 0 || base_right_->current_ == 0) {
return false;
}
/*check second axis*/
Point u;
if (fore_->current_ == 0) {
return false;
} else {
u = fore_->Sub(*base_left_);
}
Point v = fore_->Sub(*base_left_);
axis2_ = u.Sub(v.Normalize().Times(u.Dot(v))).Normalize();
// Now find the normal component
return true;
} else {
if (base_left_->current_ == 0 || fore_->current_ == 0) return false;
axis_points2_.push_back(fore_);
axis_points2_.push_back(base_left_);
Point v = fore_->Sub(*base_left_);
axis2_ = v.Sub(axis1_.Times(v.Dot(axis1_))).Normalize();
Point y_axis;
y_axis.Init(0, 1, 0);
original_axis2_ = y_axis;
return true;
}
}
示例6:
Ray(Point P0, Point dir, GLfloat T)
{
p0 = P0;
r = dir.Normalize();
t = T;
vect = p0 + (r * t);
}
示例7:
void
Trail::UpdateVerts(const Point& cam_pos)
{
if (ntrail < 2) return;
int bright = 255 - dim*ntrail;
Point head = trail[1] + loc;
Point tail = trail[0] + loc;
Point vcam = cam_pos - head;
Point vtmp = vcam.cross(head-tail);
vtmp.Normalize();
Point vlat = vtmp * (width + (0.1 * width * ntrail));
verts->loc[0] = tail - vlat;
verts->loc[1] = tail + vlat;
verts->diffuse[0] = 0;
verts->diffuse[1] = 0;
for (int i = 0; i < ntrail-1; i++) {
bright+=dim;
Point head = trail[i+1] + loc;
Point tail = trail[i] + loc;
Point vcam = cam_pos - head;
Point vtmp = vcam.cross(head-tail);
vtmp.Normalize();
float trail_width = (float) (width + (ntrail-i) * width * 0.1);
if (i == ntrail-2) trail_width = (float) (width * 0.7);
Point vlat = vtmp * trail_width;
verts->loc[2*i+2] = head - vlat;
verts->loc[2*i+3] = head + vlat;
if (bright <= 0) {
verts->diffuse[2*i+2] = 0;
verts->diffuse[2*i+3] = 0;
}
else {
verts->diffuse[2*i+2] = D3DCOLOR_RGBA(bright,bright,bright,bright);
verts->diffuse[2*i+3] = D3DCOLOR_RGBA(bright,bright,bright,bright);
}
}
}
示例8: RotateCamera
void RotateCamera(int dx, int dy)
{
gDir = gDir.Normalize();
gN = gDir ^ Point(0,1,0);
NxQuat qx(NxPiF32 * dx * 20/ 180.0f, Point(0,1,0));
qx.rotate(gDir);
NxQuat qy(NxPiF32 * dy * 20/ 180.0f, gN);
qy.rotate(gDir);
}
示例9: orientation
void
Camera::LookAt(const Point& target, const Point& eye, const Point& up)
{
Point zaxis = target - eye; zaxis.Normalize();
Point xaxis = up.cross(zaxis); xaxis.Normalize();
Point yaxis = zaxis.cross(xaxis); yaxis.Normalize();
orientation(0,0) = xaxis.x;
orientation(0,1) = xaxis.y;
orientation(0,2) = xaxis.z;
orientation(1,0) = yaxis.x;
orientation(1,1) = yaxis.y;
orientation(1,2) = yaxis.z;
orientation(2,0) = zaxis.x;
orientation(2,1) = zaxis.y;
orientation(2,2) = zaxis.z;
pos = eye;
}
示例10:
Matrix4x4& Matrix4x4::SelfShadow(const Point& light)
{
Point Light = light;
Light.Normalize();
Zero();
m[0][0] = Light.x * 0.5f;
m[0][1] = Light.y * 0.5f;
m[0][2] = Light.z * 0.5f;
m[0][3] = 0.5f;
m[3][3] = 1.0f;
return *this;
}
示例11: RotateCamera
void RotateCamera(int dx, int dy)
{
const Point Up(0.0f, 1.0f, 0.0f);
gDir.Normalize();
gViewY = gDir^Up;
// #### TODO: replicate this using Ice quats
MyQuat qx(NxPiF32 * dx * 20.0f/ 180.0f, Up);
qx.rotate(gDir);
MyQuat qy(NxPiF32 * dy * 20.0f/ 180.0f, gViewY);
qy.rotate(gDir);
}
示例12: pnt
void MeshOptimize2dOCCSurfaces ::
GetNormalVector(INDEX surfind, const Point<3> & p, Vec<3> & n) const
{
// static int cnt = 0;
// if (cnt++ % 1000 == 0) cout << "GetNV cnt = " << cnt << endl;
Standard_Real u,v;
gp_Pnt pnt(p(0), p(1), p(2));
Handle(Geom_Surface) occface;
occface = BRep_Tool::Surface(TopoDS::Face(geometry.fmap(surfind)));
/*
GeomAPI_ProjectPointOnSurf proj(pnt, occface);
if (proj.NbPoints() < 1)
{
cout << "ERROR: OCCSurface :: GetNormalVector: GeomAPI_ProjectPointOnSurf failed!"
<< endl;
cout << p << endl;
return;
}
proj.LowerDistanceParameters (u, v);
*/
Handle( ShapeAnalysis_Surface ) su = new ShapeAnalysis_Surface( occface );
gp_Pnt2d suval = su->ValueOfUV ( pnt, BRep_Tool::Tolerance( TopoDS::Face(geometry.fmap(surfind)) ) );
suval.Coord( u, v);
pnt = occface->Value( u, v );
gp_Vec du, dv;
occface->D1(u,v,pnt,du,dv);
/*
if (!occface->IsCNu (1) || !occface->IsCNv (1))
(*testout) << "SurfOpt: Differentiation FAIL" << endl;
*/
n = Cross (Vec3d(du.X(), du.Y(), du.Z()),
Vec3d(dv.X(), dv.Y(), dv.Z()));
n.Normalize();
if (geometry.fmap(surfind).Orientation() == TopAbs_REVERSED) n = -1*n;
}
示例13: Inflate
void Triangle::Inflate(float fat_coeff, bool constant_border)
{
// Compute triangle center
Point TriangleCenter;
Center(TriangleCenter);
// Don't normalize?
// Normalize => add a constant border, regardless of triangle size
// Don't => add more to big triangles
for(udword i=0;i<3;i++)
{
Point v = mVerts[i] - TriangleCenter;
if(constant_border) v.Normalize();
mVerts[i] += v * fat_coeff;
}
}
示例14: IntersectCylinder
bool Triangle::IntersectCylinder(const Point& c0, const Point& c1, const double radius) const
{
// check intersection with the edges
if(SegmentSegmentDistance(p0, p1, c0, c1) < radius)
return true;
if(SegmentSegmentDistance(p1, p2, c0, c1) < radius)
return true;
if(SegmentSegmentDistance(p2, p1, c0, c1) < radius)
return true;
// check intersection with the inner
Point n = ((p0-p1)^(p0-p2)).Normalize();
Point intersect;
double origin = n|p0;
double nC0 = (n|c0) - origin;
double nC1 = (n|c1) - origin;
if(nC0*nC1 > 0)
{
if(abs(nC0) < abs(nC1))
{
if(abs(nC0) > radius)
return false;
intersect = c0 - n*nC0;
}
else
{
if(abs(nC1) > radius)
return false;
intersect = c1 - n*nC1;
}
}
else
{
Point dir = c1 - c0;
intersect = c0 + (nC0/(dir|n))*dir.Normalize();
}
return IntersectPoint(intersect);
}
示例15: if
void
Physical::LinearFrame(double seconds)
{
// deal with lateral thrusters:
if (trans_x) { // side-to-side
Point transvec = cam.vrt();
transvec *= ((trans_x/mass) * seconds);
velocity += transvec;
}
if (trans_y) { // fore-and-aft
Point transvec = cam.vpn();
transvec *= ((trans_y/mass) * seconds);
velocity += transvec;
}
if (trans_z) { // up-and-down
Point transvec = cam.vup();
transvec *= ((trans_z/mass) * seconds) * 2; //**Compensate extra gravity
velocity += transvec;
}
// if gravity applies, attract:
if (primary_mass > 0) {
Point g = primary_loc - cam.Pos();
double r = g.Normalize();
g *= GRAV * primary_mass / (r*r);
velocity += g * seconds;
}
// constant gravity:
else if (g_accel > 0)
velocity += Point(0, -g_accel, 0) * seconds;
// if drag applies, decellerate:
if (drag)
velocity *= exp(-drag * seconds);
}