-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhud.h
129 lines (113 loc) · 3.52 KB
/
hud.h
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
117
118
119
120
121
122
123
124
125
126
127
128
129
#ifndef _HUD_ELEMENT_
#define _HUD_ELEMENT_
#include <osg/Vec3>
#include <osg/Matrix>
#include <osg/Geode>
#include <osg/PositionAttitudeTransform>
#include <osg/MatrixTransform>
#include <osg/Geometry>
#include <osg/Texture2D>
#include <osgDB/ReadFile>
#include <osg/Projection>
#include <osgText/Text>
#include <string>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <iostream>
enum OPTIONS{OPTION_A=1,OPTION_B=2, OPTION_C=3, OPTION_D=4};
osg::Projection* displayQuestion();
class HUDElement
{
public:
HUDElement(osg::Group* root, int width=1600, int height=1200);
void DefineHUDQuad(osg::Vec3 ll_corner, osg::Vec3 ul_corner, osg::Vec3 ur_corner, osg::Vec3 lr_corner, int posx, int posy, const std::string texture_filename, int draw_order=11);
void DefineHUDQuad(float width, float height, int posx, int posy, const std::string texture_filename, int draw_order=11);
void Rotate(float degrees);
void DisplayScore();
void IncreementScore(){
score += 10;
DisplayScore();
}
void DecreementScore(){
if(score > 0) score -= 10;
DisplayScore();
}
void DisplayInitScreen();
void RemoveInitScreen();
private:
osg::ref_ptr<osg::Geode> mHUDGeode;
osg::ref_ptr<osg::Projection> mHUDProjectionMatrix;
osg::ref_ptr<osg::MatrixTransform> mHUDModelViewMatrix;
osg::ref_ptr<osg::Geometry> mHUDBackgroundGeometry;
osg::ref_ptr<osg::Vec3Array> mHUDBackgroundVertices;
osg::ref_ptr<osg::DrawElementsUInt> mHUDBackgroundIndices;
osg::ref_ptr<osg::Vec4Array> mHUDcolors;
osg::ref_ptr<osg::Vec2Array> mTexcoords;
osg::ref_ptr<osg::Texture2D> mHUDTexture;
osg::ref_ptr<osg::Image> mHudImage;
osg::Matrix mMtx;
osgText::Text* textOne;
osg::Switch *swt;
osg::Geode *HUDGeode;
int score;
int mPosX;
int mPosY;
};
class Question{
public:
std::string qText;
std::string option1;
std::string option2;
std::string option3;
std::string option4;
OPTIONS correctAnswer;
Question(std::string question, std::string ans1, std::string ans2, std::string ans3, std::string ans4, OPTIONS sol)
{
qText = question;
option1 = ans1;
option2 = ans2;
option3 = ans3;
option4 = ans4;
correctAnswer = sol;
}
Question(){} // Empty constructor needed as well
};
class QuestionBank{
public:
std::vector<Question> bank;
int numQuestions;
void readQuestions(std::string qFileName)
{
std::ifstream qFile;
int ctr=0;
qFile.open(qFileName.c_str());
if (!qFile.good())
{
std::cout << "Couldn't read the questions file. Exiting" << std::endl;
exit(0);
}
for (ctr=0;ctr<numQuestions;ctr++)
{
Question tempQ;
int temp;
getline(qFile,tempQ.qText);
getline(qFile,tempQ.option1);
getline(qFile,tempQ.option2);
getline(qFile,tempQ.option3);
getline(qFile,tempQ.option4);
qFile >> temp;
tempQ.correctAnswer = (OPTIONS)temp;
bank.push_back(tempQ);
}
// To verify, temporarily:
for (ctr=0;ctr<numQuestions;ctr++)
{
std::cout << bank[ctr].qText << std::endl;
std::cout << bank[ctr].option1 << std::endl;
}
qFile.close();
return;
}
};
#endif