• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
AbanoubNassem

am trying to load a model but it's not displaying

2 posts in this topic

am trying to load an obj model :

[source lang="plain"]# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware
# File Created: 05.11.2012 20:07:48

mtllib test.mtl

#
# object Box001
#

v -12.6264 0.0000 -58.6877
v -12.6264 0.0000 6.8357
v 43.9557 0.0000 6.8357
v 43.9557 0.0000 -58.6877
v 43.9557 -51.9219 6.8357
v -12.6264 -51.9219 6.8357
v -12.6264 -51.9219 -58.6877
v 43.9557 -51.9219 -58.6877
# 8 vertices

vn 0.0000 1.0000 -0.0000
vn 0.0000 -1.0000 -0.0000
vn 0.0000 0.0000 1.0000
vn 1.0000 0.0000 -0.0000
vn 0.0000 0.0000 -1.0000
vn -1.0000 0.0000 -0.0000
# 6 vertex normals

vt 0.0000 65.5234 0.0000
vt 0.0000 0.0000 0.0000
vt 56.5821 0.0000 0.0000
vt 56.5821 65.5234 0.0000
vt 0.0000 -51.9219 0.0000
vt 56.5821 -51.9219 0.0000
vt 65.5234 0.0000 0.0000
vt 65.5234 -51.9219 0.0000
# 8 texture coords

g Box001
usemtl wire_229154215
s 2
f 1/1/1 2/2/1 3/3/1 4/4/1
s 4
f 5/2/2 6/3/2 7/4/2 8/1/2
s 8
f 3/3/3 2/2/3 6/5/3 5/6/3
s 16
f 4/7/4 3/2/4 5/5/4 8/8/4
s 32
f 1/3/5 4/2/5 8/5/5 7/6/5
s 64
f 2/7/6 1/2/6 7/5/6 6/8/6
# 6 polygons[/source]


I have a class called Model :

[source lang="cpp"]#ifndef _Model_H_
#define _Model_H_

#include <vector>

struct Coordinate{
float X,Y,Z;
Coordinate(float x,float y,float z);
};

struct TextureCoordinate{
float U,V;
TextureCoordinate(float u,float v);
};

struct Face
{
int VertexIndex,TextureIndex,NormalIndex;

Face(int vi, int ti, int ni);

};

class Model
{
public:
Model(void);
~Model(void);
bool IsTriangle;
std::string Name;
std::vector<Coordinate> Vertices;
std::vector<Coordinate> VerticesNormals;
std::vector<Coordinate> VerticesTexture;
std::vector<Face > Faces;
int ModelNumber;
};

#endif[/source]


and am trying to load it like this :-

