-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
116 lines (103 loc) · 3.77 KB
/
Copy pathmain.cpp
File metadata and controls
116 lines (103 loc) · 3.77 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "graphics.hpp"
int main()
{
sf::Vector3f lightPoint(506,435,1440);
sf::Vector3f lightColor(185,190,120);
gp::mainWindow window(1024,768);
window.clearWindow();
window.setVerticalSyncEnabled(false);
sf::Vector3f viewPortPoint(0,0,10);
window.setViewPoint(viewPortPoint);
window.setLookAtPoint(sf::Vector3f(0,0,0));
window.setProjection(sf::Vector3f(512,384,2000),500);
window.setViewVolume(sf::Vector3f(0,0,400),sf::Vector3f(1024,768,-400));
window.calcTransformation();
window.setAmbientLight(sf::Vector3f(255,255,255));
window.addLightSource(lightPoint,lightColor);
vector <gp::object3d> objects = gp::parseObj("Objects.obj");
for (unsigned i = 0; i<objects.size(); i++)
{
float x=0,y=0,z=0;
if (objects[i].name == "Chair")
{
x = 542.7, y = 330, z = 1400;
}
else if (objects[i].name == "Room")
{
x = 330, y = 280, z = 1600;
}
else if (objects[i].name == "Lamp")
{
x = 330, y = 280, z = 1700;
}
else if (objects[i].name == "Table")
{
x = 500, y = 350, z = 1260;
}
else if (objects[i].name == "Vase")
{
x = 500, y = 363, z = 1260;
}
else if (objects[i].name == "Door")
{
x = 657, y = 285, z = 1420;
}
else if (objects[i].name == "WindowFrame")
{
x = 356, y = 390, z = 1337;
}
else if (objects[i].name == "WindowSlab")
{
x = 346, y = 338, z = 1337;
}
objects[i].setPosition(sf::Vector3f(x,y,z));
objects[i].setScale(sf::Vector3f(100,100,100));
}
for (unsigned i = 0; i<objects.size(); i++)
{
objects[i].setWindow(&window);
objects[i].mapTriangleStrip();
objects[i].calculateintensity();
}
while(window.isOpen())
{
sf::Event event;
while(window.pollEvent(event))
{
if(event.type == sf::Event::KeyPressed)
{
if(event.key.code == sf::Keyboard::P)
window.saveScreenshot();
if(event.key.code == sf::Keyboard::Escape)
window.close();
if(event.key.code == sf::Keyboard::W)
viewPortPoint.z+=0.10;
if(event.key.code == sf::Keyboard::S)
viewPortPoint.z-=0.10;
if(event.key.code == sf::Keyboard::Up)
viewPortPoint.y+=0.10;
if(event.key.code == sf::Keyboard::Down)
viewPortPoint.y-=0.10;
if(event.key.code == sf::Keyboard::Left)
viewPortPoint.x+=0.10;
if(event.key.code == sf::Keyboard::Right)
viewPortPoint.x-=0.10;
window.setViewPoint(viewPortPoint);
window.calcTransformation();
}
}
window.clearWindow();
window.plotPoint(window.transformPoint(lightPoint - sf::Vector3f(1,0,0)),sf::Vector3f(255,0,0));
window.plotPoint(window.transformPoint(lightPoint + sf::Vector3f(1,0,0)),sf::Vector3f(0,0,255));
window.plotPoint(window.transformPoint(lightPoint - sf::Vector3f(0,1,0)),sf::Vector3f(0,255,0));
window.plotPoint(window.transformPoint(lightPoint + sf::Vector3f(0,1,0)),sf::Vector3f(255,255,255));
window.plotPoint(window.transformPoint(lightPoint),sf::Vector3f(0,0,0));
for (unsigned i=0; i<objects.size(); i++)
{
// if (objects[i].name == "Room")
objects[i].draw();
}
window.updateWindow();
}
return 0;
}