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

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

Const correctness fixes, pass vector/matrix objects by reference, various
formatting and style cleanups, don't spam syslog and uncomment openlog() call.
Still needs to be compiled with -DWANT_TRACE to get tracing, but now trace
output will be output to file in /tmp.

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