void TransformManipulator::spin(const Vector3F & d) { Matrix44F ps; parentSpace(ps); Matrix44F invps = ps; invps.inverse(); const Vector3F worldP = ps.transform(translation()); const Vector3F rotUp = ps.transformAsNormal(hitPlaneNormal()); Vector3F toa = m_currentPoint - worldP; Vector3F tob = toa + d; toa.normalize(); tob.normalize(); float ang = toa.angleBetween(tob, toa.cross(rotUp).reversed()); Vector3F angles; if(m_rotateAxis == AY) angles.set(0.f, ang, 0.f); else if(m_rotateAxis == AZ) angles.set(0.f, 0.f, ang); else angles.set(ang, 0.f, 0.f); m_subject->rotate(angles); setRotationAngles(m_subject->rotationAngles()); }
void BaseView::tumble(int dx, int dy, int portWidth) { Vector3F side = m_space.getSide(); Vector3F up = m_space.getUp(); Vector3F front = m_space.getFront(); Vector3F eye = m_space.getTranslation(); Vector3F toEye = eye - m_centerOfInterest; float dist = toEye.length(); const float scaleing = dist * 2.f / (float)portWidth; eye -= side * (float)dx * scaleing; eye += up * (float)dy * scaleing; toEye = eye - m_centerOfInterest; toEye.normalize(); eye = m_centerOfInterest + toEye * dist; m_space.setTranslation(eye); front = toEye; side = up.cross(front); side.y = 0.f; side.normalize(); up = front.cross(side); up.normalize(); m_space.setOrientations(side, up, front); m_invSpace = m_space; m_invSpace.inverse(); }
float MlRachis::pushToSurface(const Vector3F & wv, const Matrix33F & space) { Vector3F ov = space.transform(wv); ov.normalize(); ov.y = 0.f; ov.x += 0.05f; ov.normalize(); float a = acos(Vector3F::ZAxis.dot(ov)); if(ov.x < 0.f) a = 0.f; return a; }
void Sculptor::movePointsToward(const Vector3F & d, const float & fac, bool normalize, Vector3F * vmod) { if(m_active->numSelected() < 1) return; Array<int, VertexP> * vs = m_active->vertices; Vector3F tod; float wei; vs->begin(); while(!vs->end()) { VertexP * l = vs->value(); wei = *l->index->t4; const Vector3F p0(*(l->index->t1)); tod = d - *(l->index->t1); if(normalize) tod.normalize(); *(l->index->t1) += tod * fac * wei * m_strength; if(vmod) { *(l->index->t1) += *vmod * wei * m_strength; } m_tree->displace(l, *(l->index->t1), p0); vs->next(); } }
Matrix33F Patch::tangentFrame() const { Matrix33F frm; Vector3F du = (vertex(1) - vertex(0) + vertex(2) - vertex(3)) * .5f; Vector3F dv = (vertex(3) - vertex(0) + vertex(2) - vertex(1)) * .5f; du.normalize(); dv.normalize(); Vector3F side = du.cross(dv); side.normalize(); Vector3F up = du.cross(side); up.normalize(); frm.fill(side, up, du); return frm; }
Vector3F Vector3F::perpendicular() const { Vector3F ref(0,1,0); Vector3F n = normal(); if(n.y < -0.9f || n.y > 0.9f) ref = Vector3F(1,0,0); Vector3F per = cross(ref); per.normalize(); return per; }
Float3 MlRachis::matchNormal(const Vector3F & wv, const Matrix33F & space) { Vector3F ov = space.transform(wv); Vector3F va = ov; va.y = 0.f; va.z -= 0.05f; va.normalize(); float a = acos(Vector3F::XAxis.dot(va)); if(va.z > 0.f) a = -a; Vector3F vb = ov; vb.z = 0.f; vb.normalize(); float b = acos(Vector3F::XAxis.dot(vb)); if(vb.y < 0.f) b = -b; return Float3(a, b, 0.f); }
Vector3F AccInterior::computeNormal() const { Vector3F res = _cornerNormals[0] * _valence; res += _cornerNormals[1] * 2.f; res += _cornerNormals[3] * 2.f; res += _cornerNormals[2]; return res / (_valence + 5.f); res.normalize(); return res; }
void AccCorner::addCornerNeighborBetween(int a, int b, Vector3F * positions, Vector3F * normals) { _cornerIndices.push_back(a); _cornerIndices.push_back(b); _tagCornerIndices.push_back(0); _tagCornerIndices.push_back(0); _cornerPositions.push_back(positions[a] * 0.5f + positions[b] * 0.5f); Vector3F an = normals[a] * 0.5f + normals[b] * 0.5f; an.normalize(); _cornerNormals.push_back(an); }
void Plane::create(const Vector3F & p0, const Vector3F & p1, const Vector3F & p2, const Vector3F & p3) { Vector3F cen = p0 * 0.25f + p1 * 0.25f + p2 * 0.25f + p3 * 0.25f; Vector3F c0 = p2 - p0; Vector3F c1 = p3 - p1; Vector3F nn = c0.cross(c1); nn.normalize(); m_a = nn.x; m_b = nn.y; m_c = nn.z; m_d = - cen.dot(nn); }
char BaseMesh::triangleIntersect(const Vector3F * threeCorners, IntersectionContext * ctx) const { Vector3F a = threeCorners[0]; Vector3F b = threeCorners[1]; Vector3F c = threeCorners[2]; Vector3F ab = b - a; Vector3F ac = c - a; Vector3F nor = ab.cross(ac); nor.normalize(); Ray &ray = ctx->m_ray; float ddotn = ray.m_dir.dot(nor); if(!ctx->twoSided && ddotn > 0.f) return 0; float t = (a.dot(nor) - ray.m_origin.dot(nor)) / ddotn; if(t < 0.f || t > ray.m_tmax) return 0; //printf("face %i %f %f", idx, t, ctx->m_minHitDistance); if(t > ctx->m_minHitDistance) return 0; Vector3F onplane = ray.m_origin + ray.m_dir * t; Vector3F e01 = b - a; Vector3F x0 = onplane - a; if(e01.cross(x0).dot(nor) < 0.f) return 0; //printf("pass a\n"); Vector3F e12 = c - b; Vector3F x1 = onplane - b; if(e12.cross(x1).dot(nor) < 0.f) return 0; //printf("pass b\n"); Vector3F e20 = a - c; Vector3F x2 = onplane - c; if(e20.cross(x2).dot(nor) < 0.f) return 0; //printf("pass c\n"); ctx->m_hitP = onplane; ctx->m_hitN = nor; ctx->m_minHitDistance = t; ctx->m_geometry = (Geometry*)this; ctx->m_success = 1; return 1; }
void InverseBilinearInterpolate::setVertices(const Vector3F & a, const Vector3F & b, const Vector3F & c, const Vector3F & d) { Vector3F side = b - a; side.normalize(); Vector3F up = c - a; Vector3F front = side.cross(up); front.normalize(); up = front.cross(side); up.normalize(); m_space.setIdentity(); m_space.setTranslation(a); m_space.setOrientations(side, up, front); m_space.inverse(); Vector3F A = m_space.transform(a); Vector3F B = m_space.transform(b); m_E.set(B.x, B.y); Vector3F C = m_space.transform(c); m_F.set(C.x, C.y); Vector3F D = m_space.transform(d); m_G.set(-B.x - C.x + D.x, -B.y - C.y + D.y); }
bool Patch::isBehind(const Vector3F & po, Vector3F & nr) const { int i; float maxFacing = -1.f; float facing; Vector3F dv; for(i = 0; i < 4; i++) { dv = vertex(i) - po; dv.normalize(); facing = nr.dot(dv); if(facing > maxFacing) { maxFacing = facing; } } return maxFacing < 0.f; }
void Vector3F::rotateAroundAxis(const Vector3F& axis, float theta) { if(theta==0) return; Vector3F ori(x,y,z); float l = ori.length(); ori.normalize(); Vector3F up = axis.cross(ori); up.normalize(); Vector3F side = ori - axis*(axis.dot(ori)); up *=side.length(); ori += side*(cos(theta) - 1); ori += up*sin(theta); ori.normalize(); x = ori.x*l; y = ori.y*l; z = ori.z*l; }
char Facet::isVertexAbove(const Vertex & v) const { Vector3F dv = *v.m_v - getCentroid(); dv.normalize(); return dv.dot(m_normal) > 0.0f; }
void BCIViz::findNeighbours() { if(!checkHull()) return; const int numTri = m_hull->getNumFace(); Vector3F d; d.x = fDriverPos.x; d.y = fDriverPos.y; d.z = fDriverPos.z; d.normalize(); m_hitTriangle = 0; for(int i = 0; i < numTri; i++) { Facet f = m_hull->getFacet(i); Vertex p0 = f.getVertex(0); const Vector3F nor = f.getNormal(); float ddotn = d.dot(nor); if(ddotn < 10e-5 && ddotn > -10e-5) continue; float t = p0.dot(nor) / ddotn; if(t < 0.f) continue; Vertex p1 = f.getVertex(1); Vertex p2 = f.getVertex(2); m_hitTriangle = i; m_hitP = d * t; Vector3F e01 = p1 - p0; Vector3F e02 = p2 - p0; Vector3F tmp = e01.cross(e02); if(tmp.dot(nor) < 0.f) { Vertex sw = p1; p1 = p2; p2 = sw; } e01 = p1 - p0; Vector3F x0 = m_hitP - p0; Vector3F e12 = p2 - p1; Vector3F x1 = m_hitP - p1; Vector3F e20 = p0 - p2; Vector3F x2 = m_hitP - p2; neighbourId[0] = p0.getIndex(); neighbourId[1] = p1.getIndex(); neighbourId[2] = p2.getIndex(); if(e01.cross(x0).dot(nor) < 0.f) continue; if(e12.cross(x1).dot(nor) < 0.f) continue; if(e20.cross(x2).dot(nor) < 0.f) continue; return; } }
void MlRachis::moveForward(const Matrix33F & space, float distance, Vector3F & dst) { Vector3F wv = space.transform(Vector3F::ZAxis); wv.normalize(); dst += wv * distance; }
Vector3F BaseView::directionToEye() const { Vector3F v = eyePosition() - m_centerOfInterest; v.normalize(); return v; }