first commit
This commit is contained in:
132
CS4451/proj4/structs.h
Normal file
132
CS4451/proj4/structs.h
Normal file
@@ -0,0 +1,132 @@
|
||||
#ifndef _STRUCTS_H_
|
||||
#define _STRUCTS_H_
|
||||
|
||||
#include "defs.h"
|
||||
#include <iostream>
|
||||
|
||||
#include <GL/glut.h>
|
||||
#include <math.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef struct MaterialAttributes {
|
||||
m_float k_dr, k_dg, k_db; //diffuse properties, rgb
|
||||
m_float k_ar, k_ag, k_ab; //ambient properties, rgb
|
||||
m_float k_s; //specular properties, rgb same
|
||||
m_float n_spec; //specular exponent
|
||||
|
||||
MaterialAttributes() {
|
||||
k_dr = k_dg = k_db = k_ar = k_ag = k_ab = k_s = n_spec = 0;
|
||||
}
|
||||
|
||||
void printMe() {
|
||||
cout << " MaterialAttributes:\n";
|
||||
cout << " k_dr: " << k_dr << " k_dg: " << k_dg << " k_db: " << k_db << endl;
|
||||
cout << " k_ar: " << k_ar << " k_ag: " << k_ag << " k_ab: " << k_ab << endl;
|
||||
cout << " k_s: " << k_s << " n_spec: " << n_spec << endl;
|
||||
}
|
||||
} MaterialAttributes;
|
||||
|
||||
typedef struct Point {
|
||||
m_float x,y,z;
|
||||
void printMe() {
|
||||
cout << " x: " << x << " y: " << y << " z: " << z << endl;
|
||||
}
|
||||
Point() {
|
||||
x = y = z =0;
|
||||
}
|
||||
inline static void add(Point& dest, Point src1, Point src2) {
|
||||
dest.x = src1.x + src2.x;
|
||||
dest.y = src1.y + src2.y;
|
||||
dest.z = src1.z + src2.z;
|
||||
}
|
||||
|
||||
inline static void sub(Point& dest, Point src1, Point src2) {
|
||||
dest.x = src1.x - src2.x;
|
||||
dest.y = src1.y - src2.y;
|
||||
dest.z = src1.z - src2.z;
|
||||
}
|
||||
|
||||
inline static void div(Point& dest, Point src1, Point src2) {
|
||||
dest.x = src1.x / src2.x;
|
||||
dest.y = src1.y / src2.y;
|
||||
dest.z = src1.z / src2.z;
|
||||
}
|
||||
|
||||
inline static void mul(Point& dest, Point src1, Point src2) {
|
||||
dest.x = src1.x * src2.x;
|
||||
dest.y = src1.y * src2.y;
|
||||
dest.z = src1.z * src2.z;
|
||||
}
|
||||
|
||||
inline static void mul(Point& dest, Point src, m_float src2) {
|
||||
dest.x = src.x*src2;
|
||||
dest.y = src.y*src2;
|
||||
dest.z = src.z*src2;
|
||||
}
|
||||
|
||||
inline static void exp(Point& dest, Point src, m_float exp) {
|
||||
dest.x = pow(src.x, exp);
|
||||
dest.y = pow(src.y, exp);
|
||||
dest.z = pow(src.z, exp);
|
||||
}
|
||||
|
||||
inline m_float magnitude() {
|
||||
return sqrt(pow(this->x,2) + pow(this->y,2) + pow(this->z,2));
|
||||
}
|
||||
|
||||
inline static Point normalize(Point src) {
|
||||
Point p = src;
|
||||
p.x /= src.magnitude();
|
||||
p.y /= src.magnitude();
|
||||
p.z /= src.magnitude();
|
||||
return p;
|
||||
}
|
||||
|
||||
inline static void dot(Point& dest, Point src1, Point src2) {
|
||||
dest.x = src1.x * src2.x;
|
||||
dest.y = src1.y * src2.y;
|
||||
dest.z = src1.z * src2.z;
|
||||
}
|
||||
|
||||
inline static void cross(Point &dest, Point &a, Point &b) {
|
||||
dest.x = ( (a.y*b.z) - (a.z*b.y) ); //i
|
||||
dest.y = ( (a.z*b.x) - (a.x*b.z) ); //j
|
||||
dest.z = ( (a.x*b.y) - (a.y*b.x) ); //k
|
||||
}
|
||||
|
||||
} Point;
|
||||
|
||||
typedef struct Sphere {
|
||||
MaterialAttributes m_attr;
|
||||
Point center;
|
||||
GLUquadricObj* glSphere;
|
||||
m_float radius;
|
||||
|
||||
Sphere() {
|
||||
glSphere = NULL;
|
||||
}
|
||||
|
||||
void printMe() {
|
||||
cout << "Sphere: " << endl;
|
||||
cout << " Center ";
|
||||
center.printMe();
|
||||
cout << " Radius: " << radius << endl;
|
||||
m_attr.printMe();
|
||||
|
||||
}
|
||||
} Sphere;
|
||||
|
||||
typedef struct Triangle {
|
||||
MaterialAttributes m_attr;
|
||||
Point a1, a2, a3;
|
||||
} Triangle;
|
||||
|
||||
typedef struct Light {
|
||||
Point center;
|
||||
m_float intensity;
|
||||
} Light;
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user