• Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

# McGrane

Member Since 08 Mar 2004
Offline Last Active Today, 11:44 AM

### Understanding Perspective Devide

20 October 2014 - 04:56 PM

**Divide** :/

Hi,

Im hoping someone can help me out here, Im blowing the dust off my maths knowledge, the little that there is
I know that an understanding of the maths behind the perspective divide isint really needed, but I found it interesting, but unfortunatly I have got stuck on something basic, and while I am awating the maths book I have bought off amazon ( taking 3 weeks longer to come from america, but strangly still €30 cheeper ) I tought i could ask here.

I am currently following along a great guide here:

http://unspecified.wordpress.com/2012/06/21/calculating-the-gluperspective-matrix-and-other-opengl-matrix-maths/

I can follow along with this:

```tan( fovy / 2 ) = y / -z
y               = tan( fovy / 2 ) x -z
```

( Nothing compliticated.. Its the next jump I dont understand )

We can simplify the following maths if we define:

```f =  1 / tan( fovy / 2 )
then
y = -z / f
```

Now from what I have read, the 1/tan is the cotangent of the angle, but im just not sure how the tan of an angle multiplied to -z, is the equivalant to -z divide cotangant of angle.

This may make perfect sense to others, but as someone who had never heard of a cotangent before .. it was a bit confusing

From what i under stand, the cotangent is just cos flipped. I have tried looking up some trig to help me along, but I cant seem to find what relates here, Im either getting too basic trig, or jumping onto what i would consider advanced.

If someone could point me in the right direction, i would appreciate it

Thanks

### Beginning GLSL - Quick Question

05 June 2014 - 03:39 PM

Hi,

I have begun delving into the latest OpenGL, and am hoping someone can just answer some basic questions for me.

I'm currently working on a 2d game, I have set up my shaders, and all is well. I have my map loading and rendering correctly to the screen, and even have the view matrix set up to scroll the map. All is good

My map is currently loaded from a basic text file, the coords and colours are calculated, and are stored in a 1D array contiguously. What I now want to do is add a basic character, this is where I got confused. I add the the tile for this character - But am unsure of how I should go about moving him independently to the rest of the map. Should I just update the positions on the array, and then send the whole array to be drawn again? - Or do I set up a second shader program, and run them independently ? Or maybe is there a way to just update certain index of the array loaded in the GPU?

I use uniforms to update the matrices and such in the shaders, but really don't know how id update just one tile out of 4000/whatever.

I have not added any code, as I dont think its really relevant - but easily can if needed.

Im sure there is any easy answer for this, im just hoping someone can point me in the right direction - to save me wondering around google aimlessly

David.

### Another Component Entity System Question

20 February 2014 - 05:57 PM

Hi All,

After reading the abundance of message's recently about the subject, it got me interested in researching into it. Al tough I feel that I understand the theory behind it, there are a few conflicting ideas in articles and question I have, and am hoping someone can help me with.

In relation to the article I read on GameDev http://www.gamedev.net/page/resources/_/technical/game-programming/implementing-component-entity-systems-r3382 I have implemented a small demo using this, but am unsure if i'm going in the right direction.

In the article things are defined as Position[Entity_MAX], Velocity[Entity_MAX], Appearance[Entity_MAX].

When an entity is created, it returns an unsigned int, which I take to go across all arrays - for example the first entity that is created has a position and a velocity which is Position[0], Velocity[0], if a static item was then added it would be Position[1] and Appearance[1].

My real confusion is of the empty space ( if my understanding of how it all ties together is correct ) If I have many components created in this way - for example 50, and the majority of my entity's only use one or two of these components at a time - will that not just waste a wide range of space? - or is this acceptable because of the cache speed increase?

Alternately, am I just creating the Components in the wrong way? While using the technique he shows for the mask, I run into a problem.

My code at the minute, when being used to move and render is as below

```World    = new s_World;

CreateDynamicObject( World, 0.0f, 0.0f, 0.0001f, 0.0001f ); // xPos, yPos, xVel, yVel

Graphics = new cGraphics();
Physics  = new cPhysics();
```
```void cGame::Render() {

glClearColor( 0.1f, 0.1f, 0.1f, 1.0f );
glClear( GL_COLOR_BUFFER_BIT );

Physics->Update( World );

Graphics->Render( World );
}
```
```void cGraphics::Render( s_World *World ) {

for( int entity = 0; entity < ENTITY_MAX; entity++ ) {

// Render Code
}
}
}
```

Using this method, if the mask is a STATIC_MASK, it will render it - but if I also want it to render dynamic, do i just add another if statment, and another mask, and so on and so on until I have every scenario that needs to be rendered / Anything else i want to do

Im sure some of these questions about masks and things are going over peoples heads that have not actually read the article. But im hoping that someone with experience using a similar system can help me out.

Please let me know if I need to clarify this post more ;)

Any information / insight would be appreciated
David

### Texture problems with vertex arrays - OpenGL

26 March 2013 - 08:42 AM

Hey people,

Im having trouble getting my textures to display right.

The square in the top left is the image i am using, and as you can see, the images are coming out wrong.

The output of my program as far as i can see is in the correct format..

```	Index: 1	tX: 0	tY: 0
Index: 2	tX: 1	tY: 0
Index: 11	tX: 1	tY: 1
Index: 1	tX: 0	tY: 0
Index: 11	tX: 1	tY: 1
Index: 10	tX: 0	tY: 1
Index: 3	tX: 0	tY: 0
Index: 4	tX: 1	tY: 0
Index: 13	tX: 1	tY: 1
Index: 3	tX: 0	tY: 0
Index: 13	tX: 1	tY: 1
Index: 12	tX: 0	tY: 1
Index: 5	tX: 0	tY: 0
Index: 6	tX: 1	tY: 0
Index: 15	tX: 1	tY: 1
Index: 5	tX: 0	tY: 0
Index: 15	tX: 1	tY: 1
Index: 14	tX: 0	tY: 1
Index: 7	tX: 0	tY: 0
Index: 8	tX: 1	tY: 0
Index: 17	tX: 1	tY: 1

```

This is my code for displaying the images.

```glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );

glVertexPointer( 3, GL_FLOAT, 0, m_vertices );
glTexCoordPointer( 2, GL_FLOAT, 0, texCoords );

glBindTexture(GL_TEXTURE_2D, m_textureOne );
glDrawElements( GL_TRIANGLES, m_ammountPoints, GL_UNSIGNED_INT, m_squareLight );

glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
```

Any ideas what could be going wrong ? - as far as i can tell, the indices seem to line up with the texcoords.. But everysqure seems to be different ?

### C++ Array

26 February 2013 - 05:18 PM

Hi,

Im currently looking at motion detection, and im looking for the most efficient way to check a large array for change. What i was thinking is splitting the 1D array up using a quadtree. And then just doing a small check on the larger area, and more indepth calculations the further into the tree as it goes. My question here is this an efficent way to do it ? Or is there a better method to use?- is less better here, If im doing this check every few frames of a video, would it be better to just check one array of the next in a whole ?

Thanks !

 Sorry... i ment to post this is general programming :S - Can someone move it ?

PARTNERS