Skip to content

Commit 30dea31

Browse files
committedMay 8, 2015
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+

‎specto.project

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<CodeLite_Project Name="specto" InternalType="Console">
3+
<Plugins>
4+
<Plugin Name="qmake">
5+
<![CDATA[00010001N0005Debug000000000000]]>
6+
</Plugin>
7+
<Plugin Name="CMakePlugin">
8+
<![CDATA[[{
9+
"name": "Debug",
10+
"enabled": false,
11+
"buildDirectory": "build",
12+
"sourceDirectory": "$(ProjectPath)",
13+
"generator": "",
14+
"buildType": "",
15+
"arguments": [],
16+
"parentProject": ""
17+
}]]]>
18+
</Plugin>
19+
</Plugins>
20+
<Description/>
21+
<Dependencies/>
22+
<VirtualDirectory Name="src">
23+
<File Name="main.cpp"/>
24+
<File Name="Vertex.h"/>
25+
<File Name="Vertex.cpp"/>
26+
<File Name="Camera.h"/>
27+
<File Name="Camera.cpp"/>
28+
<File Name="World.h"/>
29+
<File Name="World.cpp"/>
30+
</VirtualDirectory>
31+
<Settings Type="Executable">
32+
<GlobalSettings>
33+
<Compiler Options="-std=c++11" C_Options="" Assembler="">
34+
<IncludePath Value="."/>
35+
</Compiler>
36+
<Linker Options="">
37+
<LibraryPath Value="."/>
38+
</Linker>
39+
<ResourceCompiler Options=""/>
40+
</GlobalSettings>
41+
<Configuration Name="Debug" CompilerType="GCC" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
42+
<Compiler Options="-g;-O0;-Wall" C_Options="-g;-O0;-Wall" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
43+
<IncludePath Value="."/>
44+
</Compiler>
45+
<Linker Options="" Required="yes">
46+
<Library Value="expat"/>
47+
</Linker>
48+
<ResourceCompiler Options="" Required="no"/>
49+
<General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Debug" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
50+
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
51+
<![CDATA[]]>
52+
</Environment>
53+
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="yes">
54+
<DebuggerSearchPaths/>
55+
<PostConnectCommands/>
56+
<StartupCommands/>
57+
</Debugger>
58+
<PreBuild/>
59+
<PostBuild/>
60+
<CustomBuild Enabled="no">
61+
<RebuildCommand/>
62+
<CleanCommand/>
63+
<BuildCommand/>
64+
<PreprocessFileCommand/>
65+
<SingleFileCommand/>
66+
<MakefileGenerationCommand/>
67+
<ThirdPartyToolName>None</ThirdPartyToolName>
68+
<WorkingDirectory/>
69+
</CustomBuild>
70+
<AdditionalRules>
71+
<CustomPostBuild/>
72+
<CustomPreBuild/>
73+
</AdditionalRules>
74+
<Completion EnableCpp11="no">
75+
<ClangCmpFlagsC/>
76+
<ClangCmpFlags/>
77+
<ClangPP/>
78+
<SearchPaths/>
79+
</Completion>
80+
</Configuration>
81+
<Configuration Name="Release" CompilerType="GCC" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
82+
<Compiler Options="-O2;-Wall" C_Options="-O2;-Wall" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
83+
<IncludePath Value="."/>
84+
<Preprocessor Value="NDEBUG"/>
85+
</Compiler>
86+
<Linker Options="" Required="yes"/>
87+
<ResourceCompiler Options="" Required="no"/>
88+
<General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Release" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
89+
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
90+
<![CDATA[]]>
91+
</Environment>
92+
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="yes">
93+
<DebuggerSearchPaths/>
94+
<PostConnectCommands/>
95+
<StartupCommands/>
96+
</Debugger>
97+
<PreBuild/>
98+
<PostBuild/>
99+
<CustomBuild Enabled="no">
100+
<RebuildCommand/>
101+
<CleanCommand/>
102+
<BuildCommand/>
103+
<PreprocessFileCommand/>
104+
<SingleFileCommand/>
105+
<MakefileGenerationCommand/>
106+
<ThirdPartyToolName>None</ThirdPartyToolName>
107+
<WorkingDirectory/>
108+
</CustomBuild>
109+
<AdditionalRules>
110+
<CustomPostBuild/>
111+
<CustomPreBuild/>
112+
</AdditionalRules>
113+
<Completion EnableCpp11="no">
114+
<ClangCmpFlagsC/>
115+
<ClangCmpFlags/>
116+
<ClangPP/>
117+
<SearchPaths/>
118+
</Completion>
119+
</Configuration>
120+
</Settings>
121+
</CodeLite_Project>

‎specto.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./Debug/main.cpp.o ./Debug/Vertex.cpp.o ./Debug/Camera.cpp.o ./Debug/World.cpp.o

0 commit comments

Comments
 (0)
Please sign in to comment.