programming help?


#1

I was wondering if there are any good programmers out there that could help me out with something…

I’m trying to learn win32 programming using c++ and I would like to learn more about how 3d apps work. So for now I just need a very simple example program. What I would like is just a basic program that when run, displays a cube and you can move the view to rotate around it with the mouse. It would need a coordinate system to properly place the cube’s veritces. (thats another thing I don’t know how to represent. would you use a 3 dimensional array?)

Would this be simple to make? If anyone thinks it would be easy, I would love it if you could knock something together. But if its a big project don’t spend a bunch of time on it or anything, I just need a starting point, and source code to look at.

I’ve checked out source code for stuff like blender but when looking through the code, I just haven’t been able to find the part in it that does this.


#2

Download FLTK. There is a simple example and tutorial in there that does just what you want.Better yet, FLTK is multi-platform so you won’t be locked into just windows. FLTK is a windows wrapper that hides the complexity of showing windows/requesters/etc. across platforms.

In order to do what you want, however, you will also need to familiarize yourself with OpenGL (or DirectX, albeit directx is just windows).


#3

don’t get me wrong, but if you think that to store the vertices positions you need a 3dimensional arrays then you need to take one step back into the learning process and get to writing “hello world” string array manipulation programs that run in a shell (to store vertices, that are nothing but displacment vectors starting off the object’s local origin, you need 3by1 matrices, aka a 2D array with indices in a column and coords in the respective row or viceversa)

the above is absolutely not meant to be sarcastic or to diminish you, we all had to start somewhere, but before you worry about 3D manipulation you need to learn at least the basics of programming (a language, paradigms, common necessities and the very basics of project planning, including learning what’s meant with API, libraries etc.) and at least some very basic linear algebra.

to make my point more clear, did you think how you would want to display this cube? using an existing platform like OGL or DX? write the whole thing from scratch (including all the sorting and space conversions routines)? Being able to ask yourself (and others) these questions is more then fundamental to even only begin thinking of very basic programming.


#4

gga - thanks for the info

the_jaco - I was thinking about doing it with openGL. I think what I meant to ask is if you could use a 3 dimensional array to represend the centers, or pivot points of an object. This would then be the local origin for the object to indicate the vertex positions. But that could be wrong too. Anyway thanks for the detailed response. Thats why I posted here, I don’t know much about how it works, and I was just looking for a place to start.

but come on, who doesn’t know what an API or library is?? =)


#5

If you want the basics, check out the tutorials available at http://nehe.gamedev.net. They have everything you want, from the first triangle to full 3D worlds. A lot of aspiring 3D programmers start their path from there, I believe.


#6

Use GLUT or FreeGLUT. They really condense the API down and it’s cross platform capable. These libraries will let you focus on your OpenGL code and not worry about the underlying process of creating a window, creating an OGL context and attaching it to the window. GLUT takes care of all of that with as few function calls as possible for you.

Not to be an ass, but yeah, it’s wrong. I’ll give you the benefit of the doubt in that you didn’t mean to say 3 dimensional array. I’m sure you thinking of the right thing just worded it differently. What you want is an array of 3 elements. 3 floats to be exact. Each float would be a coordinate, like X, Y, or Z. If you really want to get crafty you could just use a flat memory buffer rather than an array. A flat memory buffer would just be a series of bytes, big enough to hold the number of floats you need. Then with a pointer to that buffer you could move the buffer forward and back within the bounds of that buffer to extract the desired float data. This is actually a lot faster in execution than using arrays.


#7

I’m glad you took my comments at face value and not as an offense. I don’t know what your coding skills level is like, but at the very least you are starting with the right foot as far as attitude goes :wink:

as for arrays:
think of a 2D array as of a spreadshit with row and colums, basically a grid
a 3D array would be more alike to a 2D array with a stack of metadata raising from each grid square.

if you picture the thing graphically you can see how a bunch of vectors really only requires a 2D one, while a push in the 3rd dimension would only come in handy if you wanted additional data for each vector (if it was just additional data bound to the index of the vertex then all you’d want would be a larger array).

as for starting out with writing a viewer you are better off starting studying openGL, plentiful good advice has already been given in the regards.

99% of the OGL tutorials and courses around start from building and shading vertices and then manipulating the object and/or moving the camera, this will naturally progress into what you are after.

