Exemplo n.º 1
0
bool Collision::Octree_Capsule(int modelID, const Capsule& capsule, HitInfo& hitInfo) {
	MV1_COLL_RESULT_POLY_DIM mv1HitInfo;
	mv1HitInfo = MV1CollCheck_Capsule(modelID, -1, Convert::ToVECTOR(capsule.p1), Convert::ToVECTOR(capsule.p2), capsule.radius);

	if (mv1HitInfo.HitNum < 1) {
		return false;
	}

	int hitNum = mv1HitInfo.HitNum;

	Vector3 pos;
	Vector3 normal;
	for (int i = 0; i < hitNum; ++i) {
		VECTOR p = mv1HitInfo.Dim[i].HitPosition;
		pos += Vector3(p.x, p.y, p.z);
		VECTOR n = mv1HitInfo.Dim[i].Normal;
		normal += Vector3(n.x, n.y, n.z);
	}
	pos /= hitNum;
	normal /= hitNum;
	hitInfo.intersect = pos;
	hitInfo.normal = normal.GetNormal();

	MV1CollResultPolyDimTerminate(mv1HitInfo);

	return true;
}
Exemplo n.º 2
0
    void WorldNode::SetDirection(const Vector3& Direction, const Mezzanine::TransformSpace& TS, const Vector3& LocalAxis)
    {
        static const Vector3 Zero(0,0,0);
        if(Direction == Zero)
            return;

        Vector3 NormalizedDir = Direction.GetNormal();
        switch(TS)
        {
            default:
            case Mezzanine::TS_World:
            {
                // Do nothing
                break;
            }
            case Mezzanine::TS_Local:
            {
                NormalizedDir = GetOrientation() * NormalizedDir;
                break;
            }
            case Mezzanine::TS_Parent:
            {
                if(Parent) NormalizedDir = Parent->GetOrientation() * NormalizedDir;
                else return;  /// @todo May want to change this to an exception, maybe.
                break;
            }
        }

        Quaternion FinalOrientation;
        if(FixedYaw)
        {
            Vector3 XVec = FixedYawAxis.CrossProduct(NormalizedDir);
            XVec.Normalize();
            Vector3 YVec = NormalizedDir.CrossProduct(XVec);
            YVec.Normalize();
            Quaternion ZToTarget(XVec,YVec,NormalizedDir);

            if(LocalAxis == Vector3::Neg_Unit_Z())
            {
                FinalOrientation.SetValues(-ZToTarget.Y,-ZToTarget.Z,ZToTarget.W,ZToTarget.X);
            }else{
                FinalOrientation = ZToTarget * (LocalAxis.GetRotationToAxis(Vector3::Unit_Z()));
            }
        }else{
            Quaternion CurrOri = GetOrientation();
            Vector3 CurrDir = CurrOri * LocalAxis;
            if( (CurrDir+NormalizedDir).SquaredLength() < 0.00005 )
            {
                FinalOrientation.SetValues(-CurrOri.Y,-CurrOri.Z,CurrOri.W,CurrOri.X);
            }else{
                FinalOrientation = (CurrDir.GetRotationToAxis(NormalizedDir)) * CurrOri;
            }
        }

        SetOrientation(FinalOrientation);
    }
