VTFLib
A C and C++ API that, with a few simple functions, can open and save .vtf and .vmt files.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
VTFMathlib.h
Go to the documentation of this file.
1 /*
2  * VTFLib
3  * Copyright (C) 2005-2010 Neil Jedrzejewski & Ryan Gregg
4 
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later
9  * version.
10  */
11 
12 // ============================================================
13 // NOTE: This file is commented for compatibility with Doxygen.
14 // ============================================================
22 #ifndef VTFLIB_VTFMATHLIB_H
23 #define VTFLIB_VTFMATHLIB_H
24 
25 #include "stdafx.h"
26 
27 // Defines for data alignment
28 //---------------------------
29 #define CACHE_LINE 16
30 
31 #ifdef __WINDOWS__
32 # define CACHE_ALIGN __declspec(align(CACHE_LINE))
33 #else
34 # define CACHE_ALIGN __attribute__((aligned (CACHE_LINE)))
35 #endif
36 
37 // Macros
38 //-------
39 #define drand48() (((vlSingle) rand())/((vlSingle) RAND_MAX))
40 
41 // Vector class
42 //-------------
44 
47 class Vector
48 {
49  public:
50 
54 
56  inline void Init(vlSingle vX, vlSingle vY, vlSingle vZ)
57  {
58  x = vX;
59  y = vY;
60  z = vZ;
61  }
62 
64  inline void Init(void)
65  {
66  x = 0.0f;
67  y = 0.0f;
68  z = 0.0f;
69  }
70 };
71 
72 // VectorAligned class
73 //--------------------
75 
80 class CACHE_ALIGN VectorAligned
81 {
82  public:
83 
87 
90  {
91  x = vX;
92  y = vY;
93  z = vZ;
94  }
95 
97  inline VectorAligned(void)
98  {
99  x = 0.0f;
100  y = 0.0f;
101  z = 0.0f;
102  }
103 };
104 
105 void VecAdd(Vector *a, Vector *b, Vector *sum);
106 void VecSub(Vector *a, Vector *b, Vector *diff);
107 void VecScale(Vector *v, vlSingle scale);
108 vlSingle VecDot(Vector *u, Vector *v);
109 void VecReflect(Vector *axis, Vector *v, Vector *r);
110 vlInt Intersect(Vector *v);
111 
112 #endif //VTF_MATHLIB
void Init(vlSingle vX, vlSingle vY, vlSingle vZ)
Initialise the vector with the three given values.
Definition: VTFMathlib.h:56
Simple 3D Vector class.
Definition: VTFMathlib.h:47
vlSingle x
Vector value in the X axis.
Definition: VTFMathlib.h:51
vlSingle x
Vector value in the X axis.
Definition: VTFMathlib.h:84
Application framework header plus VTFLib custom data types.
void Init(void)
Initialise the vector defaulting all values to zero.
Definition: VTFMathlib.h:64
void VecReflect(Vector *axis, Vector *v, Vector *r)
Vector reflect function.
Definition: VTFMathlib.cpp:43
vlSingle y
Vector value in the Y axis.
Definition: VTFMathlib.h:52
void VecSub(Vector *a, Vector *b, Vector *diff)
Vector subtraction function.
Definition: VTFMathlib.cpp:24
VectorAligned(void)
Initialise the vector defaulting all values to zero.
Definition: VTFMathlib.h:97
VectorAligned(vlSingle vX, vlSingle vY, vlSingle vZ)
Initialise the vector with the three given values.
Definition: VTFMathlib.h:89
vlSingle z
Vector value in the Z axis.
Definition: VTFMathlib.h:53
signed int vlInt
Signed integer value.
Definition: stdafx.h:55
Simple Aligned 3D Vector class.
Definition: VTFMathlib.h:80
vlInt Intersect(Vector *v)
Vector intersect function.
Definition: VTFMathlib.cpp:50
vlSingle z
Vector value in the Z axis.
Definition: VTFMathlib.h:86
vlSingle VecDot(Vector *u, Vector *v)
Vector dot-product function.
Definition: VTFMathlib.cpp:38
vlSingle y
Vector value in the Y axis.
Definition: VTFMathlib.h:85
float vlSingle
Floating point number.
Definition: stdafx.h:59
void VecAdd(Vector *a, Vector *b, Vector *sum)
Vector addition function.
Definition: VTFMathlib.cpp:17
void VecScale(Vector *v, vlSingle scale)
Vector scale function.
Definition: VTFMathlib.cpp:31