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

Last change on this file since 2861 was 2827, checked in by ldelgass, 12 years ago

Move Vector3/4Array typdefs to the Vector3/4.h headers and remove TypeDefs?.h.
Also misc. cleanups

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