Exemplo n.º 3
0
bool Collision::BoundingShpere_BoundingSphere(const BoundingSphere& sphere1, const BoundingSphere& sphere2, HitInfo& hitInfo) {
	float radius = sphere1.radius + sphere2.radius;
	Vector3 distance = sphere2.center - sphere1.center;

	if (distance.SquareLength() >= radius * radius)
		return false;

	//中央を結んだベクトルの正規化
	Vector3 n = distance.GetNormal();

	hitInfo.intersect = sphere2.center - radius * n;
	return true;
}
Exemplo n.º 4
0
int main()
{
    cout << "---------------------------Matrix 3--------------------------------" << endl;

    Matrix3 TranslationXY;
    TranslationXY = Mat3.m_TranslationXY(2, 2);
    cout << TranslationXY;
    cout << endl;

    cout << "--------------------------MATRIX 4 --------------------------------" << endl;

    Matrix4 RotationX;
    RotationX = Mat4.m_RotationX(3);
    cout << RotationX;
    cout << endl;

    Matrix4 RotationY;
    RotationY = Mat4.m_RotationY(2);
    cout << RotationY;
    cout << endl;

    Matrix4 RotationZ;
    RotationZ = Mat4.m_RotationZ(2);
    cout << RotationZ;
    cout << endl;

    Matrix4 TranslationXYZ;
    TranslationXYZ = Mat4.m_TranslationXYZ(2, 2, 2);
    cout << TranslationXYZ;
    cout << endl;

    Matrix4 mat;
    mat = Mat4.m_OrthoProjection(2,2,2,2,2,2);
    cout << mat;
    cout << endl;

    Matrix4 Identity;
    mat = Mat4.m_CreateIdentity();
    cout << Identity;
    cout <<endl;

    cout << "---------------------------COMMON MATH--------------------------------" << endl;

    cout << ComMath.Pow2(2, 2)<< endl;
    cout << ComMath.m_RadianConvert(360)<< endl;
    cout << ComMath.m_degreeConvert(6) << endl;
    Vect3.x = 2;
    Vect3.y = 2;
    Vect3.z =2;
    Vect33.x = 4;
    Vect33.y = 4;
    Vect33.z = 4;
    cout << ComMath.m_Lerp(Vect3, Vect33, 2) << endl;

    cout << "---------------------------VECTOR 3--------------------------------" << endl;
    Vect3.x = 2;
    Vect3.y =2;
    Vect3.z =2;
    cout << Vect3.Magnitude()<<endl;

    Vect3.x = 2;
    Vect3.y =2;
    Vect3.z =2;
    cout << Vect33.Normalise(Vect3)<<endl;

    Vect3.x = 2;
    Vect3.y =2;
    Vect3.z = 2;
    cout << Vect33.GetNormal(Vect3) << endl;

    Vect3.x = 2;
    Vect3.y = 2;
    Vect3.z =2;
    cout <<Vect33.DotProduct(Vect3) << endl;

    Vect3.x = 4;
    Vect3.y = 4;
    Vect3.z = 4;
    Vect33.x =4;
    Vect33.y = 4;
    Vect3.z = 4;
    cout << Vect3.EulerAngle(Vect3, Vect33)<<endl;

    Vect3.x = 2;
    Vect3.y = 2;
    Vect3.z = 2;
    Vect33.x = 2;
    Vect33.y =2;
    Vect33.z = 2;
    cout << Vect3.CrossProduct(Vect3, Vect33)<<endl;

    Matrix3 Transform;
    Transform = Mat3;
    Vect3.x =2;
    Vect3.y = 2;
    Vect3.z = 2;
    cout << Vect3.m_TransformVector3(Mat3)<<endl;

    Matrix3 tempM;
    tempM = Mat3;
    Vect3.x = 2;
    Vect3.y = 2;
    Vect3.z = 2;
    cout << Vect3.Scale(Mat3);
    cout << endl;

    cout << "---------------------------VECTOR 4--------------------------------" << endl;
    Vect4.x = 2;
    Vect4.y =2;
    Vect4.z =2;
    Vect4.w = 2;
    cout << Vect4.m_Magnitude()<<endl;

    Vect4.x = 2;
    Vect4.y =2;
    Vect4.z =2;
    Vect4.w = 2;
    cout << Vect4.m_GetNormal(Vect4)<<endl;

    Vect4.x = 2;
    Vect4.y =2;
    Vect4.z =2;
    Vect4.w = 2;
    cout << Vect4.m_Normalise(Vect4) <<endl;

    Vect4.x = 2;
    Vect4.y =2;
    Vect4.z =2;
    Vect4.w = 2;
    cout << Vect4.m_DotProduct(Vect4) << endl;

    cout << Vect4.m_RGBconverter(0xFFFFFFFF)<<endl;

    Matrix4 Transform2;
    Transform2 = Mat4;
    Vect4.x = 2;
    Vect4.y =2;
    Vect4.z =2;
    Vect4.w = 2;
    cout << Vect4.m_TransformPoint(Mat4) << endl;

    Matrix4 Transform3;
    Transform3 = Mat4;
    Vect4.x = 2;
    Vect4.y =2;
    Vect4.z =2;
    Vect4.w = 2;
    cout << Vect4.m_TransformVector4(Vect4, Mat4);
    cout << endl;

    Matrix4 mat4;
    mat4 = Mat4;
    Vect4.x = 2;
    Vect4.y = 2;
    Vect4.z = 2;
    Vect4.w = 2;
    cout << Vect4.Scale(Mat4);
    cout << endl;

    cout << "---------------------------VECTOR 2--------------------------------" << endl;
    Vectors Point;
    Point.x = 2;
    Point.y =2;
    cout << V2.pointSubtract(Point, 2) << endl;

    Vectors Point2;
    Point2.x = 2;
    Point2.y =2;
    cout << V2.pointAdd(Point2, 2)<<endl;

    Vectors Point3;
    Point3.x = 2;
    Point3.y =2;
    cout << V2.multiplyScalar(Point3, 2) << endl;

    Vectors Point4;
    Point4.x = 2;
    Point4.y =2;
    cout << V2.getMagnitude(Point4)<<endl;

    Vectors Point5;
    Point5.x = 2;
    Point5.y =2;
    cout<<V2.getNormal(Point5)<<endl;

    getchar();
    return 0;
}