Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 01 Aug 2011
Offline Last Active Jan 13 2013 02:16 PM

Topics I've Started

OpenSource 2D RPG Engine iOS (OpenGL, C++)

10 April 2012 - 02:39 AM

Hey Community,

i decided yesterday to open source my 2d Engine and did it today in the morning. The link to my github can be found on http://howtomakeitin...m.wordpress.com . (stupid name i know)

The code is approx. 9 months old and it was the first time i wrote something big like this so don't be angry if it is not so beatiful as it should be :-) I wrote everything from scratch, the rendering, the script engine, the animation engine etc.

The source code to the level editor will follow next week. It is written in Objective C cocoa and C++ (same rendering code as the game)

Have fun,

Angle between two vectors - the law of cosines - derivation problem

11 February 2012 - 03:23 AM

Hello math community,

i am studying for math at the moment and I am stuck a bit with the derivation of the law of cosines. First of all, sorry if i mention some things wrong, I study in german so it could be that we name some things different. :-)

My problem is that i don't know how to go on after a certain step. It would be cool if you could point me in the right direction .


Derive the law of cosines from a triangle made of 2 vectors

a = { ax, ay az }
b = { bx, by, bz }

c = b - a

All lengths are unknown and arbitrary.

So, we are looking for c, alpha, beta & gamma

alpha is between c and b
beta is between c and a
gamma is between a and b

the longest side is c which can be separated into p and q which will give me two right angled triangles.

From this information i can easily get

cos alpha = p / b -> p = b * cos alpha

cos beta = q / a -> q = a * cos beta

c = p + q

c = b * cos alpha + a * cos beta

so far so good ^-^

In the book is written that I shall do the same for the sides a and b. And that is were i get stuck. All the time i am calculating the same stuff on and on again but i am not able to go one step further. It seems that i am missing some variable or s.th.

Lets say the opposite leg of alpha is h

so b = sqrt ( p * p + h * h )

p = cos alpha * b

h = ??? <- how

i ??

The goal is to get

c*c = a*a + b*b - 2ab*cos gamma

OGL "Big Framerate drop with 2d tile map" (on iOS)

11 September 2011 - 05:16 AM

Hello Game Dev Community,

once again I have a question to you and maybe you can help me out with it. The fact is that I try to display a tile map on my iPhone. The problem occurs when i try to display more than 30x30 tiles.. Beyond that benchmark, the FPS is ok but at around 50x50 the character movement is tremendously slow.

Maybe the problems lays in the scrolling? When the player moves up, the whole map moves down (with glTranslatef) and i do glPushMatrix() glPopMatrix() before i draw each tile.. can this be the reason?

My other ideas to handle this where:

-spriteBatch which loads texture and vbo for units who share this information (tried, didn't speed it up)

Here are the codes which may be interesting for you:

Core Drawing routine:

void Sprite2D::draw_to_scene(GLuint texture_id)

    glTranslatef(this->rect.pos.x, this->rect.pos.y, 0.0f);
    glRotatef(this->angle, 0, 0, 1);
    glScalef(this->scalar, this->scalar, 0.0f);

    // i tried to cut out this part into a batchBegin function

    glBindTexture(GL_TEXTURE_2D, this->texture);
    glBindBuffer(GL_ARRAY_BUFFER, this->vbo);
    glVertexPointer(3, GL_FLOAT, 0, (char*)NULL);

    // until here.. didn't gave me a big performance hit

    glBindBuffer(GL_ARRAY_BUFFER, this->tbo[texture_id]);			<- right now i create for each texture on the tex atlas a tbo which i switch
    glTexCoordPointer(2, GL_FLOAT, 0, (char*)NULL);	               mabye this slows it down?

    glDrawArrays(GL_TRIANGLES, 0, this->vertex_count);



Scrolling and Drawing Routine from World Map

void WorldMap::draw()
    for (int i = 0; i < nRows; i++)
        for (int j = 0; j < nCols; j++)

void WorldMap::update_world_coordinates(const AnimatedChar &_char)
    Point2D temp;

    if (_char.getMoving())
        for (int i = 0; i < nRows; i++)
            for (int j = 0; j < nCols; j++)
                temp.x = this->tiles_layer1[i][j].sprite->getRect().pos.x;
                temp.y = this->tiles_layer1[i][j].sprite->getRect().pos.y;

                if (_char.getViewDirection()==DOWN)
                    temp.y -= _char.getMovingSpeed();
                else if(_char.getViewDirection()==LEFT)
                    temp.x += _char.getMovingSpeed();
                else if(_char.getViewDirection()==RIGHT)
                    temp.x -= _char.getMovingSpeed();
                else if(_char.getViewDirection()==UP)
                    temp.y += _char.getMovingSpeed();


Any help is highly appreciated. I think i have a logic mistake somewhere. I read on stacks overflow that i should scroll with glOrtho for example instead of translating the whole world all the time..

Thanks very much!!



2D Tileset Map Editor SOURCE CODE online

08 September 2011 - 05:51 AM

Hey guys,

i uploaded my 2d tileset map editor source code on my homepage.. !!
Feel free to play around with it, learn from it, flame me about mistakes i made :-)


