Skip to content

Commit 30dea31

Browse files
committed
implement base structure
1 parent a541b98 commit 30dea31

12 files changed

+478
-0
lines changed

Camera.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "Camera.h"
2+
#include "Vertex.h"
3+
4+
5+
Camera::Camera(Vertex position, Vertex image, float width, float height, int dpi):
6+
position(position), image(image), width(width), height(height), dpi(dpi){
7+
}

Camera.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef CAMERA_H
2+
#define CAMERA_H
3+
#include <string.h>
4+
#include "Vertex.h"
5+
6+
class Camera {
7+
private:
8+
Vertex position;
9+
Vertex image;
10+
float width;
11+
float height;
12+
int dpi;
13+
public:
14+
Camera(Vertex position, Vertex image, float width, float height, int dpi);
15+
};
16+
17+
#endif // CAMERA_H

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
specto.mk

Vertex.cpp

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include <string>
2+
#include <sstream>
3+
#include <iostream>
4+
#include <iomanip>
5+
#include <stdio.h>
6+
7+
#include "Vertex.h"
8+
9+
Vertex::Vertex(float x, float y, float z): x(x), y(y), z(z){};
10+
Vertex::Vertex(std::string &xyz){
11+
12+
std::istringstream ss(xyz);
13+
std::string token;
14+
15+
float x;
16+
float y;
17+
float z;
18+
19+
std::getline(ss, token, ',');
20+
x = std::stof(token);
21+
std::getline(ss, token, ',');
22+
y = std::stof(token);
23+
std::getline(ss, token, ',');
24+
z = std::stof(token);
25+
std::cout << this;
26+
*this = Vertex(x,y,888.0988);
27+
this->z = 99;
28+
return;
29+
};
30+
31+
void Vertex::SetX(float x) {
32+
this->x = x;
33+
}
34+
void Vertex::SetY(float y) {
35+
this->y = y;
36+
}
37+
void Vertex::SetZ(float z) {
38+
this->z = z;
39+
}
40+
float Vertex::GetX() const {
41+
return x;
42+
}
43+
float Vertex::GetY() const {
44+
return y;
45+
}
46+
float Vertex::GetZ() const {
47+
return z;
48+
}
49+
std::ostream& operator<<(std::ostream& os, const Vertex &obj) {
50+
os << "<Vertex(" << std::fixed << std::setprecision(3) << obj.GetX() << "," << obj.GetY() << "," << obj.GetZ() << ")>";
51+
return os;
52+
}

Vertex.h

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef VERTEX_H
2+
#define VERTEX_H
3+
#include <string>
4+
#include <ostream>
5+
#include "Vertex.h"
6+
7+
class Vertex
8+
{
9+
private:
10+
float x;
11+
float y;
12+
float z;
13+
14+
public:
15+
Vertex(float x, float y, float z);
16+
Vertex(std::string& xyz);
17+
18+
void SetX(float x);
19+
void SetY(float y);
20+
void SetZ(float z);
21+
float GetX() const;
22+
float GetY() const;
23+
float GetZ() const;
24+
};
25+
26+
std::ostream& operator<<(std::ostream& os, const Vertex& obj);
27+
28+
#endif // VERTEX_H

World.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "World.h"
2+
3+
World::World()
4+
{
5+
}

World.h

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef WORLD_H
2+
#define WORLD_H
3+
4+
class World
5+
{
6+
public:
7+
World();
8+
9+
};
10+
11+
#endif // WORLD_H

examples/cube.xml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<specto>
3+
<camera
4+
position="8,0,0"
5+
image="5,0,0"
6+
width="3"
7+
height="4"
8+
dpi="72" />
9+
10+
</specto>
11+

