-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplane.cpp
More file actions
96 lines (86 loc) · 3.63 KB
/
plane.cpp
File metadata and controls
96 lines (86 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "plane.h"
#include "scenetexture.h"
plane::plane(QVector3D location, QVector3D scaling, QVector3D rotation,QObject *parent) :
sceneObject(parent)
{
this->texture = NULL;
this->location = location;
this->scaling = scaling;
this->invScaling.setX(1.0/scaling.x());
this->invScaling.setY(1.0/scaling.y());
this->invScaling.setZ(1.0/scaling.z());
this->rotation = rotation;
}
bool plane::isHit(QVector3D ray_loc, QVector3D ray_dir, float &t) {
QVector3D ray_loc_trans = this->vectorToObjectSpace(ray_loc);
QVector3D ray_dir_trans = this->vectorToObjectSpaceRS(ray_dir);
// find out if the line intersects the plane
float NdotD = ray_dir_trans.x();
if (NdotD == 0.0) {
// if true then the ray is parallel to the plane
return false;
}
t = -ray_loc_trans.x()/NdotD;
if (t > 0) {
// check for edges
QVector3D hit = ray_loc_trans + ray_dir_trans * t;
if (hit.y() < 0.0 || hit.y() > 1.0 || hit.z() < 0.0 || hit.z() > 1.0) {
return false;
}
// store location of hit
this->lastHit = ray_loc + ray_dir * t;
// angle of normal to sun for use in texturing
if (ray_dir_trans.x() > 0) {
this->light = QVector3D::dotProduct(this->vectorFromObjectSpaceRS(QVector3D(-1,0,0)).normalized(), QVector3D(0.707,0,0.707) /* the sun */) * 0.5 + 0.5;
} else {
this->light = QVector3D::dotProduct(this->vectorFromObjectSpaceRS(QVector3D(1,0,0)).normalized(), QVector3D(0.707,0,0.707) /* the sun */) * 0.5 + 0.5;
}
return true;
}
// no hit found
return false;
}
void plane::connectObject(spineMLNetworkServer * src, QString port) {
if (port == "Location") {
QObject::connect(src,SIGNAL(dataReceived(QVector<float>)), this, SLOT(setLocation(QVector<float>)));
}
if (port == "LocationX") {
QObject::connect(src,SIGNAL(dataReceived(QVector<float>)), this, SLOT(setLocationX(QVector<float>)));
}
if (port == "LocationY") {
QObject::connect(src,SIGNAL(dataReceived(QVector<float>)), this, SLOT(setLocationY(QVector<float>)));
}
if (port == "LocationZ") {
QObject::connect(src,SIGNAL(dataReceived(QVector<float>)), this, SLOT(setLocationZ(QVector<float>)));
}
if (port == "Rotation") {
QObject::connect(src,SIGNAL(dataReceived(QVector<float>)), this, SLOT(setRotation(QVector<float>)));
}
if (port == "RotationX") {
QObject::connect(src,SIGNAL(dataReceived(QVector<float>)), this, SLOT(setRotationX(QVector<float>)));
}
if (port == "RotationY") {
QObject::connect(src,SIGNAL(dataReceived(QVector<float>)), this, SLOT(setRotationY(QVector<float>)));
}
if (port == "RotationZ") {
QObject::connect(src,SIGNAL(dataReceived(QVector<float>)), this, SLOT(setRotationZ(QVector<float>)));
}
if (port == "Scaling") {
QObject::connect(src,SIGNAL(dataReceived(QVector<float>)), this, SLOT(setScaling(QVector<float>)));
}
if (port == "ScalingX") {
QObject::connect(src,SIGNAL(dataReceived(QVector<float>)), this, SLOT(setScalingX(QVector<float>)));
}
if (port == "ScalingY") {
QObject::connect(src,SIGNAL(dataReceived(QVector<float>)), this, SLOT(setScalingY(QVector<float>)));
}
if (port == "ScalingZ") {
QObject::connect(src,SIGNAL(dataReceived(QVector<float>)), this, SLOT(setScalingZ(QVector<float>)));
}
}
sceneObject * plane::copy() {
// create a new plane and return a pointer
plane * newObj = new plane(this->location, this->scaling, this->rotation);
newObj->setTextureGenerator(this->texture->copy());
return newObj;
}