Ignore:
Timestamp:
Mar 7, 2012, 12:21:30 PM (13 years ago)
Author:
ldelgass
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/nanovis/Vector4.h

    r2798 r2822  
    1717#define _VECTOR4_H_
    1818
    19 #include <stdio.h>
    20 #include <Trace.h>
     19#include "Trace.h"
    2120
    2221class Vector4 
     
    2524    float x, y, z, w;
    2625
    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.;
     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);
    3632    }
    3733
    38     void print(void) {
    39         TRACE("Vector4: (%.3f, %.3f, %.3f, %.3f)\n", x, y, z, w);
     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;
    4037    }
    4138
    42     Vector4 operator +(Vector4 &op2){
    43         return Vector4(x + op2.x, y + op2.y, z + op2.z, w + op2.w);
     39    void perspective_divide()
     40    {
     41        /* Divide vector by w */
     42        x /= w, y /= w, z /= w, w = 1.;
    4443    }
    4544
    46     Vector4 operator -(Vector4 &op2){
    47         return Vector4(x - op2.x, y - op2.y, z - op2.z, w - op2.w);
     45    void print() const
     46    {
     47        TRACE("Vector4: (%.3f, %.3f, %.3f, %.3f)\n", x, y, z, w);
    4848    }
    4949
    50     float operator *(Vector4 &op2) {
    51         return (x * op2.x) + (y * op2.y) + (z * op2.z) + (w * op2.w);
     50    Vector4 operator +(const Vector4& op2) const
     51    {
     52        return Vector4(x + op2.x, y + op2.y, z + op2.z, w + op2.w);
    5253    }
    5354
    54     Vector4 operator *(float op2){
    55         return Vector4(x * op2, y * op2, z * op2, w * op2);
     55    Vector4 operator -(const Vector4& op2) const
     56    {
     57        return Vector4(x - op2.x, y - op2.y, z - op2.z, w - op2.w);
    5658    }
    5759
    58     Vector4 operator /(float op2) {
    59         return Vector4(x / op2, y / op2, z / op2, w / op2);
     60    float operator *(const Vector4& op2) const
     61    {
     62        return (x * op2.x) + (y * op2.y) + (z * op2.z) + (w * op2.w);
    6063    }
    6164
    62     void operator <(Vector4 &op2) {
    63         set(op2.x, op2.y, op2.z, op2.w);
     65    Vector4 operator *(float op2) const
     66    {
     67        return Vector4(x * op2, y * op2, z * op2, w * op2);
    6468    }
    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;
     69
     70    Vector4 operator /(float op2) const
     71    {
     72        return Vector4(x / op2, y / op2, z / op2, w / op2);
    6773    }
    6874};
Note: See TracChangeset for help on using the changeset viewer.