Add a new OpenGL pyramid sample
This sample shows the use of modern OpenGL (3.2). Closes #16910.
This commit is contained in:
committed by
Vadim Zeitlin
parent
bdc95f5766
commit
d6fb44e158
83
samples/opengl/pyramid/mathstuff.h
Normal file
83
samples/opengl/pyramid/mathstuff.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: mathstuff.h
|
||||
// Purpose: Some maths used for pyramid sample
|
||||
// Author: Manuel Martin
|
||||
// Created: 2015/01/31
|
||||
// Copyright: (c) 2015 Manuel Martin
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef MATHSTUFF_H
|
||||
#define MATHSTUFF_H
|
||||
|
||||
//NOTE:
|
||||
// glm library is great for handling matrices and vectors in a OpenGL style, see
|
||||
// http://glm.g-truc.net/
|
||||
// But it's too large for this simple sample. I coded on my own the maths needed.
|
||||
|
||||
// A vector with 3 components
|
||||
class myVec3
|
||||
{
|
||||
public:
|
||||
myVec3() { x = y = z = 0.0 ;}
|
||||
myVec3(double xd, double yd, double zd) : x(xd), y(yd), z(zd) {}
|
||||
~myVec3() {}
|
||||
|
||||
double x, y, z;
|
||||
};
|
||||
|
||||
// A vector with 4 components
|
||||
class myVec4
|
||||
{
|
||||
public:
|
||||
myVec4() { x = y = z = w = 0.0 ;}
|
||||
myVec4(double xd, double yd, double zd, double wd)
|
||||
: x(xd), y(yd), z(zd), w(wd) {}
|
||||
myVec4(const myVec3& v3, double wd = 0.0)
|
||||
: x(v3.x), y(v3.y), z(v3.z), w(wd) {}
|
||||
~myVec4() {}
|
||||
|
||||
double x, y, z, w;
|
||||
};
|
||||
|
||||
// Overload of "-" operator
|
||||
myVec3 operator- (const myVec3& v1, const myVec3& v2);
|
||||
|
||||
// Vector normalization
|
||||
myVec3 MyNormalize(const myVec3& v);
|
||||
|
||||
// Dot product
|
||||
double MyDot(const myVec3& v1, const myVec3& v2);
|
||||
|
||||
// Cross product
|
||||
myVec3 MyCross(const myVec3& v1, const myVec3& v2);
|
||||
|
||||
// Distance between two points
|
||||
double MyDistance(const myVec3& v1, const myVec3& v2);
|
||||
|
||||
// Angle between two normalized vectors, in radians
|
||||
double AngleBetween(myVec3 v1, myVec3 v2);
|
||||
|
||||
// Matrix 4x4 by 4x1 multiplication
|
||||
myVec4 MyMatMul4x1(const float *m1, const myVec4& v);
|
||||
|
||||
// Matrix 4x4 by 4x4 multiplication
|
||||
void MyMatMul4x4(const float *m1, const float *m2, float* mm);
|
||||
|
||||
// Matrix inverse. Returns the determinant
|
||||
double MyMatInverse(const float *m, float *minv);
|
||||
|
||||
// Matrix of rotation around an axis in the origin
|
||||
void MyRotate(const myVec3& axis, double angle, float *mrot);
|
||||
|
||||
// Matrix for defining the viewing transformation
|
||||
void MyLookAt(const myVec3& camPos, const myVec3& camUp, const myVec3& targ, float *mt);
|
||||
|
||||
// Matrix for defining the perspective projection with symmetric frustum
|
||||
void MyPerspective(double fov, double aspect, double zNear, double zFar, float *mp);
|
||||
|
||||
// Matrix for defining the orthogonal projection
|
||||
void MyOrtho(double left, double right, double bottom, double top,
|
||||
double zNear, double zFar, float *mo);
|
||||
|
||||
#endif // MATHSTUFF_H
|
Reference in New Issue
Block a user