[source lang="cpp"]Model ModelsLoader::LoadModel(const char * ModelName){
std::ifstream fs(ModelName);
char temp[256];
std::string * line;
Model m;
float tempX,tempY,tempZ;
int tempA1,tempA2,tempA3,tempA4;

if(fs.is_open()){

while (!fs.eof())
{
fs.getline(temp,256);
Lines.push_back(new std::string(temp));
}
int c,slashes;
for (int i = 0; i < Lines.size(); i++)
{
line = Lines[i];

if(line->size() == 0 ||(*line)[0] == '#' ) continue;
else if((*line)[0] == 'v' && (*line)[1] == ' ')
{
sscanf(line->c_str(),"v %f %f %f",&tempX,&tempY,&tempZ);
m.Vertices.push_back( Coordinate(tempX,tempY,tempZ));
}
else if((*line)[0] == 'v' && (*line)[1] == 't'){
sscanf(line->c_str(),"vn %f %f %f",&tempX,&tempY,&tempZ);
m.VerticesTexture.push_back( Coordinate(tempX,tempY,tempZ));
}
else if((*line)[0] == 'v' && (*line)[1] == 'n'){
sscanf(line->c_str(),"vn %f %f %f",&tempX,&tempY,&tempZ);
m.VerticesNormals.push_back( Coordinate(tempX,tempY,tempZ));
}
else if((*line)[0] == 'f' && (*line)[1] == ' ')
{
c = std::count(line->begin(),line->end(),' ') - 1;
slashes = std::count(line->begin(),line->end(),'/');

if( slashes / c == 2){
int i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12;
sscanf(line->c_str(),"f %d/%d/%d %d/%d/%d %d/%d/%d %d/%d/%d",&i1,&i2,&i3,&i4,&i5,&i6,&i7,&i8,&i9,&i10,&i11,&i12);
m.Faces.push_back(Face(i1-1,i2-1,i3-1));
m.Faces.push_back(Face(i4-1,i5-1,i6-1));
m.Faces.push_back(Face(i7-1,i8-1,i9-1));
m.Faces.push_back(Face(i10-1,i11-1,i12-1));
m.IsTriangle = false;
}
else if (slashes / c == 3)
{
int i1,i2,i3,i4,i5,i6,i7,i8,i9;
sscanf(line->c_str(),"f %d/%d/%d %d/%d/%d %d/%d/%d",&i1,&i2,&i3,&i4,&i5,&i6,&i7,&i8,&i9);
m.Faces.push_back(Face(i1-1,i2-1,i3-1));
m.Faces.push_back(Face(i4-1,i5-1,i6-1));
m.Faces.push_back(Face(i7-1,i8-1,i9-1));
m.IsTriangle = true;
}

}
}
fs.close();
m.ModelNumber = glGenLists(1);
glNewList(m.ModelNumber, GL_COMPILE);
for (int i = 0; i < m.Faces.size(); i++)
{
if(m.IsTriangle){
}
else
{
glBegin(GL_QUADS);
for (int i = 0; i < m.Faces.size(); i++)
{
glVertex3f(m.VerticesNormals[m.Faces[i].NormalIndex].X,m.VerticesNormals[m.Faces[i].NormalIndex].Y,m.VerticesNormals[m.Faces[i].NormalIndex].Z);
glVertex3f(m.Vertices[m.Faces[i].VertexIndex].X,m.Vertices[m.Faces[i].VertexIndex].Y,m.Vertices[m.Faces[i].VertexIndex].Z);
}
glEnd();
}
}
glEndList();
}

Clear();
return m;
}[/source]


now when I call the list it's not showing anything:-

[source lang="cpp"]void drawScene() {

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
glLoadIdentity(); //Reset the drawing perspective

camera();

glCallList(model.ModelNumber);

glutSwapBuffers(); //Send the 3D scene to the screen
}[/source]

what am doing worng here!?
0

Share this post


Link to post
Share on other sites
[list=1]
[*]What does camera() do? Are you sure you are setting up ModelView and Projection matrices properly.
[*]Can you check in debugger or using debug printout how many quads it adds to your list?
[*]You are setting vertex coordinates twice instead of vertex+normal, but this should not be your problem.
[/list]
0

Share this post


Link to post
Share on other sites
[quote name='Lauris Kaplinski' timestamp='1352144591' post='4997697'][list=1]
[*]What does camera() do? Are you sure you are setting up ModelView and Projection matrices properly.
[*]Can you check in debugger or using debug printout how many quads it adds to your list?
[*]You are setting vertex coordinates twice instead of vertex+normal, but this should not be your problem.
[/list]
[/quote]
1-
[source lang="cpp"]void camera (void) {
glRotatef(xrot,1.0,0.0,0.0); //rotate our camera on teh x-axis (left and right)
glRotatef(yrot,0.0,1.0,0.0); //rotate our camera on the y-axis (up and down)
glTranslated(-xpos,-ypos,-zpos); //translate the screen to the position of our camera
}[/source]
so I can walk through the whole scene! and yes am setting up ModelView and Projection matrices properly.

2- I can but idk how to do it [img]http://public.gamedev.net//public/style_emoticons/default/huh.png[/img]

3-fixed it Edited by Mr_PoP
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0