be warned though,you are in for a bumpy ride unless you already posses some basic C++ skills.


#8

Follow gga’s advice, download FLTK. There’s an example program with a simple box and a bunch of view controls, its done in FLTK + OpenGL. It will also teach you a bit about how to implement controls to affect your OpenGL view, the code is very clear and easy to read even for a beginner.

Try it, then you can go further and dive into the details!

-mk-


#9

the_jaco - my c++ skills are still what I consider to be at novice level. I have knowledge of IO, String manipulation, a few sorting algorithms (yea the old deck shuffling classic too), pointers, recursion, basic stuff. I am entirely self taught with c++, using a really good book, (and a lot of transferable, language independent OOP design skills from a java class I took). And for those who are just tuning into this thread, I have zero graphics knowledge, aside from draing a bitmap image onto a blank window, but that doesn’t count.

I do understand 2 and 3 dimensional arrays though (earlier today I made a tic-tac-toe game using a 3x3 2d array). I just made a bad stab at guessing you could use them for a coordinate system.

Learning some OpenGL is pretty high up there on my to-do. I don’t think I’ll ever bother with DirectX, the platform indepent route is much more enticing.

vertizor - no problem, I’ve just been throwing out random theories on how it might work, really. As you can tell, I wasn’t on the dev-team of 3ds max.

thanks again for the links everyone. and btw, you guys seem to have done a lot of this before. What sorts of cool programs have you made??


#10

I’ve made a textured box (wooden crate) that spins. I’ve gotten OpenGL working in MFC, which I was able to work into a 4-viewport 3D modeling type app.


#11

Hey there, you not so far from right, let me give you an example :

public struct vector3{
int x = 0.0;
int y = 0.0;
int z = 0.0;
}

and use this as the basic of the engine, what if this might be the origin of every vertex, polygon or line…

live and learn…


#12

Those should be float not int, otherwise you can’t set them to 0.0 or any other floating point value :slight_smile:

Float datatype is generally more useful in a 3D app anyways.


#13

that’s sort of suggesting critter to create as many problems for himself as possible :smiley:
first an inconvenient datatype (an integer isn’t going to get you far) and then a struct thrown there with no project specifications… what is that exactly supposed to mean? and what was critter not so far from right about? :slight_smile:

there are lots of good and free math libraries out there, without the need to create your own (it’s quite a task in itself, altho you learn lots from a project like that), and they come with their own vector objects (we are dealing with 3D here, defining a vector struct is a spit in the sea compared to what you need, not a starting point).


#14

Whoops im sorry guys my fault it should be floats offcourse how vould i be so stupid, well it was late…


#15

Hmmm… Let’s try some adjustments.


 class vector3{
 public:
 	 vector3(const float& a, const float& b, const float& c) : vec[0](a), vec[1](b), vec[2](c) { }
 	 vector3() { vec[0]=0; vec[1]=0; vec[2]=0; }
 	 float x() { return vec[0]; }
 	 float y() { return vec[1]; }
 	 float z() { return vec[2]; }
 	 void set(const float a, const float b, const float c) { vec[0]=a; vec[1]=b; vec[2]=c; }
 	 void Setx(const float& a) { vec[0]=a; }
  	 void Sety(const float& a) { vec[1]=a; }
  	 void Setz(const float& a) { vec[2]=a; }
 private:
 	 float vec[3];
 };
 
 

Did I miss anything guys?


#16

Haha you know when I saw the int variable =0.0 it raised a mental red flag which is a good thing I guess. I was thinking that it should be double but float makes more sense. Hey mummey, nice code! Lets turn this thread into putting together a small program that would be pretty awesome.


#17

Allright, i was just trying to give him a perspective of how to start-off, i rather use struct to handle small datatypes like camera movements, texturing coordinates and local/world coordinated which get attached to every point/poly aso, but hey who am i :slight_smile:

Btw, im using C# as language

here’s the rest of what i ment!

if you started out with some primitives…

public stract Vector3{
public float X = 0.0;
public float Y = 0.0;
public float Z = 0.0;
}

public struct Attitude{
public float pitch = 0.0;
public float yaw = 0.0;
public float roll = 0.0;
}

