C++ (Cpp) Vector3 Examples

C++ (Cpp) Vector3 - 30 examples found. These are the top rated real world C++ (Cpp) examples of Vector3 extracted from open source projects. You can rate examples to help us improve the quality of examples.
void fillSubModelArary(const ModelContainer* pModelContainer, const TreeNode *root, Array<SubModel>& array, Vector3& pLo, Vector3& pHi) {
    Vector3 lo = Vector3(inf(), inf(), inf());
    Vector3 hi = Vector3(-inf(), -inf(), -inf());

    for(int i=0; i<	root->getNValues(); i++) {
        SubModel sm = pModelContainer->getSubModel(root->getStartPosition() + i);
        lo = lo.min(sm.getAABoxBounds().low());
        hi = hi.max(sm.getAABoxBounds().high());
        array.append(sm);
    }

    if(root->getChild((TreeNode *) &pModelContainer->getTreeNode(0), 0)) {
        fillSubModelArary(pModelContainer, root->getChild((TreeNode *)&pModelContainer->getTreeNode(0), 0), array, lo, hi);
    }
    if(root->getChild((TreeNode *)&pModelContainer->getTreeNode(0), 1)) {
        fillSubModelArary(pModelContainer, root->getChild((TreeNode *)&pModelContainer->getTreeNode(0), 1), array, lo, hi);
    }

    float dist1 = (hi -lo).magnitude();
    AABox b;
    root->getBounds(b);
    float dist2 = (b.high() -b.low()).magnitude();
    if(dist1 > dist2) {
        // error
        int xxx = 0;
    }

}
bool IntrSegment3Triangle3<Real>::Test ()
{
    // Compute the offset origin, edges, and normal.
    Vector3<Real> diff = mSegment->Center - mTriangle->V[0];
    Vector3<Real> edge1 = mTriangle->V[1] - mTriangle->V[0];
    Vector3<Real> edge2 = mTriangle->V[2] - mTriangle->V[0];
    Vector3<Real> normal = edge1.Cross(edge2);

    // Solve Q + t*D = b1*E1 + b2*E2 (Q = diff, D = segment direction,
    // E1 = edge1, E2 = edge2, N = Cross(E1,E2)) by
    //   |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
    //   |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
    //   |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
    Real DdN = mSegment->Direction.Dot(normal);
    Real sign;
    if (DdN > Math<Real>::ZERO_TOLERANCE)
    {
        sign = (Real)1;
    }
    else if (DdN < -Math<Real>::ZERO_TOLERANCE)
    {
        sign = (Real)-1;
        DdN = -DdN;
    }
    else
    {
        // Segment and triangle are parallel, call it a "no intersection"
        // even if the segment does intersect.
        mIntersectionType = IT_EMPTY;
        return false;
    }

    Real DdQxE2 = sign*mSegment->Direction.Dot(diff.Cross(edge2));
    if (DdQxE2 >= (Real)0)
    {
        Real DdE1xQ = sign*mSegment->Direction.Dot(edge1.Cross(diff));
        if (DdE1xQ >= (Real)0)
        {
            if (DdQxE2 + DdE1xQ <= DdN)
            {
                // Line intersects triangle, check if segment does.
                Real QdN = -sign*diff.Dot(normal);
                Real extDdN = mSegment->Extent*DdN;
                if (-extDdN <= QdN && QdN <= extDdN)
                {
                    // Segment intersects triangle.
                    mIntersectionType = IT_POINT;
                    return true;
                }
                // else: |t| > extent, no intersection
            }
            // else: b1+b2 > 1, no intersection
        }
        // else: b2 < 0, no intersection
    }
    // else: b1 < 0, no intersection

    mIntersectionType = IT_EMPTY;
    return false;
}
Matrix
Sprite3D::get_attachment_point_matrix(PointID id) const
{
    const AttachmentPointPosition& point1
        = frame1.action->frames[frame1.frame].attachment_points[id];
    const AttachmentPointPosition& point2
        = frame2.action->frames[frame2.frame].attachment_points[id];

    Quaternion rotquat = Quaternion(0, 0, 1, 0);
    Quaternion quat1 = point1.quat;
    Vector3 pos1 = point1.pos;
    if(frame1.rot) {
        quat1 = rotquat * quat1;
        pos1.x = -pos1.x;
        pos1.z = -pos1.z;
    }
    Quaternion quat2 = point2.quat;
    Vector3 pos2 = point2.pos;
    if(frame2.rot) {
        quat2 = rotquat * quat2;
        pos2.x = -pos2.x;
        pos2.z = -pos2.z;
    }

    Vector3 pos = pos1 + (pos2 - pos1) * blend_time;
    Quaternion quat = quat1.slerp(quat2, blend_time);
    Matrix result = pos.to_matrix();
    result = result.multiply(quat.to_matrix());

    return result;
}
Example #4
0
Intersection* Sphere::Intersect(const Ray& ray) const
{
    /* Quadratic equation */
    Vector3 dst = ray.GetOrigin() - translation;
    float B = dst.Dot(ray.GetDirection());
    float C = dst.Dot(dst) - (radius * radius);
    float D = B*B - C;

    /* Discriminant < 0, so we know the object does not intersect */
    if(D < 0) {
        return new Intersection(Vector3(), Vector3(), (Geometry*)this, 0, 0, -1);
    }

    /* Right now we only care about where the ray /enters/ the sphere
     * float t2 = (-B + sqrt(D)) would give us its exit point. Will
     * compute later for refraction / transmission
     */
    float t = (-B + sqrt(D));

    /* Avoid intersecting with the near plane */
    if(t <= 0.00001) {
        return new Intersection(Vector3(), Vector3(), (Geometry*)this, 0, 0, -1);
    }

    /* Intersection point */
    Vector3 point = (ray.GetOrigin() + ray.GetDirection() * t);

    /* Normal at the intersection point */
    Vector3 normal = (point - translation);

    return new Intersection(point, normal.Normalize(), (Geometry*)this, 0, 0, t);
}
Example #5
0
/**
   assuming Link::v,w is already computed by calcForwardKinematics(true);
   assuming Link::wc is already computed by calcCenterOfMass();
*/
void Body::calcTotalMomentum(Vector3& out_P, Vector3& out_L)
{
    out_P.setZero();
    out_L.setZero();

    Vector3 dwc;    // Center of mass speed in world frame
    Vector3 P;	    // Linear momentum of the link
    Vector3 L;	    // Angular momentum with respect to the world frame origin
    Vector3 Llocal; // Angular momentum with respect to the center of mass of the link

    int n = linkTraverse_.numLinks();

    for(int i=0; i < n; i++) {
        Link* link = linkTraverse_[i];
        dwc = link->v() + link->w().cross(link->R() * link->c());
        P   = link->m() * dwc;

        //L   = cross(link->wc, P) + link->R * link->I * trans(link->R) * link->w;
        Llocal.noalias() = link->I() * link->R().transpose() * link->w();
        L     .noalias() = link->wc().cross(P) + link->R() * Llocal;

        out_P += P;
        out_L += L;
    }
}
Example #6
0
float Angle(Vector3 &v1, Vector3 &v2)
{
    if(v1.Magnitude() * v2.Magnitude())
        return acos((DotProduct(v1, v2)) / (v1.Magnitude() * v2.Magnitude()));
    else
        return 0;
}