camera_t
object is used to look at a simple plane,
now replace the simple plane (list of point_t
pointers)
by an Alias|Wavefront object, e.g., a simple cube.
aw_t
object that will be used to store the
so-called B-REP (boundary representation) of a (hollow) 3D object.
The aw_t
object contains the following data objects:
std::vector<vertex_t *> verts
a list of (pointers to) vertices,
std::vector<face_t *> faces
a list of (pointers to) faces, and
std::string group
an unused string to store the group
designation
aw.h
and implementation
aw.cpp
files.
vertex_t
object that will be used to store the
3D coordinates of a vertex. This object is very similar to the
point_t
object used previously.
The vertex_t
object contains the following data objects:
std::vector<float> coord
a list of coordinates
vertex.h
and implementation
vertex.cpp
files.
face_t
object that will be used to store the
integer vertex indeces that index into the object's vertex list,
basically a list of integers.
The face_t
object contains the following data objects:
std::vector<int> vin
a list of integers
face.h
and implementation
face.cpp
files.
std::vector
, are indexed 0..n-1.
point_t
object and follow that pattern.
This time, when looping through the input, you will have to
decide what is being read in: a vertex_t
object,
a face_t
object, or the std::string
object. Each of these is identified by the leading character,
i.e., v
, g
, or f
,
respectively. Therefore, your parsing loop should read in a
single character and then switch
on that character
to decide what to read in, e.g., with
std::istream& s
,
while( s.get(c) && !s.eof() ) {
switch(c) {
case 'v':
// read in vertex_t object
break;
case 'g':
// read in group string
break;
case 'f':
// read in face_t object
break;
}
For convenience, you should have each object read itself
so that you are calling each object's operator>>
.
glBegin(GL_QUADS);
. The tricky part is
getting at the three x-, y-, and z-coordinates
of each vertex for the call to glVertex3f
.
To do the above, you will need to
glVertex3f
.
(*the_points[i])[0]
syntax).
new
vertex_t*
each
time a new vertex is read in (this gets added to the object's
vertex list).
new
face_t*
each
time a new face is read in (this gets added to the object's
face list).
delete
ing each point pointer as you erase each one
from the list (i.e., when the program exits).
cube-ccw.obj
file used to test the above program is:
v 1.0 1.0 1.0
v 1.0 1.0 -1.0
v 1.0 -1.0 1.0
v 1.0 -1.0 -1.0
v -1.0 1.0 1.0
v -1.0 1.0 -1.0
v -1.0 -1.0 1.0
v -1.0 -1.0 -1.0
g cube
f 1 5 7 3
f 2 1 3 4
f 5 6 8 7
f 6 2 4 8
f 2 6 5 1
f 8 4 3 7
std::vector
containers, which keep track
of the size of the list.
GL: 2.1 NVIDIA-10.2.1 310.41.15f01 NVIDIA Corporation
number of verts read in: 8
number of faces read in: 5
*** printing object list
v 1.0 1.0 1.0
v 1.0 1.0 -1.0
v 1.0 -1.0 1.0
v 1.0 -1.0 -1.0
v -1.0 1.0 1.0
v -1.0 1.0 -1.0
v -1.0 -1.0 1.0
v -1.0 -1.0 -1.0
g cube
f 1 5 7 3
f 2 1 3 4
f 5 6 8 7
f 6 2 4 8
f 2 6 5 1
it is a good idea to print out the object parsed in, to make
sure you can read the object data and then reproduce it by
iterating through the vertex and face lists.
Makefile
that you can use to compile the project:
.SUFFIXES: .c .o .cpp .cc .cxx .C
UNAME = $(shell uname)
PLATFORM = $(shell uname -p)
CC = g++
COPTS = -g -Wall
INCDIR =
LIBDIR =
ifeq ("$(shell uname)", "Linux")
INC = \
-I/usr/lib/glut-3.7/include
LIBDIR = \
-L/usr/lib -L/usr/X11R6/lib -L/usr/lib/glut-3.7/lib/glut
LIBS = \
-lglut -lGLU -lGL -lXmu -lXi -lXext -lX11 -lm
else
ifeq ("$(shell uname)", "Darwin")
LIBS = \
-framework OpenGL -framework GLUT -framework Foundation -lstdc++
endif
endif
.c.o:
$(CC) -c $(INCDIR) $(COPTS) -o $@ $<
.cpp.o:
$(CC) -c $(INCDIR) $(COPTS) -o $@ $<
all : main
OBJECTS = \
point.o \
face.o \
vertex.o \
aw.o \
camera.o
main : $(OBJECTS) main.o
$(CC) -o $@ $(INCDIR) $(COPTS) $(OBJECTS) $@.o $(LIBDIR) $(LIBS)
point.o: point.h point.cpp
clean :
rm -f *.o
rm -rf main
tar.gz
archive of your asg##/ directory, including:
README
file containing
Makefile
.h
headers and .cpp
source)
make clean
before tar
)
handin
notes