finally define a vertex…

public struct Vertex{
public Vector3 Point;
public Vector3 Normal;
public Color Diffuse;
public Color Spectaculair;
public float TU = 0.0;
public float TV = 0.0;
}

So now every time you adress a vertex you allready implemented the coordinate structs…
just for the ones who are intressted since i work with c#…

cheers


#18

I have to say I’m much more fond of mummey’s class then of that shrunk down struct, no offense meant :slight_smile:

also look at the class and the way it structures data, it’s much more flexible then a straight declaration, and could be expanded straight away (with a very simple additions) for quadrivectors, matrices etc. retaining a consistancy of style over the whole math library set.

as for defining a vertex so extensively I wouldn’t know… it’s a bit cumbersome.
defining all that data at once for every vertex.

IE: an explicit normal like that is very unconvenient, what if the model needs to deform? you are going to rewrite the whole vertex for that? if you really want to incorporate it in the vertex definition at least handle it by reference, so that another routine can take care of normal computation and the vertices will always fish the right normals even when those are modified.

also, are there any particular advantages in defining the texture coordinates directly in the vertex?
I can see that going wrong in a number of occasions.

to avoid data redundancy you won’t define each single tri/poly repeating overlapping vertices everytime, you’d be better off with a lookup for a point cloud where shared vertices only take one slot and then another lookup takes care of binding texture space samples to vertices, therefore you declare the UVs in the samples data and look them up, not straight away in the 3D space vertices.

also this kind of handling allows to see if you need to shade continuously or not just looking at the point cloud (overlapping double entries mean the points aren’t merged).

dunno, maybe I’m thinking too much in terms of plugins and dev for 3D apps, while you think in different terms that come from a different school of thought.
where I come from you don’t always need/use all those info about vertices, so this style (including its baked normals) doesn’t make much sense to me.


#19

I’m in agreement. Extra time spent on what will define the program structure can lead to alot of redundant programming prevented.

  class vector3{
  public:
 	 vector3(const float& a, const float& b, const float& c) : vec[0](a), vec[1](b), vec[2](c) { }
  	 vector3() { vec[0]=0; vec[1]=0; vec[2]=0; }
  	 float x() { return vec[0]; }
  	 float y() { return vec[1]; }
  	 float z() { return vec[2]; }
  	 void set(const float a, const float b, const float c) { vec[0]=a; vec[1]=b; vec[2]=c; }
  	 void Setx(const float& a) { vec[0]=a; }
   	 void Sety(const float& a) { vec[1]=a; }
   	 void Setz(const float& a) { vec[2]=a; }
  private:
  	 float vec[3];
  };
 
 class RotationAngle : public Vector3 {
   public:
  	 float yaw() { return Vector3::x(); }
  	 float pitch() { return Vector3::y(); }
  	 float roll() { return Vector3::z(); }
 
  	 void SetYaw(const float& a) { Vector3::Setx(a); }
   	 void SetPitch(const float& a) { Vector3::Sety(a); }
   	 void SetRoll(const float& a) { Vector3::Setz(a); }
 };
  

As for vertex, I don’t think there is an All-in-One solution for them. You could have multiple definitions depends on what you want it to have.


#20

The OOP class method might be nicer looking and clearn/organized, but it is slow. Sure you can use it to make a spinning cube demo and say, “what are you talking about? it’s not slow.” Well throw a couple thousand/million vertices at it and tell me it’s not slow.

Problem with classes (C++ or C#) is the memory allocation of the object doesn’t necessarily have to be linear. So in worst case scenario your program would have to make a few hops and jumps to different memory addresses to get the entire contents of that object. A struct allocates memory linearly, also makes it a little easier to vectorize. Why vectorize? For one thing you get more throughput when you can stream data smoothly to the CPU, moreover it makes more sense when you go to optimize it with SSE/SSE2/3DNow!

Also, when you go to save the scene to a file, you can directly write a struct into file, and read it back later on byte-by-byte. A class must first be serialize (this brings all data of the object together linearly) then written to disk. I can almost guarentee that majority of newbie programmers will sit there writing a routine that loops through all their vertex objects and individually write out each component. Oh excuse me, it’s the 21st century, we convert the numbers into plain text first, then write it out as XML :stuck_out_tongue: