Advertisement

How to program a chess: a forum based tutorial

Started by December 23, 2004 11:09 PM
276 comments, last by da_grat1 19 years, 8 months ago
Quote:
Also, about the menus. Will we be using the basic dialog boxes for that? Or will we be putting bmps on these buttons and just catching the click and loading the particular context?

Are you thinking about using classes or function libs for the window creation/management(resizing, switching style etc)?


Some details on the menus:
- We will be using a combination of dialog boxes and basic controls for the menus (they are actually going to use the same drawing code)
- No bitmaps for the drawing code but its easy to do
- We will be using function libs for the drawing code and classes for the individual controls. The controls we will be supporting are the frame control and the button control (buttons go in frames).

We will not be supporting style switching or resizing since these features are not necessary but it can easily be done. You may also want to consider writing a menu style loader so that users can customize skins.
Although I have been following this thread since it started, I have not yet had the time to download the source for this project (due to the fact that I've not been home a whole lot since this thread began)and I just wanted to know exactly what libraries do I need for it to run.

So, if you would plz tell me the name of all the libs (and external programs like milkshape for example) that I would need and where I could get them that would be great.

Thanks.
Advertisement
I've documented all of the necessary libraries and where to find them in the respective inc_...h files. Heres a list of sdk files you should need:

- OpenAL
- OpenIL
- Ogg Vorbis

We will also be programming a model exporter for milkshape but you dont actually need milkshape (maybe just to try it out) to understand the code. I'll run the exporter and produce the assets using my copy of milkshape.

Will post tomorrow,
- llvllatrix
Quote: We will also be programming a model exporter for milkshape but you dont actually need milkshape (maybe just to try it out) to understand the code. I'll run the exporter and produce the assets using my copy of milkshape.

can I use the same code for 3d max
You should be able to use part of it but not all. You're going to have to download the 3ds max sdk and write the plugin using their api. The best way to go about this, imo, is to modify one of the given examples.
Hey guys,

I thought I should spend a bit of extra time to make it easier for someone to port our 3d format's exporter. Heres the interface to our model loading subsystem...still working on the implementation...

#ifndef __RES_MDL_MODEL_H__#define __RES_MDL_MODEL_H__//----------------------------------------------------------------------------////res_mdl_model.h////Copyright © Rishi Ramraj, 2004// Model loading/displaying library//----------------------------------------------------------------------------//··········································································////    header :: Inclusions//··········································································//#include "res_img_image.h"//··········································································////    header :: Definitions//··········································································////··········································································////    header :: Structures//··········································································////··········································································////    header :: Class Defs//··········································································//// Class design philosophy// These classes are designed to operate in two modes; read mode and write mode.// To use write mode, use the init function to initalize the respective class// with the desired values. Behaviour is undefined if both modes are used together. // The read, write, or init functions should only be called once. Both read and // write functions append directly onto the file passed.class res_mdl_vertex{public:	res_mdl_vertex();	~res_mdl_vertex();	// sends the vector data to OpenGL	void draw(void);	// reads vector data from the FILE struct passed	bool read(void * file);		bool init(float v_x, float v_y, float v_z, 			  float u, float v);	// writes vector data to the FILE struct passed	bool write(void * file);private:	// vertex data	float vertex[3];	// texture coordinates	float tex_u;	float tex_v;};class res_mdl_normal{public:	res_mdl_normal();	~res_mdl_normal();	// sends the normal data to OpenGL	void draw(void);	// reads normal data from the FILE struct passed	bool read(void * file);	bool init(float n_x, float n_y, float n_z);	// writes normal data to the FILE struct passed	bool write(void * file);private:	// normal data	float normal[3];};class res_mdl_triangle{public:	res_mdl_triangle();	~res_mdl_triangle();	// sends the triangle data to OpenGL	void draw( res_mdl_vertex * vertices, res_mdl_normal * normals);	// reads vector data from the FILE struct passed	bool read(void * file);	bool init(int v_1, int v_2, int v_3, 		      int n_1, int n_2, int n_3);	// writes vector data to the FILE struct passed	bool write(void * file);private:	// triangle data	int vertex_indices[3];	int normal_indices[3];};class res_mdl_material{public:	res_mdl_material();	~res_mdl_material();	// sends the material data to OpenGL	void draw(void);	// reads material data from the FILE struct passed	bool read(void * file);	// Note that path is duplicated in memory	bool init(float al_x, float al_y, float al_z, 		      float dl_x, float dl_y, float dl_z,			  float sl_x, float sl_y, float sl_z,			  float el_x, float el_y, float el_z,			  const char * path);	// writes material data to the FILE struct passed	bool write(void * file);private:	// material data	float ambiant_light[4];	float diffuse_light[4];	float specular_light[4];	float emissive_light[4];	res_img_image texture;	// path is only used for writing	// path is stored to resolve an issue that arises with the write function. 	// The class is responsible for writing the relative path of the texture to	// disk, but the path does not need to be stored when the class is used	// under read mode circumstances.	char * path;};class res_mdl_mesh{public:	res_mdl_mesh();	~res_mdl_mesh();	// sends the mesh data to OpenGL	void draw(void);	// reads mesh data from the FILE struct passed	bool read(void * file);	// Note that the pointers are not duplicated in memory.	// They should be allocated using new. The mesh class	// will delete the data after it goes out of scope.	bool init(int mi,			  int n_verts, res_mdl_vertex	* verts,			  int n_norms, res_mdl_normal	* norms,			  int n_faces, res_mdl_triangle	* faces);	// writes material data to the FILE struct passed	bool write(void * file);private:	// mesh data	int material_index;	int num_vertices;	res_mdl_vertex * vertices;	int num_normals;	res_mdl_normal * normals;	int num_triangles;	res_mdl_triangle * triangles;};class res_mdl_model{public:	res_mdl_model();	~res_mdl_model();	// sends the mesh data to OpenGL as a display list	void draw(void);	// reads mesh data from the FILE struct passed. Once the model	// has been read, it is sent to OpenGL as a display list.	bool read(void * file);	// Note that the pointers are not duplicated in memory.	// They should be allocated using new. The model class	// will delete the data after it goes out of scope.	bool init(int n_mats  , res_mdl_material * mats,			  int n_meshes, res_mdl_mesh	 * meshes);	// writes material data to the FILE struct passed	bool write(void * file);private:	// model data	int num_materials;	res_mdl_material * materials;	int num_meshes;	res_mdl_mesh * meshes;	unsigned int display_list;};//··········································································////    header :: Function Defs//··········································································////----------------------------------------------------------------------------//res_mdl_model.h//Copyright © Rishi Ramraj, 2004//----------------------------------------------------------------------------#endif //__RES_MDL_MODEL_H__


I'm still working on tweaking it to make it a bit easier to use (scalable that is). I will probably end up changing the interface a bit before the subsystem is complete. Should be done by tomorrow.

Once the model loading subsystem is done, I'll take a bit of time to discuss how chess game logic/ai is programmed on a computer. This way we can hammer out a rough design for our implementation before we get there.

Till then,
- llvllatrix
Advertisement
wah.. there are so many classes to define... where can i learn the basic of the coding.. :) ?

