Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
vectorlib.h
Package: VCtracking.rar [view]
Upload User: xuczgm
Upload Date: 2022-04-25
Package Size: 8601k
Code Size: 2k
Category:
Special Effects
Development Platform:
Visual C++
- #ifndef __VECTORLIB_H_INCLUDED__
- #define __VECTORLIB_H_INCLUDED__
- #include <math.h>
- /*************************** Macros and constants ***************************/
- // returns a number ranging from -1.0 to 1.0
- #define FRAND (((float)rand()-(float)rand())/RAND_MAX)
- #define Clamp(x, min, max) x = (x<min ? min : x<max ? x : max);
- #define SQUARE(x) (x)*(x)
- struct vector3_t
- {
- vector3_t(float x, float y, float z) : x(x), y(y), z(z) {}
- vector3_t(const vector3_t &v) : x(v.x), y(v.y), z(v.z) {}
- vector3_t() : x(0.0f), y(0.0f), z(0.0f) {}
- vector3_t& operator=(const vector3_t &rhs)
- {
- x = rhs.x;
- y = rhs.y;
- z = rhs.z;
- return *this;
- }
- // vector add
- vector3_t operator+(const vector3_t &rhs) const
- {
- return vector3_t(x + rhs.x, y + rhs.y, z + rhs.z);
- }
- // vector subtract
- vector3_t operator-(const vector3_t &rhs) const
- {
- return vector3_t(x - rhs.x, y - rhs.y, z - rhs.z);
- }
- // scalar multiplication
- vector3_t operator*(const float scalar) const
- {
- return vector3_t(x * scalar, y * scalar, z * scalar);
- }
- // dot product
- float operator*(const vector3_t &rhs) const
- {
- return x * rhs.x + y * rhs.y + z * rhs.z;
- }
- // cross product
- vector3_t operator^(const vector3_t &rhs) const
- {
- return vector3_t(y * rhs.z - rhs.y * z, rhs.x * z - x * rhs.z, x * rhs.y - rhs.x * y);
- }
- float& operator[](int index)
- {
- return v[index];
- }
- float Length()
- {
- float length = (float)sqrt(SQUARE(x) + SQUARE(y) + SQUARE(z));
- return (length != 0.0f) ? length : 1.0f;
- }
- /*****************************************************************************
- Normalize()
- Helper function to normalize vectors
- *****************************************************************************/
- vector3_t Normalize()
- {
- *this = *this * (1.0f/Length());
- return *this;
- }
- union
- {
- struct
- {
- float x;
- float y;
- float z;
- };
- float v[3];
- };
- };
- #endif __VECTORLIB_H_INCLUDED__