common/inc/Vector3d.h
changeset 0 c316ab048e9d
equal deleted inserted replaced
-1:000000000000 0:c316ab048e9d
       
     1 /*
       
     2  * Name        : Vector3d.h
       
     3  * Description : 
       
     4  * Project     : This file is part of OpenMAR, an Open Mobile Augmented Reality browser
       
     5  * Website     : http://OpenMAR.org
       
     6  *
       
     7  * Copyright (c) 2010 David Caabeiro
       
     8  *
       
     9  * All rights reserved. This program and the accompanying materials are made available 
       
    10  * under the terms of the Eclipse Public License v1.0 which accompanies this 
       
    11  * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
       
    12  *
       
    13  */
       
    14 
       
    15 #ifndef VECTOR3D_H_
       
    16 #define VECTOR3D_H_
       
    17 
       
    18 #include <e32math.h>
       
    19 
       
    20 #include "Scalar.h"
       
    21 
       
    22 /**
       
    23  * @brief Provides needed 3d-vector functionality and operations
       
    24  */
       
    25 class Vector3d
       
    26 {
       
    27 public:
       
    28     Vector3d(Scalar x = 0, Scalar y = 0, Scalar z = 0);
       
    29 
       
    30     Scalar Norm() const;
       
    31 
       
    32     static const Vector3d Cross(const Vector3d& lhs, const Vector3d& rhs);
       
    33 
       
    34 //private:
       
    35     Scalar mX;
       
    36     Scalar mY;
       
    37     Scalar mZ;
       
    38 };
       
    39 
       
    40 inline Vector3d::Vector3d(Scalar x, Scalar y, Scalar z)
       
    41     : mX(x), mY(y), mZ(z)
       
    42 {}
       
    43 
       
    44 inline Scalar Vector3d::Norm() const
       
    45 {
       
    46     Scalar sm = mX * mX + mY * mY + mZ * mZ;
       
    47 
       
    48     TReal norm = 0;
       
    49     Math::Sqrt(norm, sm);
       
    50 
       
    51     return norm;
       
    52 }
       
    53 
       
    54 inline const Vector3d Vector3d::Cross(const Vector3d& lhs, const Vector3d& rhs)
       
    55 {
       
    56     return Vector3d(lhs.mY * rhs.mZ - lhs.mZ * rhs.mY,
       
    57                     lhs.mZ * rhs.mX - lhs.mX * rhs.mZ,
       
    58                     lhs.mX * rhs.mY - lhs.mY * rhs.mX);
       
    59 }
       
    60 
       
    61 #endif