To be honest.. I can wait until tomorrow :) ....I can't wait to see the model loading.. :)
Hey guys,

Time for a short tutorial on model loading. The format I've specified may not seem intuitive at first, but the design is fairly common between most polygon based modeling systems. Lets say we we're going to develop a modeling system from scratch. The first step you would probably take is something like this:

struct mdl_triangle{   float point_one[3];   float point_two[3];   float point_three[3];};


Basically we store a mesh as a collection of these triangle structures. Wile this structure may seem like a good idea at first it runs into some preformance issues when put into practice. Most models used in games are continous (like a shell), so edges between triangles are shared between triangles:

/*   -----------                           \        / \                           \      /   \                           \    / <---\----- shared edge          \  /       \                           \/_________\                   */


If we used our triangle struct, then the vertex data would be duplicated for every shared edge (and all edges in game models are usually shared). To get around this problem we divide the mesh into several parts. We have an array of vertices, indexed from 1 to n. All vertices that are in the mesh are in this vertex list. We then have an array of triangles that compose the mesh. Instead of actually storing the vertex data, all the triangles have to store now is the index of the vertices that compose the triangles. We use a similar technique to store the normal data for the triangles.

A similar technique is also used to store the model's materials. The model is divided into an array of materials used in the model and an array of meshes. Each mesh represents the use of a different material. The mesh uses an index into the array of materials and thats it...

Will post later,
- llvllatrix

[Edited by - llvllatrix on January 27, 2005 6:47:09 AM]
why do we need to draw triangle... but not rectangle... i know this sound like stupid question.. :) i just want to know..
The triangle is the most basic shape(with area) in 3d. We can approximate every other shape (including circles) using it. In fact, everything that gets sent to OpenGL ultimately gets reduced to a set of triangles. Here's how we make a rectangle:

/*   _______                |    /|   |   / |   |  /  |   | /   |   |/____|*/


Good question :),
- llvllatrix

This topic is closed to new replies.

Advertisement