Coin  4.0.3
Coin3D core library
Loading...
Searching...
No Matches
SbVec3us.h
1#ifndef COIN_SBVEC3US_H
2#define COIN_SBVEC3US_H
3
4/**************************************************************************\
5 * Copyright (c) Kongsberg Oil & Gas Technologies AS
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * Neither the name of the copyright holder nor the names of its
20 * contributors may be used to endorse or promote products derived from
21 * this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34\**************************************************************************/
35
36#include <cstdio>
37#include <Inventor/SbBasic.h>
38#include <Inventor/system/inttypes.h>
39#include <Inventor/SbByteBuffer.h>
40#include <Inventor/SbString.h>
41
42#ifndef NDEBUG
43#include <Inventor/errors/SoDebugError.h>
44#endif // !NDEBUG
45
46class SbVec3s;
47class SbVec3ub;
48class SbVec3ui32;
49
51public:
52 SbVec3us(void) { }
53 SbVec3us(const unsigned short v[3]) { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; }
54 SbVec3us(unsigned short x, unsigned short y, unsigned short z) { vec[0] = x; vec[1] = y; vec[2] = z; }
55 explicit SbVec3us(const SbVec3s & v) { setValue(v); }
56 explicit SbVec3us(const SbVec3ub & v) { setValue(v); }
57 explicit SbVec3us(const SbVec3ui32 & v) { setValue(v); }
58
59 SbVec3us & setValue(const unsigned short v[3]) { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; return *this; }
60 SbVec3us & setValue(unsigned short x, unsigned short y, unsigned short z) { vec[0] = x; vec[1] = y; vec[2] = z; return *this; }
61 SbVec3us & setValue(const SbVec3s & v);
62 SbVec3us & setValue(const SbVec3ub & v);
63 SbVec3us & setValue(const SbVec3ui32 & v);
64
65 const unsigned short * getValue(void) const { return vec; }
66 void getValue(unsigned short & x, unsigned short & y, unsigned short & z) const { x = vec[0]; y = vec[1]; z = vec[2]; }
67
68 unsigned short & operator [] (int i) { return vec[i]; }
69 const unsigned short & operator [] (int i) const { return vec[i]; }
70
71 int32_t dot(const SbVec3us & v) const { return vec[0] * v[0] + vec[1] * v[1] + vec[2] * v[2]; }
72 void negate(void);
73
74 SbVec3us & operator *= (int d) { vec[0] = (unsigned short)(vec[0] * d); vec[1] = (unsigned short)(vec[1] * d); vec[2] = (unsigned short)(vec[2] * d); return *this; }
75 SbVec3us & operator *= (double d);
76 SbVec3us & operator /= (int d) { SbDividerChk("SbVec3us::operator/=(int)", d); vec[0] = (unsigned short)(vec[0] / d); vec[1] = (unsigned short)(vec[1] / d); vec[2] = (unsigned short)(vec[2] / d); return *this; }
77 SbVec3us & operator /= (double d) { SbDividerChk("SbVec3us::operator/=(double)", d); return operator *= (1.0 / d); }
78 SbVec3us & operator += (const SbVec3us & v) { vec[0] += v[0]; vec[1] += v[1]; vec[2] += v[2]; return *this; }
79 SbVec3us & operator -= (const SbVec3us & v) { vec[0] -= v[0]; vec[1] -= v[1]; vec[2] -= v[2]; return *this; }
80 SbVec3us operator - (void) const { SbVec3us v(*this); v.negate(); return v; }
81
82protected:
83 unsigned short vec[3];
84
85}; // SbVec3us
86
87COIN_DLL_API inline SbVec3us operator * (const SbVec3us & v, int d) {
88 SbVec3us val(v); val *= d; return val;
89}
90
91COIN_DLL_API inline SbVec3us operator * (const SbVec3us & v, double d) {
92 SbVec3us val(v); val *= d; return val;
93}
94
95COIN_DLL_API inline SbVec3us operator * (int d, const SbVec3us & v) {
96 SbVec3us val(v); val *= d; return val;
97}
98
99COIN_DLL_API inline SbVec3us operator * (double d, const SbVec3us & v) {
100 SbVec3us val(v); val *= d; return val;
101}
102
103COIN_DLL_API inline SbVec3us operator / (const SbVec3us & v, int d) {
104 SbDividerChk("operator/(SbVec3us,int)", d);
105 SbVec3us val(v); val /= d; return val;
106}
107
108COIN_DLL_API inline SbVec3us operator / (const SbVec3us & v, double d) {
109 SbDividerChk("operator/(SbVec3us,double)", d);
110 SbVec3us val(v); val /= d; return val;
111}
112
113COIN_DLL_API inline SbVec3us operator + (const SbVec3us & v1, const SbVec3us & v2) {
114 SbVec3us v(v1); v += v2; return v;
115}
116
117COIN_DLL_API inline SbVec3us operator - (const SbVec3us & v1, const SbVec3us & v2) {
118 SbVec3us v(v1); v -= v2; return v;
119}
120
121COIN_DLL_API inline int operator == (const SbVec3us & v1, const SbVec3us & v2) {
122 return ((v1[0] == v2[0]) && (v1[1] == v2[1]) && (v1[2] == v2[2]));
123}
124
125COIN_DLL_API inline int operator != (const SbVec3us & v1, const SbVec3us & v2) {
126 return !(v1 == v2);
127}
128
129#endif // !COIN_SBVEC3US_H
The SbList class is a template container class for lists.
Definition SbList.h:70
SbList(const int sizehint=DEFAULTSIZE)
Definition SbList.h:78
Type operator[](const int index) const
Definition SbList.h:195
The SbVec3s class is a 3 dimensional vector with short integer coordinates.
Definition SbVec3s.h:51
Definition SbVec3ub.h:46
Definition SbVec3ui32.h:46
Definition SbVec3us.h:50