~ubuntu-branches/ubuntu/warty/aqsis/warty

« back to all changes in this revision

Viewing changes to libaqsistypes/vector3d.cpp

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-08-24 07:25:04 UTC
  • Revision ID: james.westby@ubuntu.com-20040824072504-zf993vnevvisdsvb
Tags: upstream-0.9.1
Import upstream version 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Aqsis
 
2
// Copyright � 1997 - 2001, Paul C. Gregory
 
3
//
 
4
// Contact: pgregory@aqsis.com
 
5
//
 
6
// This library is free software; you can redistribute it and/or
 
7
// modify it under the terms of the GNU General Public
 
8
// License as published by the Free Software Foundation; either
 
9
// version 2 of the License, or (at your option) any later version.
 
10
//
 
11
// This library is distributed in the hope that it will be useful,
 
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
// General Public License for more details.
 
15
//
 
16
// You should have received a copy of the GNU General Public
 
17
// License along with this library; if not, write to the Free Software
 
18
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 
 
20
 
 
21
/** \file
 
22
                \brief Implements the CqVector3D class.
 
23
                \author Paul C. Gregory (pgregory@aqsis.com)
 
24
*/
 
25
 
 
26
#include        <math.h>
 
27
 
 
28
#include        "aqsis.h"
 
29
#include        "vector3d.h"
 
30
#include        "vector4d.h"
 
31
#include        "color.h"
 
32
 
 
33
START_NAMESPACE( Aqsis )
 
34
 
 
35
//---------------------------------------------------------------------
 
36
/** Copy constructor from 4D Vector.
 
37
 */
 
38
 
 
39
CqVector3D::CqVector3D( const CqVector4D &From )
 
40
{
 
41
    *this = From;
 
42
}
 
43
 
 
44
 
 
45
//---------------------------------------------------------------------
 
46
/** Copy constructor from color.
 
47
 */
 
48
 
 
49
CqVector3D::CqVector3D( const CqColor &From )
 
50
{
 
51
    *this = From;
 
52
}
 
53
 
 
54
 
 
55
//---------------------------------------------------------------------
 
56
/** Cross product of two vectors.
 
57
 */
 
58
 
 
59
CqVector3D operator%( const CqVector3D &a, const CqVector3D &b )
 
60
{
 
61
    return ( CqVector3D( ( a.m_y * b.m_z ) - ( a.m_z * b.m_y ),
 
62
                         ( a.m_z * b.m_x ) - ( a.m_x * b.m_z ),
 
63
                         ( a.m_x * b.m_y ) - ( a.m_y * b.m_x ) ) );
 
64
}
 
65
 
 
66
//---------------------------------------------------------------------
 
67
/** Sets this vector to be the cross product of itself and another vector.
 
68
 */
 
69
 
 
70
CqVector3D &CqVector3D::operator%=( const CqVector3D &From )
 
71
{
 
72
    CqVector3D  vecTemp( *this );
 
73
 
 
74
    m_x = ( vecTemp.m_y * From.m_z ) - ( vecTemp.m_z * From.m_y );
 
75
    m_y = ( vecTemp.m_z * From.m_x ) - ( vecTemp.m_x * From.m_z );
 
76
    m_z = ( vecTemp.m_x * From.m_y ) - ( vecTemp.m_y * From.m_x );
 
77
 
 
78
    return ( *this );
 
79
}
 
80
 
 
81
//---------------------------------------------------------------------
 
82
/** Copy from specified 4D vector.
 
83
 */
 
84
 
 
85
CqVector3D &CqVector3D::operator=( const CqVector4D &From )
 
86
{
 
87
    if ( From.h() != 1.0 )
 
88
    {
 
89
        m_x = From.x() / From.h();
 
90
        m_y = From.y() / From.h();
 
91
        m_z = From.z() / From.h();
 
92
    }
 
93
    else
 
94
    {
 
95
        m_x = From.x();
 
96
        m_y = From.y();
 
97
        m_z = From.z();
 
98
    }
 
99
 
 
100
    return ( *this );
 
101
}
 
102
 
 
103
 
 
104
//---------------------------------------------------------------------
 
105
/** Copy from specified color.
 
106
 */
 
107
 
 
108
CqVector3D &CqVector3D::operator=( const CqColor &From )
 
109
{
 
110
    m_x = From.fRed();
 
111
    m_y = From.fGreen();
 
112
    m_z = From.fBlue();
 
113
 
 
114
    return ( *this );
 
115
}
 
116
 
 
117
 
 
118
//----------------------------------------------------------------------
 
119
/** Outputs a vector to an output stream.
 
120
 * \param Stream Stream to output the matrix to.
 
121
 * \param Vector The vector to output.
 
122
 * \return The new state of Stream.
 
123
 */
 
124
 
 
125
std::ostream &operator<<( std::ostream &Stream, const CqVector3D &Vector )
 
126
{
 
127
    Stream << Vector.m_x << "," << Vector.m_y << "," << Vector.m_z;
 
128
    return ( Stream );
 
129
}
 
130
 
 
131
 
 
132
//---------------------------------------------------------------------
 
133
 
 
134
END_NAMESPACE( Aqsis )