Commit ccacfa3c authored by gilles's avatar gilles

Add some features to lauch the project :

- complete homogeneous matrix class
- specification of Color, Vector3d and Point3d
- global code (global.h/cpp, config.h)
- Makefile
parent a002aea3
/*****************************************************************************
* class LrColor (specification) *
* *
* author : Gilles Subrenat *
* creation : Sunday, March 2 2008 (3/2/2008) *
* note : *
*****************************************************************************/
#ifndef LRCOLOR_H
#define LRCOLOR_H
class LrColor
{
public:
static const LrColor BLACK;
static const LrColor WHITE;
static const LrColor RED;
static const LrColor GREEN;
static const LrColor BLUE;
static const LrColor CYAN;
static const LrColor MAGENTA;
static const LrColor YELLOW;
// constructors and destructor
// ***************************
LrColor();
LrColor(const LrColor &source);
LrColor(Real red, Real green, Real blue);
explicit LrColor(Real grey);
virtual ~LrColor();
// assignement operator(s)
// ***********************
LrColor & operator = (const LrColor &source);
LrColor & operator += (const LrColor &source);
LrColor & operator += (Real grey);
LrColor & operator -= (const LrColor &source);
LrColor & operator -= (Real grey);
LrColor & operator *= (const LrColor &source);
LrColor & operator *= (Real factor);
LrColor & operator /= (Real factor);
// comparison operator(s)
// **********************
friend bool operator == (const LrColor &lhs, const LrColor &rhs);
friend bool operator != (const LrColor &lhs, const LrColor &rhs);
// "mathematical" operator(s)
// **************************
friend LrColor operator + (const LrColor &lhs, const LrColor &rhs);
friend LrColor operator + (Real lhs, const LrColor &rhs);
friend LrColor operator + (const LrColor &lhs, Real rhs);
friend LrColor operator - (const LrColor &lhs, const LrColor &rhs);
friend LrColor operator - (Real lhs, const LrColor &rhs);
friend LrColor operator - (const LrColor &lhs, Real rhs);
friend LrColor operator * (const LrColor &lhs, const LrColor &rhs);
friend LrColor operator * (Real lhs, const LrColor &rhs);
friend LrColor operator * (const LrColor &lhs, Real rhs);
friend LrColor operator / (const LrColor &lhs, Real rhs);
// accessors
// *********
Real getRed() const;
void setRed(Real red);
Real getGreen() const;
void setGreen(Real green);
Real getBlue() const;
void setBlue(Real blue);
void setRGB(Real red, Real green, Real blue);
Real getGrey() const;
void setGrey(Real grey);
Real getLuminosity() const;
private:
// data
// ****
Real m_red;
Real m_green;
Real m_blue;
};
#endif
This diff is collapsed.
/*****************************************************************************
* class LrMatrix (specification) *
* *
* author : Gilles Subrenat *
* creation : Sunday, March 2 2008 (3/2/2008) *
* note : homogeneous 3d-matrix *
* (r11 r12 r14 t1 *
* r21 r22 r24 t2 *
* r31 r32 r34 t3 *
* 0 0 0 1) *
* let M, N are matrix and U is vector (or point) *
* let V = N*M*U *
* M is applied first and N last *
*****************************************************************************/
#ifndef LRMATRIX_H
#define LRMATRIX_H
#include "LrPoint3d.h"
#include "LrVector3d.h"
class LrMatrix
{
public:
// constructors and destructor
// ***************************
LrMatrix();
LrMatrix(const LrMatrix &source);
LrMatrix * clone() const;
LrMatrix(Real coeffs[3][4]);
LrMatrix(Real c11, Real c12, Real c13, Real c14,
Real c21, Real c22, Real c23, Real c24,
Real c31, Real c32, Real c33, Real c34);
virtual ~LrMatrix();
// assignement operator(s)
// ***********************
LrMatrix & operator = (const LrMatrix &source);
LrMatrix & operator *= (const LrMatrix &source);
// comparison operator(s)
// **********************
friend bool operator == (const LrMatrix &lhs, const LrMatrix &rhs);
friend bool operator != (const LrMatrix &lhs, const LrMatrix &rhs);
// "mathematical" operator(s)
// **************************
friend LrMatrix operator * (const LrMatrix &lhs, const LrMatrix &rhs);
friend LrPoint3d operator * (const LrMatrix &lhs, const LrPoint3d &rhs);
friend LrVector3d operator * (const LrMatrix &lhs, const LrVector3d &rhs);
// inverse matrix
// **************
Real getDeterminant() const;
void inverse();
// matrix generators
// *****************
static LrMatrix scale(Real scaleXYZ);
static LrMatrix scale(Real scaleX, Real scaleY, Real scaleZ);
static LrMatrix translate(const LrVector3d &v);
static LrMatrix rotateX(Real angle);
static LrMatrix rotateX(Real cosinus, Real sinus);
static LrMatrix rotateY(Real angle);
static LrMatrix rotateY(Real cosinus, Real sinus);
static LrMatrix rotateZ(Real angle);
static LrMatrix rotateZ(Real cosinus, Real sinus);
static LrMatrix rotate(const LrPoint3d &center, const LrVector3d &axis,
Real angle);
static LrMatrix rotate(const LrPoint3d &center, const LrVector3d &axis,
Real cosinus, Real sinus);
static LrMatrix frameToFrame(const LrPoint3d &o1, const LrVector3d &u1,
const LrVector3d &v1, const LrVector3d &w1,
const LrPoint3d &o2, const LrVector3d &u2,
const LrVector3d &v2, const LrVector3d &w2);
static LrMatrix projectOnPlane(const LrPoint3d &o,
const LrVector3d &normal);
static LrMatrix projectOnLine(const LrPoint3d &o,
const LrVector3d &direction);
// accessors
// *********
Real getCoeff(int l, int c) const;
void setCoeff(int l, int c, Real coeff);
private:
// data
// ****
Real m11, m12, m13, m14;
Real m21, m22, m23, m24;
Real m31, m32, m33, m34;
void setCoeffs(Real c11, Real c12, Real c13, Real c14,
Real c21, Real c22, Real c23, Real c24,
Real c31, Real c32, Real c33, Real c34);
};
#endif
/*****************************************************************************
* class LrPoint3d (specification) *
* *
* author : Gilles Subrenat *
* creation : Sunday, March 2 2008 (3/2/2008) *
* note : *
*****************************************************************************/
#ifndef LRPOINT3D_H
#define LRPOINT3D_H
class LrVector3d;
class LrPoint3d
{
public:
// constants
// *********
static const LrPoint3d ZERO;
static const LrPoint3d I;
static const LrPoint3d J;
static const LrPoint3d K;
// constructors and destructor
// ***************************
LrPoint3d();
LrPoint3d(const LrPoint3d &source);
LrPoint3d(Real x, Real y, Real z);
virtual ~LrPoint3d();
// assignement operator(s)
// ***********************
LrPoint3d & operator = (const LrPoint3d &source);
// comparison operator(s)
// **********************
friend bool operator == (const LrPoint3d &lhs, const LrPoint3d &rhs);
friend bool operator != (const LrPoint3d &lhs, const LrPoint3d &rhs);
// accessors
// *********
Real getX() const;
void setX(Real x);
Real getY() const;
void setY(Real y);
Real getZ() const;
void setZ(Real z);
void setXYZ(Real x, Real y, Real z);
// miscellaneous functions
// ***********************
static Real distance(const LrPoint3d &p1, const LrPoint3d &p2);
static LrPoint3d middle(const LrPoint3d &p1, const LrPoint3d &p2);
static LrPoint3d interpolate(Real t, const LrPoint3d &p1,
const LrPoint3d &p2);
static LrPoint3d translate( const LrPoint3d &p, const LrVector3d &v);
void translate(const LrVector3d &v);
// data
// ****
// public members EXCEPTIONNALY : to simplify use of this class
Real x, y, z;
private:
// data
// ****
// see public part
};
#endif
/*****************************************************************************
* class LrVector3d (specification) *
* *
* author : Gilles Subrenat *
* creation : Sunday, March 2 2008 (3/2/2008) *
* note : *
*****************************************************************************/
#ifndef LRVECTOR3D_H
#define LRVECTOR3D_H
class LrPoint3d;
class LrVector3d
{
public:
// constants
// *********
static const LrVector3d ZERO;
static const LrVector3d I;
static const LrVector3d J;
static const LrVector3d K;
// constructors and destructor
// ***************************
LrVector3d();
LrVector3d(const LrVector3d &source);
LrVector3d(Real x, Real y, Real z);
LrVector3d(const LrPoint3d &p1, const LrPoint3d &p2);
explicit LrVector3d(const LrPoint3d &p);
virtual ~LrVector3d();
// assignement operator(s)
// ***********************
LrVector3d & operator = (const LrVector3d &source);
LrVector3d & operator += (const LrVector3d &source);
LrVector3d & operator -= (const LrVector3d &source);
LrVector3d & operator *= (Real source);
LrVector3d & operator /= (Real source);
// comparison operator(s)
// **********************
friend bool operator == (const LrVector3d &lhs, const LrVector3d &rhs);
friend bool operator != (const LrVector3d &lhs, const LrVector3d &rhs);
// unary and binary operator(s)
// ****************************
friend LrVector3d operator + (const LrVector3d &rhs);
friend LrVector3d operator - (const LrVector3d &rhs);
friend LrVector3d operator + (const LrVector3d &lhs,
const LrVector3d &rhs);
friend LrVector3d operator - (const LrVector3d &lhs,
const LrVector3d &rhs);
friend Real operator * (const LrVector3d &lhs, const LrVector3d &rhs);
friend LrVector3d operator * (Real lhs, const LrVector3d &rhs);
friend LrVector3d operator * (const LrVector3d &lhs, Real rhs);
friend LrVector3d operator / (const LrVector3d &lhs, Real rhs);
friend LrVector3d operator ^ (const LrVector3d &lhs,
const LrVector3d &rhs);
// accessors
// *********
Real getX() const;
void setX(Real x);
Real getY() const;
void setY(Real y);
Real getZ() const;
void setZ(Real z);
void setXYZ(Real x, Real y, Real z);
// miscellaneous functions
// ***********************
Real length() const;
Real lengthSquare() const;
void normalize();
// data
// ****
// public members EXCEPTIONNALY : to simplify use of this class
Real x, y, z;
private:
// data
// ****
// see public part
};
#endif
###############################################################################
# Makefile #
# #
# author : Gilles Subrenat #
# creation : Sunday, March 2 2008 (3/2/2008) #
# Projet M1-STIC 2007-2008 sur le lancer de rayons #
# Encadrant : Gilles Subrenat #
# Encadrés : Josselin François #
# Michaël Nauge #
# Axel Richard #
# Hervé Souchaud #
# Emeric Verschuur #
###############################################################################
SHELL = /bin/sh
INSTALL = cp
INSTALL_PROGRAM = $(INSTALL)
INSTALL_DATA = $(INSTALL)
#########################################################
# Compiler and options
#########################################################
CC = g++
CPP = g++ -E
INCDIR = -I.
CPPFLAGS = $(INCDIR) -DHAVE_CONFIG_H
CFLAGS = -g -Wall
#CFLAGS = -O -Wall
PERSONNAL_LIB = $(HOME)/local/lib
#LIBS = -ljpeg -lXaw -lm
LIBS =
#LDFLAGS = -L/usr/local/X11R6/lib -L../jpeg $(LIBS)
LDFLAGS = $(LIBS)
#########################################################
# Common prefix for installation directories.
#########################################################
#prefix = /usr/local
prefix = .
exec_prefix = ${prefix}
bindir = ${exec_prefix}/bin
sbindir = ${exec_prefix}/sbin
libexecdir = ${exec_prefix}/libexec
libdir = ${exec_prefix}/lib
infodir = ${prefix}/info
includedir = ${prefix}/include
mandir = ${prefix}/man
srcdir = .
#########################################################
# bin, sources, ...
#########################################################
BIN = scout
SRC = main.cpp \
GiMatrix.cpp
OBJ = $(subst .cpp,.o,$(SRC))
DFILES = $(subst .cpp,.d,$(SRC))
#########################################################
# explicite rules
#########################################################
all: $(BIN)
$(BIN): $(OBJ)
$(CC) $(CFLAGS) -o $@ $(OBJ) $(LDFLAGS)
install:
@echo install to do
uninstall:
@echo uninstall to do
clean:
$(RM) $(OBJ) $(DFILES)
distclean: clean
$(RM) $(BIN)
mostlyclean:
@echo mostlyclean to do
maintainer-clean:
@echo maintainer-clean to do
TAGS:
@echo TAGS to do
info:
@echo info to do
#########################################################
# Implicite rules
#########################################################
.SUFFIXES : .cpp .o .d
%.o : %.cpp
@echo $(CC) -c $<
$(CC) $(CFLAGS) -c $(CPPFLAGS) $< -o $@
%.d : %.cpp
$(SHELL) -ec '$(CC) -MM $(CPPFLAGS) $< \
| sed '\''s/\($*\.o\)[ :]*/\1 $@ : /g'\'' > $@'
# include dependance files
-include $(DFILES)
/*****************************************************************************
* file config (specification) *
* *
* author : Gilles Subrenat *
* creation : Sunday, March 2 2008 (3/2/2008) *
* note : *
*****************************************************************************/
#ifndef CONFIG_H
#define CONFIG_H
/*---------------------------------------------------------------------------*
* Debug mode *
*---------------------------------------------------------------------------*/
// default : have debugging code and assertions
// uncomment next line to suppress debug mode
//#define NDEBUG
/*---------------------------------------------------------------------------*
* Numerical precision *
*---------------------------------------------------------------------------*/
// default : simple précision
// uncomment next line for double precision
//#define REAL_DOUBLE_PRECISION
/*---------------------------------------------------------------------------*
* To avoid this include in each file *
*---------------------------------------------------------------------------*/
#include "global.h"
#endif
#if defined HAVE_CONFIG_H
#include "config.h"
#endif
/*****************************************************************************
* file global (body) *
* *
* author : Gilles Subrenat *
* creation : Sunday, March 2 2008 (3/2/2008) *
* note : *
*****************************************************************************/
#include "global.h"
/*---------------------------------------------------------------------------*
* Some constants *
*---------------------------------------------------------------------------*/
/*****************************************************************************
* file global (specification) *
* *
* author : Gilles Subrenat *
* creation : Sunday, March 2 2008 (3/2/2008) *
* note : *
*****************************************************************************/
#ifndef GLOBAL_H
#define GLOBAL_H
/*---------------------------------------------------------------------------*
* General types *
*---------------------------------------------------------------------------*/
// real type
#if ! defined REAL_DOUBLE_PRECISION
typedef float Real;
#define REAL_FORMAT "%f"
#else
typedef double Real;
#define REAL_FORMAT "%lf"
#endif
/*---------------------------------------------------------------------------*
* Some constants *
*---------------------------------------------------------------------------*/
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment