[1028] | 1 | |
---|
| 2 | /* |
---|
| 3 | * ---------------------------------------------------------------------- |
---|
| 4 | * Vector4.h: Vector4 class |
---|
| 5 | * |
---|
| 6 | * ====================================================================== |
---|
| 7 | * AUTHOR: Wei Qiao <qiaow@purdue.edu> |
---|
| 8 | * Purdue Rendering and Perceptualization Lab (PURPL) |
---|
| 9 | * |
---|
| 10 | * Copyright (c) 2004-2006 Purdue Research Foundation |
---|
| 11 | * |
---|
| 12 | * See the file "license.terms" for information on usage and |
---|
| 13 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
| 14 | * ====================================================================== |
---|
| 15 | */ |
---|
| 16 | #ifndef _VECTOR4_H_ |
---|
| 17 | #define _VECTOR4_H_ |
---|
| 18 | |
---|
| 19 | #include <stdio.h> |
---|
| 20 | |
---|
| 21 | class Vector4 |
---|
| 22 | { |
---|
| 23 | public: |
---|
| 24 | float x, y, z, w; |
---|
| 25 | |
---|
| 26 | Vector4(void) { |
---|
| 27 | /*empty*/ |
---|
| 28 | } |
---|
| 29 | Vector4(float x_val, float y_val, float z_val, float w_val) { |
---|
| 30 | set(x_val, y_val, z_val, w_val); |
---|
| 31 | } |
---|
| 32 | void perspective_devide(void) { |
---|
| 33 | /* Divide vector by w */ |
---|
| 34 | x /= w, y /= w, z /= w, w = 1.; |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | void print(void) { |
---|
| 38 | fprintf(stderr, "Vector4: (%.3f, %.3f, %.3f, %.3f)\n", x, y, z, w); |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | Vector4 operator +(Vector4 &op2){ |
---|
| 42 | return Vector4(x + op2.x, y + op2.y, z + op2.z, w + op2.w); |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | Vector4 operator -(Vector4 &op2){ |
---|
| 46 | return Vector4(x - op2.x, y - op2.y, z - op2.z, w - op2.w); |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | float operator *(Vector4 &op2) { |
---|
| 50 | return (x * op2.x) + (y * op2.y) + (z * op2.z) + (w * op2.w); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | Vector4 operator *(float op2){ |
---|
| 54 | return Vector4(x * op2, y * op2, z * op2, w * op2); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | Vector4 operator /(float op2) { |
---|
| 58 | return Vector4(x / op2, y / op2, z / op2, w / op2); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | void operator <(Vector4 &op2) { |
---|
| 62 | set(op2.x, op2.y, op2.z, op2.w); |
---|
| 63 | } |
---|
| 64 | void set(float x_val, float y_val, float z_val, float w_val) { |
---|
| 65 | x = x_val, y = y_val, z = z_val, w = w_val; |
---|
| 66 | } |
---|
| 67 | }; |
---|
| 68 | |
---|
| 69 | #endif |
---|