main.cpp

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#include <iostream>
2+
#include <expat.h>
3+
#include <stdio.h>
4+
#include <string.h>
5+
#include "Camera.h"
6+
#include "Vertex.h"
7+
8+
9+
const std::string CAMERA_XML_ELMEMENT = "camera";
10+
11+
12+
void startElement(void* userData, const char* name, const char** atts) {
13+
14+
//Camera camera = new Camera();
15+
16+
if (CAMERA_XML_ELMEMENT.compare(name) == 0){
17+
18+
19+
20+
int i = 0;
21+
while(const char* attr_name = atts[i++]){
22+
std::string attr_value = atts[i++];
23+
std::string comp = attr_name;
24+
25+
if (comp.compare("position") == 0){
26+
std::cout << Vertex(attr_value);
27+
}
28+
}
29+
30+
}
31+
std::cout << "end";
32+
}
33+
34+
35+
void endElement(void* userData, const char* name) {
36+
}
37+
38+
39+
int data_loader(char* data_path) {
40+
FILE* fp;
41+
char* buffer;
42+
long fsize;
43+
XML_Parser parser;
44+
int userData = 0;
45+
int done;
46+
47+
if ((fp = fopen(data_path, "r")) == NULL) {
48+
std::cerr << "Can't open \"" << data_path << "\"\n";
49+
exit(1);
50+
}
51+
52+
fseek(fp, 0, SEEK_END);
53+
fsize = ftell(fp);
54+
rewind(fp);
55+
56+
buffer = (char*)malloc(fsize + 1);
57+
58+
if(buffer == NULL)
59+
exit(2);
60+
61+
fread(buffer, 1, fsize, fp);
62+
63+
buffer[fsize] = '\0';
64+
65+
printf("%s\n", buffer);
66+
fclose(fp);
67+
68+
parser = XML_ParserCreate((XML_Char*)"UTF-8");
69+
XML_SetUserData(parser, &userData);
70+
XML_SetElementHandler(parser, startElement, endElement);
71+
72+
if(!XML_Parse(parser, buffer, fsize, 0)) {
73+
fprintf(stderr,
74+
"%s at line %d\n",
75+
XML_ErrorString(XML_GetErrorCode(parser)),
76+
XML_GetCurrentLineNumber(parser));
77+
return 1;
78+
}
79+
80+
81+
XML_ParserFree(parser);
82+
83+
return 0;
84+
}
85+
86+
87+
int main(int argc, char** argv) {
88+
if(argc != 2) {
89+
std::cerr << "Usage: specto [file]\n";
90+
return 1;
91+
}
92+
93+
return data_loader(*++argv);
94+
}

