VIZ++ Class: Vector3f

 VIZ++ Class Library  VIZ++ Samples  VIZ++ ClassTree 

Source code

/*
 * Vector3f.h 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


#pragma once

#include <viz++/Vector.h>
#include <viz++/Vertex.h>

namespace VIZ {

#define DIM_THREE (3)
  
class Vector3f : public Vector<float, DIM_THREE> {

public:
  Vector3f()
  :Vector<float, DIM_THREE>()
  {
  }
  
  Vector3f(float x, float y, float z)
  :Vector<float, DIM_THREE>()
  {
    float f[DIM_THREE];
    f[0] = x;
    f[1] = y;
    f[2] = z;
    set(f, 3);
  }

  Vector3f(const Vertex<3>& vertex)
  :Vector<float, DIM_THREE>()
  {
    float f[DIM_THREE];
    for (int i = 0; i<DIM_THREE; i++) {
      f[i] = vertex.value[i];
    }
    set(f, 3);
  }

  static Vector3f crossProduct(const Vector<float, DIM_THREE>& v1, const Vector<float, DIM_THREE>& v2)
  {
    return Vector3f(
      v1[1] * v2[2] - v1[2] * v2[1], 
      v1[2] * v2[0] - v1[0] * v2[2], 
      v1[0] * v2[1] - v1[1] * v2[0]);
  }

  static Vector3f crossProduct(const Vector3f& v1, const Vector3f& v2)
  {
    return Vector3f(
      v1[1] * v2[2] - v1[2] * v2[1], 
      v1[2] * v2[0] - v1[0] * v2[2], 
      v1[0] * v2[1] - v1[1] * v2[0]);
  }
  
  Vector3f crossProduct(const Vector<float, DIM_THREE> &vec) const
  {
    return crossProduct(*this, vec);
  }

};

}



Last modified: 10 Feb 2017

Copyright (c) 2009-2017 Antillia.com ALL RIGHTS RESERVED.