source: trunk/packages/vizservers/nanovis/Vector4.h @ 2277

Last change on this file since 2277 was 2096, checked in by ldelgass, 13 years ago

Normalize line endings, set eol-style to native on *.cpp, *.h files

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
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#include <Trace.h>
21
22class Vector4 
23{
24public:
25    float x, y, z, w;
26
27    Vector4(void) {
28        /*empty*/
29    }
30    Vector4(float x_val, float y_val, float z_val, float w_val) {
31        set(x_val, y_val, z_val, w_val);
32    }
33    void perspective_devide(void) {
34        /* Divide vector by w */
35        x /= w, y /= w, z /= w, w = 1.;
36    }
37
38    void print(void) {
39        TRACE("Vector4: (%.3f, %.3f, %.3f, %.3f)\n", x, y, z, w);
40    }
41
42    Vector4 operator +(Vector4 &op2){
43        return Vector4(x + op2.x, y + op2.y, z + op2.z, w + op2.w);
44    }
45
46    Vector4 operator -(Vector4 &op2){
47        return Vector4(x - op2.x, y - op2.y, z - op2.z, w - op2.w);
48    }
49
50    float operator *(Vector4 &op2) {
51        return (x * op2.x) + (y * op2.y) + (z * op2.z) + (w * op2.w);
52    }
53
54    Vector4 operator *(float op2){
55        return Vector4(x * op2, y * op2, z * op2, w * op2);
56    }
57
58    Vector4 operator /(float op2) {
59        return Vector4(x / op2, y / op2, z / op2, w / op2);
60    }
61
62    void operator <(Vector4 &op2) {
63        set(op2.x, op2.y, op2.z, op2.w);
64    }
65    void set(float x_val, float y_val, float z_val, float w_val) {
66        x = x_val, y = y_val, z = z_val, w = w_val;
67    }
68};
69
70#endif
Note: See TracBrowser for help on using the repository browser.