]> git.mxchange.org Git - simgear.git/blob - simgear/scene/sky/clouds3d/vec3fv.cpp
Clouds3D crashes because there is no Light
[simgear.git] / simgear / scene / sky / clouds3d / vec3fv.cpp
1 //------------------------------------------------------------------------------
2 // File : vec3fv.cpp
3 //------------------------------------------------------------------------------
4 // GLVU : Copyright 1997 - 2002 
5 //        The University of North Carolina at Chapel Hill
6 //------------------------------------------------------------------------------
7 // Permission to use, copy, modify, distribute and sell this software and its 
8 // documentation for any purpose is hereby granted without fee, provided that 
9 // the above copyright notice appear in all copies and that both that copyright 
10 // notice and this permission notice appear in supporting documentation. 
11 // Binaries may be compiled with this software without any royalties or 
12 // restrictions. 
13 //
14 // The University of North Carolina at Chapel Hill makes no representations 
15 // about the suitability of this software for any purpose. It is provided 
16 // "as is" without express or implied warranty.
17
18 //============================================================================
19 // vec3fv.cpp
20 //============================================================================
21
22 #include <stdio.h>
23 #include <math.h>
24
25 void Set3fv(float v[3], float x, float y, float z)
26 {
27   v[0]=x;
28   v[1]=y;
29   v[2]=z;
30 }
31
32 void Copy3fv(float A[3], const float B[3]) // A=B
33 {
34   A[0]=B[0];
35   A[1]=B[1];
36   A[2]=B[2];
37 }
38
39 void ScalarMult3fv(float c[3], const float a[3], float s) // c=a*s
40 {
41   c[0] = a[0] * s;
42   c[1] = a[1] * s;
43   c[2] = a[2] * s;
44 }
45
46 void ScalarDiv3fv(float v[3], float s)
47 {
48   v[0] /= s;
49   v[1] /= s;
50   v[2] /= s;
51 }
52
53 void Add3fv(float c[3], const float a[3], const float b[3]) // c = a + b
54 {
55   c[0] = a[0] + b[0];
56   c[1] = a[1] + b[1];
57   c[2] = a[2] + b[2];
58 }
59
60 void Subtract3fv(float c[3], const float a[3], const float b[3]) // c = a - b
61 {
62   c[0] = a[0] - b[0];
63   c[1] = a[1] - b[1];
64   c[2] = a[2] - b[2];
65 }
66
67 void Negate3fv(float a[3], const float b[3])  // a = -b
68 {
69   a[0] = -b[0];
70   a[1] = -b[1];
71   a[2] = -b[2];
72 }
73
74 float Length3fv(const float v[3])
75 {
76   return( (float)sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]) );
77 }
78
79 void Normalize3fv(float v[3])
80 {
81   float l = Length3fv(v);
82   v[0] /= l;
83   v[1] /= l;
84   v[2] /= l;
85 }
86
87 float DotProd3fv(const float a[3], const float b[3])
88 {
89   return( a[0]*b[0] + a[1]*b[1] + a[2]*b[2] );
90 }
91
92 void CrossProd3fv(float* C, const float* A, const float* B) // C = A X B
93
94   Set3fv(C, A[1]*B[2]-A[2]*B[1], A[2]*B[0]-A[0]*B[2], A[0]*B[1]-A[1]*B[0]);
95 }