include/vector.h
branchpyrit
changeset 78 9569e9f35374
parent 74 09aedbf5f95f
child 83 e3a2a5b26abb
equal deleted inserted replaced
77:dbe8438d5dca 78:9569e9f35374
    27 #ifndef VECTOR_H
    27 #ifndef VECTOR_H
    28 #define VECTOR_H
    28 #define VECTOR_H
    29 
    29 
    30 #include <math.h>
    30 #include <math.h>
    31 #include <iostream>
    31 #include <iostream>
       
    32 
       
    33 #include "common.h"
    32 
    34 
    33 using namespace std;
    35 using namespace std;
    34 
    36 
    35 /**
    37 /**
    36  * three cell vector
    38  * three cell vector
   164 	friend Vector3 operator*(const Vector3 &a,  const Vector3 &b)
   166 	friend Vector3 operator*(const Vector3 &a,  const Vector3 &b)
   165 	{
   167 	{
   166 		return Vector3(a.x * b.x, a.y * b.y, a.z * b.z);
   168 		return Vector3(a.x * b.x, a.y * b.y, a.z * b.z);
   167 	};
   169 	};
   168 
   170 
   169 	// print
   171 	// write
   170 	friend ostream & operator<<(ostream &st, const Vector3 &v)
   172 	friend ostream & operator<<(ostream &st, const Vector3 &v)
   171 	{
   173 	{
   172 		return st << "(" << v.x << ", " << v.y  << ", " << v.z << ")";
   174 		return st << "(" << v.x << "," << v.y  << "," << v.z << ")";
       
   175 	};
       
   176 
       
   177 	// read
       
   178 	friend istream & operator>>(istream &st, Vector3 &v)
       
   179 	{
       
   180 		char s[10];
       
   181 		st.getline(s, 10, '(');
       
   182 		st >> v.x;
       
   183 		st.getline(s, 10, ',');
       
   184 		st >> v.y;
       
   185 		st.getline(s, 10, ',');
       
   186 		st >> v.z;
       
   187 		st.getline(s, 10, ')');
       
   188 		return st;
   173 	};
   189 	};
   174 };
   190 };
   175 
   191 
   176 typedef Vector3 Colour;
   192 typedef Vector3 Colour;
   177 
   193