Physics in a Game World
OK, hello again.
I have a physics-less game game and am writing some functions for my game. Currently I am using a function like this:
![[Image: i6i1ja.png]](http://i36.tinypic.com/i6i1ja.png)
and the code is this:
]
Now, I can't get this code to work (help would be appreciated) but when I did, all it would spit out is the average y for a wide square of map, which would be OK for deserts, but rubbish for anything else, e.g. the player walks halfway up a wall.
Is there another option? Or should I just increase the 160 to 512 or something?
I have a physics-less game game and am writing some functions for my game. Currently I am using a function like this:
![[Image: i6i1ja.png]](http://i36.tinypic.com/i6i1ja.png)
and the code is this:
Code:
void gravPhysics(Mesh *mesh)
{
float x1;
float y1;
float z1;
x1 = (mesh->verts[counter+1]); // *
z1 = (mesh->verts[counter+2]); // | This finds the first point
y1 = (mesh->verts[counter+3]); // *
for (indexSQ = 0; (indexSQ <= 25600) ; indexSQ += 0 )
{
printf("Entered for loop...\n");
printf("SQRX is %i\n", (indexSQ % 160));
x1 = mesh->verts[counter+1]; // *
z1 = mesh->verts[counter+2]; // | This finds the first point
y1 = mesh->verts[counter+3]; // *
printf("x1 = %f y1 = %f z1 = %f\n",x1,y1,z1);
if ( (x1 <= sqrx) && (x1 >= sqrx) && (z1 <= sqry) && (z1 >= (sqry -1))) // checks if the first point is in the square designated by sqr
{
counter += 3;
vt += y1;
vtcount ++;
printf("The vertex is in the box...\n");
}
else
{
if (vtcount > 0)
{
squares[sqrx][sqry] = (vt/vtcount);
vtcount = 0;
vt = 0;
printf("Setting Y position of vertex: %d\n" , counter+1);
}
else
{
indexSQ ++;
sqrx = (indexSQ % 160);
sqry = ( indexSQ - sqrx ) / 160;
}
}
}
}Now, I can't get this code to work (help would be appreciated) but when I did, all it would spit out is the average y for a wide square of map, which would be OK for deserts, but rubbish for anything else, e.g. the player walks halfway up a wall.
Is there another option? Or should I just increase the 160 to 512 or something?
~ Bring a Pen ~
P.S. I realised I did not include the bit that when finished searching the box's vertices sets the y for squares[sqrx][sqry] to VT/vtcount.
~ Bring a Pen ~
A couple things.
This line appears to increment by zero
for (indexSQ = 0; (indexSQ <= 25600) ; indexSQ += 0 )
and this line would only be true when x1 == sqrx
if ( (x1 <= sqrx) && (x1 >= sqrx) && (z1 <= sqry) && (z1 >= (sqry -1)))
This line appears to increment by zero
for (indexSQ = 0; (indexSQ <= 25600) ; indexSQ += 0 )
and this line would only be true when x1 == sqrx
if ( (x1 <= sqrx) && (x1 >= sqrx) && (z1 <= sqry) && (z1 >= (sqry -1)))
Quote:This line appears to increment by zero
for (indexSQ = 0; (indexSQ <= 25600) ; indexSQ += 0 )
Well, as you can see from the flowchart, indexSQ only changes when we move the squares block.
Quote:if ( (x1 <= sqrx) && (x1 >= sqrx) && (z1 <= sqry) && (z1 >= (sqry -1)))
Oops, my mistake. as you can see from y1's example, it should be this:
Code:
if ( (x1 <= sqrx) && (x1 >= (sqrx-1)) && (z1 <= sqry) && (z1 >= (sqry -1)))~ Bring a Pen ~
mikey Wrote:Well, as you can see from the flowchart, indexSQ only changes when we move the squares block.Perhaps it would be more appropriate to use this then:
Code:
while (indexSQ <= 25600)
Did the new version of that if statement help with your problem?
Yeah, I originally wanted to put an if in a for loop? But this can't be done.
And no, it did not fix my problem.I think I'm going to use octrees:
split the map into 4 and then figure out which corner the player is nearest to, then find the closest vertex by checking all the vertex' in that corner. Thanks anyway though, I may use this code in a flight sim.
*cuckoo*
And no, it did not fix my problem.I think I'm going to use octrees:
split the map into 4 and then figure out which corner the player is nearest to, then find the closest vertex by checking all the vertex' in that corner. Thanks anyway though, I may use this code in a flight sim.
*cuckoo*
~ Bring a Pen ~
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Bullet Physics Library / COLLADA physics viewer | erwincoumans | 14 | 11,327 |
Aug 12, 2006 12:59 AM Last Post: Fenris |
|
| Game Data In A OOP World | KiroNeem | 5 | 3,726 |
Feb 15, 2006 03:46 PM Last Post: zKing |
|
| Good Game Loop with Physics Units | blobbo | 6 | 4,082 |
Oct 14, 2005 02:59 AM Last Post: unknown |
|
| Free sample chapter from Physics for Game Programmers | Leisure Suit Lurie | 9 | 5,330 |
Jul 25, 2005 05:14 PM Last Post: codemattic |
|
| 2D Game Physics 101 | Malarkey | 4 | 6,259 |
Apr 7, 2005 09:09 PM Last Post: PowerMacX |
|

