types.h

Mon, 22 Apr 2013 16:30:33 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Mon, 22 Apr 2013 16:30:33 +0300
changeset 128
73a7edf82ca9
parent 121
7e87c85ad092
child 135
c243df39913e
permissions
-rw-r--r--

Warn for save failures with the save and save as actions, also provide with a button to save the file under a different name.

#ifndef __TYPES_H__
#define __TYPES_H__

#include "types.h"
#include "common.h"

class matrix;

// =============================================================================
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// =============================================================================
// vertex
// 
// Vertex class. Not to be confused with LDVertex, which is a vertex used in an
// LDraw code file.
// =============================================================================
class vertex {
public:
	double x, y, z;
	
	vertex () {}
	vertex (double fX, double fY, double fZ) {
		x = fX;
		y = fY;
		z = fZ;
	}
	
	// =========================================================================
	void move (vertex other) {
		x += other.x;
		y += other.y;
		z += other.z;
	}
	
	// =========================================================================
	vertex& operator+= (vertex other) {
		move (other);
		return *this;
	}
	
	// =========================================================================
	vertex operator/ (const double d) {
		vertex other (*this);
		return other /= d;
	}
	
	// =========================================================================
	vertex& operator/= (const double d) {
		x /= d;
		y /= d;
		z /= d;
		return *this;
	}
	
	// =========================================================================
	vertex operator- () const {
		return vertex (-x, -y, -z);
	}
	
	// =========================================================================
	// Midpoint between this vertex and another vertex.
	vertex midpoint (vertex& other);
	str getStringRep (const bool bMangled);
	void transform (matrix mMatrix, vertex pos);
};

// =============================================================================
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// =============================================================================
// matrix
// 
// A mathematical 3x3 matrix
// =============================================================================
class matrix {
public:
	double faValues[9];
	
	// Constructors
	matrix () {}
	matrix (std::vector<double> vals);
	matrix (double fVal);
	matrix (double a, double b, double c,
		double d, double e, double f,
		double g, double h, double i);
	
	matrix mult (matrix mOther);
	
	matrix& operator= (matrix mOther) {
		memcpy (&faValues[0], &mOther.faValues[0], sizeof faValues);
		return *this;
	}
	
	matrix operator* (matrix mOther) {
		return mult (mOther);
	}
	
	inline double& operator[] (const uint uIndex) {
		return faValues[uIndex];
	}
	
	void zero ();
	void testOutput ();
	str getStringRep();
};

#endif // __TYPES_H__

mercurial