specto.mk

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
##
2+
## Auto Generated makefile by CodeLite IDE
3+
## any manual changes will be erased
4+
##
5+
## Debug
6+
ProjectName :=specto
7+
ConfigurationName :=Debug
8+
WorkspacePath := "/home/sriolo/.codelite/riols"
9+
ProjectPath := "/home/sriolo/development/cpp/specto"
10+
IntermediateDirectory :=./Debug
11+
OutDir := $(IntermediateDirectory)
12+
CurrentFileName :=
13+
CurrentFilePath :=
14+
CurrentFileFullPath :=
15+
User :=Samuel Riolo
16+
Date :=05/08/15
17+
CodeLitePath :="/home/sriolo/.codelite"
18+
LinkerName :=/usr/bin/g++
19+
SharedObjectLinkerName :=/usr/bin/g++ -shared -fPIC
20+
ObjectSuffix :=.o
21+
DependSuffix :=.o.d
22+
PreprocessSuffix :=.i
23+
DebugSwitch :=-g
24+
IncludeSwitch :=-I
25+
LibrarySwitch :=-l
26+
OutputSwitch :=-o
27+
LibraryPathSwitch :=-L
28+
PreprocessorSwitch :=-D
29+
SourceSwitch :=-c
30+
OutputFile :=$(IntermediateDirectory)/$(ProjectName)
31+
Preprocessors :=
32+
ObjectSwitch :=-o
33+
ArchiveOutputSwitch :=
34+
PreprocessOnlySwitch :=-E
35+
ObjectsFileList :="specto.txt"
36+
PCHCompileFlags :=
37+
MakeDirCommand :=mkdir -p
38+
LinkOptions :=
39+
IncludePath := $(IncludeSwitch). $(IncludeSwitch).
40+
IncludePCH :=
41+
RcIncludePath :=
42+
Libs := $(LibrarySwitch)expat
43+
ArLibs := "expat"
44+
LibPath := $(LibraryPathSwitch).
45+
46+
##
47+
## Common variables
48+
## AR, CXX, CC, AS, CXXFLAGS and CFLAGS can be overriden using an environment variables
49+
##
50+
AR := /usr/bin/ar rcu
51+
CXX := /usr/bin/g++
52+
CC := /usr/bin/gcc
53+
CXXFLAGS := -std=c++11 -g -O0 -Wall $(Preprocessors)
54+
CFLAGS := -g -O0 -Wall $(Preprocessors)
55+
ASFLAGS :=
56+
AS := /usr/bin/as
57+
58+
59+
##
60+
## User defined environment variables
61+
##
62+
CodeLiteDir:=/usr/share/codelite
63+
Objects0=$(IntermediateDirectory)/main.cpp$(ObjectSuffix) $(IntermediateDirectory)/Vertex.cpp$(ObjectSuffix) $(IntermediateDirectory)/Camera.cpp$(ObjectSuffix) $(IntermediateDirectory)/World.cpp$(ObjectSuffix)
64+
65+
66+
67+
Objects=$(Objects0)
68+
69+
##
70+
## Main Build Targets
71+
##
72+
.PHONY: all clean PreBuild PrePreBuild PostBuild
73+
all: $(OutputFile)
74+
75+
$(OutputFile): $(IntermediateDirectory)/.d $(Objects)
76+
@$(MakeDirCommand) $(@D)
77+
@echo "" > $(IntermediateDirectory)/.d
78+
@echo $(Objects0) > $(ObjectsFileList)
79+
$(LinkerName) $(OutputSwitch)$(OutputFile) @$(ObjectsFileList) $(LibPath) $(Libs) $(LinkOptions)
80+
81+
$(IntermediateDirectory)/.d:
82+
@test -d ./Debug || $(MakeDirCommand) ./Debug
83+
84+
PreBuild:
85+
86+
87+
##
88+
## Objects
89+
##
90+
$(IntermediateDirectory)/main.cpp$(ObjectSuffix): main.cpp $(IntermediateDirectory)/main.cpp$(DependSuffix)
91+
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/sriolo/development/cpp/specto/main.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/main.cpp$(ObjectSuffix) $(IncludePath)
92+
$(IntermediateDirectory)/main.cpp$(DependSuffix): main.cpp
93+
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/main.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/main.cpp$(DependSuffix) -MM "main.cpp"
94+
95+
$(IntermediateDirectory)/main.cpp$(PreprocessSuffix): main.cpp
96+
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/main.cpp$(PreprocessSuffix) "main.cpp"
97+
98+
$(IntermediateDirectory)/Vertex.cpp$(ObjectSuffix): Vertex.cpp $(IntermediateDirectory)/Vertex.cpp$(DependSuffix)
99+
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/sriolo/development/cpp/specto/Vertex.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Vertex.cpp$(ObjectSuffix) $(IncludePath)
100+
$(IntermediateDirectory)/Vertex.cpp$(DependSuffix): Vertex.cpp
101+
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/Vertex.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/Vertex.cpp$(DependSuffix) -MM "Vertex.cpp"
102+
103+
$(IntermediateDirectory)/Vertex.cpp$(PreprocessSuffix): Vertex.cpp
104+
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/Vertex.cpp$(PreprocessSuffix) "Vertex.cpp"
105+
106+
$(IntermediateDirectory)/Camera.cpp$(ObjectSuffix): Camera.cpp $(IntermediateDirectory)/Camera.cpp$(DependSuffix)
107+
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/sriolo/development/cpp/specto/Camera.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Camera.cpp$(ObjectSuffix) $(IncludePath)
108+
$(IntermediateDirectory)/Camera.cpp$(DependSuffix): Camera.cpp
109+
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/Camera.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/Camera.cpp$(DependSuffix) -MM "Camera.cpp"
110+
111+
$(IntermediateDirectory)/Camera.cpp$(PreprocessSuffix): Camera.cpp
112+
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/Camera.cpp$(PreprocessSuffix) "Camera.cpp"
113+
114+
$(IntermediateDirectory)/World.cpp$(ObjectSuffix): World.cpp $(IntermediateDirectory)/World.cpp$(DependSuffix)
115+
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/sriolo/development/cpp/specto/World.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/World.cpp$(ObjectSuffix) $(IncludePath)
116+
$(IntermediateDirectory)/World.cpp$(DependSuffix): World.cpp
117+
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/World.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/World.cpp$(DependSuffix) -MM "World.cpp"
118+
119+
$(IntermediateDirectory)/World.cpp$(PreprocessSuffix): World.cpp
120+
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/World.cpp$(PreprocessSuffix) "World.cpp"
121+
122+
123+
-include $(IntermediateDirectory)/*$(DependSuffix)
124+
##
125+
## Clean
126+
##
127+
clean:
128+
$(RM) -r ./Debug/
129+
130+

0 commit comments

Comments
 (0)