Coin Logo http://www.sim.no/
http://www.coin3d.org/

SbVec3f.h
1#ifndef COIN_SBVEC3F_H
2#define COIN_SBVEC3F_H
3
4/**************************************************************************\
5 *
6 * This file is part of the Coin 3D visualization library.
7 * Copyright (C) by Kongsberg Oil & Gas Technologies.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * ("GPL") version 2 as published by the Free Software Foundation.
12 * See the file LICENSE.GPL at the root directory of this source
13 * distribution for additional information about the GNU GPL.
14 *
15 * For using Coin with software that can not be combined with the GNU
16 * GPL, and for taking advantage of the additional benefits of our
17 * support services, please contact Kongsberg Oil & Gas Technologies
18 * about acquiring a Coin Professional Edition License.
19 *
20 * See http://www.coin3d.org/ for more information.
21 *
22 * Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY.
23 * http://www.sim.no/ sales@sim.no coin-support@coin3d.org
24 *
25\**************************************************************************/
26
27#include <stdio.h>
28
29#include <Inventor/SbBasic.h>
30#ifndef NDEBUG
31#include <Inventor/errors/SoDebugError.h>
32#endif // !NDEBUG
33
34class SbPlane;
35class SbVec3d;
36class SbVec3b;
37class SbVec3s;
38class SbVec3i32;
39
40class COIN_DLL_API SbVec3f {
41public:
42 SbVec3f(void) { }
43 SbVec3f(const float v[3]) { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; }
44 SbVec3f(float x, float y, float z) { vec[0] = x; vec[1] = y; vec[2] = z; }
45 explicit SbVec3f(const SbVec3d & v) { setValue(v); }
46 explicit SbVec3f(const SbVec3b & v) { setValue(v); }
47 explicit SbVec3f(const SbVec3s & v) { setValue(v); }
48 explicit SbVec3f(const SbVec3i32 & v) { setValue(v); }
49 SbVec3f(const SbPlane & p0, const SbPlane & p1, const SbPlane & p2);
50
51 SbVec3f & setValue(const float v[3]) { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; return *this; }
52 SbVec3f & setValue(float x, float y, float z) { vec[0] = x; vec[1] = y; vec[2] = z; return *this; }
53 SbVec3f & setValue(const SbVec3f & barycentric,
54 const SbVec3f & v0,
55 const SbVec3f & v1,
56 const SbVec3f & v2);
57 SbVec3f & setValue(const SbVec3d & v);
58 SbVec3f & setValue(const SbVec3b & v);
59 SbVec3f & setValue(const SbVec3s & v);
60 SbVec3f & setValue(const SbVec3i32 & v);
61
62 const float * getValue(void) const { return vec; }
63 void getValue(float & x, float & y, float & z) const { x = vec[0]; y = vec[1]; z = vec[2]; }
64
65 float & operator [] (int i) { return vec[i]; }
66 const float & operator [] (int i) const { return vec[i]; }
67
68 SbBool equals(const SbVec3f & v, float tolerance) const;
69 SbVec3f cross(const SbVec3f & v) const;
70 float dot(const SbVec3f & v) const { return vec[0] * v[0] + vec[1] * v[1] + vec[2] * v[2]; }
71 SbVec3f getClosestAxis(void) const;
72 float length(void) const;
73 float sqrLength(void) const { return vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]; }
74 float normalize(void);
75 void negate(void) { vec[0] = -vec[0]; vec[1] = -vec[1]; vec[2] = -vec[2]; }
76
77 SbVec3f & operator *= (float d) { vec[0] *= d; vec[1] *= d; vec[2] *= d; return *this; }
78 SbVec3f & operator /= (float d) { SbDividerChk("SbVec3f::operator/=(float)", d); return operator *= (1.0f / d); }
79 SbVec3f & operator += (const SbVec3f & v) { vec[0] += v[0]; vec[1] += v[1]; vec[2] += v[2]; return *this; }
80 SbVec3f & operator -= (const SbVec3f & v) { vec[0] -= v[0]; vec[1] -= v[1]; vec[2] -= v[2]; return *this; }
81 SbVec3f operator - (void) const { return SbVec3f(-vec[0], -vec[1], -vec[2]); }
82
83 void print(FILE * fp) const;
84
85protected:
86 float vec[3];
87
88}; // SbVec3f
89
90COIN_DLL_API inline SbVec3f operator * (const SbVec3f & v, float d) {
91 SbVec3f val(v); val *= d; return val;
92}
93
94COIN_DLL_API inline SbVec3f operator * (float d, const SbVec3f & v) {
95 SbVec3f val(v); val *= d; return val;
96}
97
98COIN_DLL_API inline SbVec3f operator / (const SbVec3f & v, float d) {
99 SbDividerChk("operator/(SbVec3f,float)", d);
100 SbVec3f val(v); val /= d; return val;
101}
102
103COIN_DLL_API inline SbVec3f operator + (const SbVec3f & v1, const SbVec3f & v2) {
104 SbVec3f v(v1); v += v2; return v;
105}
106
107COIN_DLL_API inline SbVec3f operator - (const SbVec3f & v1, const SbVec3f & v2) {
108 SbVec3f v(v1); v -= v2; return v;
109}
110
111COIN_DLL_API inline int operator == (const SbVec3f & v1, const SbVec3f & v2) {
112 return ((v1[0] == v2[0]) && (v1[1] == v2[1]) && (v1[2] == v2[2]));
113}
114
115COIN_DLL_API inline int operator != (const SbVec3f & v1, const SbVec3f & v2) {
116 return !(v1 == v2);
117}
118
119#endif // !COIN_SBVEC3F_H
The SbPlane class represents a plane in 3D space.
Definition SbPlane.h:34
Definition SbVec3b.h:39
The SbVec3d class is a 3 dimensional vector with double precision floating point coordinates.
Definition SbVec3d.h:39
The SbVec3f class is a 3 dimensional vector with floating point coordinates.
Definition SbVec3f.h:40
SbVec3f(const SbVec3d &v)
Definition SbVec3f.h:45
SbVec3f(const SbVec3b &v)
Definition SbVec3f.h:46
SbVec3f & setValue(const float v[3])
Definition SbVec3f.h:51
const float * getValue(void) const
Definition SbVec3f.h:62
void getValue(float &x, float &y, float &z) const
Definition SbVec3f.h:63
SbVec3f(const float v[3])
Definition SbVec3f.h:43
SbVec3f(const SbVec3s &v)
Definition SbVec3f.h:47
float dot(const SbVec3f &v) const
Definition SbVec3f.h:70
void negate(void)
Definition SbVec3f.h:75
SbVec3f(void)
Definition SbVec3f.h:42
SbVec3f(float x, float y, float z)
Definition SbVec3f.h:44
SbVec3f & setValue(float x, float y, float z)
Definition SbVec3f.h:52
SbVec3f(const SbVec3i32 &v)
Definition SbVec3f.h:48
float sqrLength(void) const
Definition SbVec3f.h:73
Definition SbVec3i32.h:39
The SbVec3s class is a 3 dimensional vector with short integer coordinates.
Definition SbVec3s.h:39

Copyright © 1998-2010 by Kongsberg Oil & Gas Technologies. All rights reserved.

Generated on Wed Jul 17 2024 for Coin by Doxygen 1.12.0.