Bye Markus

Loading 3ds Model (MultiObjects)

19 August 2011 - 06:30 PM

Hello everybody..

for my 3d engine i've written a loader for 3ds models based on some tutorial i found on the net called spacesimulator or s.th. like this .-). It works perfectly fine when i import a model which consists out of one mesh.. texture and model will be displayed correctly. But when i load in an object which consists of multiple meshes, lets say a car.. which consists out of the main part and 4 weels, only one wheel gets rendered and the rest of the 4 parts not. i probably think that this is because i need to read out the other meshes as well and displaying them.

the 3ds file looks like this:
[size=2]|  +--EDIT_OBJECT   (0x4000)[/size]

[size=2]              	|  |  |[/size]

[size=2]              	|  | +--OBJ_TRIMESH   (0x4100)  	[/size]

[size=2]              	|  | |  |[/size]

[size=2]              	|  | |  +--TRI_VERTEXL      	(0x4110) [/size]

[size=2]              	|  | |  +--TRI_VERTEXOPTIONS	(0x4111)[/size]

[size=2]              	|  | |  +--TRI_MAPPINGCOORS 	(0x4140) [/size]


and i read out 4110 to 4140 like this:



[font="'Courier New"][size="2"]while blabla: switch (chunk_id)

		case 0x4100:			// Object Trimesh


		case 0x4110:			// Tri Vertex (Vertices List)

			fread(&l_qty, sizeof(unsigned short), 1, l_file);

			this->vertices_qty = l_qty;


			for (i = 0; i < l_qty; i++)


				fread(&this->vertex[i].x, sizeof(float), 1, l_file);

				fread(&this->vertex[i].y, sizeof(float), 1, l_file);

				fread(&this->vertex[i].z, sizeof(float), 1, l_file);



		case 0x4120:

			fread(&l_qty, sizeof(unsigned short), 1, l_file);

			this->polygons_qty = l_qty;


			for (i = 0; i < l_qty; i++)


				fread(&this->polygon[i].a, sizeof(unsigned short), 1, l_file);

				fread(&this->polygon[i].b, sizeof(unsigned short), 1, l_file);

				fread(&this->polygon[i].c, sizeof(unsigned short), 1, l_file);

				fread(&l_face_flags, sizeof(unsigned short), 1, l_file);



		case 0x4140:

			fread(&l_qty, sizeof(unsigned short), 1, l_file);

			for (i = 0; i < l_qty; i++)


				fread(&this->mapcoord[i].u, sizeof(float), 1, l_file);

				fread(&this->mapcoord[i].v, sizeof(float), 1, l_file);




			fseek(l_file, l_chunk_length-6, SEEK_CUR);




It wonders me that i skip through the different vertices, polygons and tex coordinates but not through the object. where in the 3ds files are they defined then? so where is the point where the next objects begins...

Hope someone can help me.. it would really like to understand the concept ..
For completeness: Thats how i draw them:

[size="2"]	glBindTexture(GL_TEXTURE_2D, this->texture->get_texture());[/size]
[size="2"]	glBegin(GL_TRIANGLES);[/size]
[size="2"]	for (unsigned int i = 0; i < this->polygons_qty; i++)[/size]
[size="2"]	{[/size]
[size="2"]		glTexCoord2f(this->mapcoord[this->polygon[i].a].u,[/size]
[size="2"]	                 this->mapcoord[this->polygon[i].a].v);[/size]
[size="2"]		glVertex3f(this->vertex[this->polygon[i].a].x,[/size]
[size="2"]                   this->vertex[this->polygon[i].a].y,[/size]
[size="2"]                   this->vertex[this->polygon[i].a].z);[/size]
[size="2"]		glTexCoord2f(this->mapcoord[this->polygon[i].b].u,[/size]
[size="2"]	                 this->mapcoord[this->polygon[i].b].v);[/size]
[size="2"]		glVertex3f(this->vertex[this->polygon[i].b].x,[/size]
[size="2"]                   this->vertex[this->polygon[i].b].y,[/size]
[size="2"]                   this->vertex[this->polygon[i].b].z);[/size]
[size="2"]		glTexCoord2f(this->mapcoord[this->polygon[i].c].u,[/size]
[size="2"]	                 this->mapcoord[this->polygon[i].c].v);[/size]
[size="2"]		glVertex3f(this->vertex[this->polygon[i].c].x,[/size]
[size="2"]                   this->vertex[this->polygon[i].c].y,[/size]
[size="2"]                   this->vertex[this->polygon[i].c].z);[/size]
[size="2"]	}[/size]
[size="2"]	glEnd();[/size]