Newton/Irrlicht FPS source code available
Newton/Irrlicht FPS source code available
I've been working on a FPS character controller using Newton and Irrilicht with the following features
first person view camera
head tilt
following camera
jump
crouch
stairs
newton based movement, newton used for collision detection and navigation.
Anyone interested in source code can contact me at dhenton[at]users[dot]sourceforge.net
If there is enough interest I will see about packaging this as a tutorial.
first person view camera
head tilt
following camera
jump
crouch
stairs
newton based movement, newton used for collision detection and navigation.
Anyone interested in source code can contact me at dhenton[at]users[dot]sourceforge.net
If there is enough interest I will see about packaging this as a tutorial.
-
- Posts: 395
- Joined: Fri Apr 08, 2005 8:46 pm
-
- Posts: 98
- Joined: Mon Dec 13, 2004 11:47 am
- Location: Japan
Very impressive stuff! Player movement was the bit that looked the trickiest to me. Looks like we're really close to sorting out Irrlicht and Newton now. I've made some headway with vehicles - as soon as I get my laptop back from being repaired (grrr) I'll post that too. Yes a tutorial explaining how you went about it would be very interesting; your code looks very clear and readable but it's always nice to have these things described in plain english. It seems that Newton is the physics engine many people are trying to use with Irrlicht and so having proven implementations of the two working together would be a great asset. Many thanks and much respect for sharing your work - keep it up!
-
- Posts: 395
- Joined: Fri Apr 08, 2005 8:46 pm
This is guest (now properly logged in)RLG unlogged wrote:hey i was playin with ur source and tried using the .bsp map that comes with irrlicht, and my character just falls thru everytime, any help guys?
When this happened to me, It was because the newton box was not "above" anything. I have to position it by hand over an area that I know will catch it (done by trial and error).
That would be my guess.
-
- Posts: 98
- Joined: Mon Dec 13, 2004 11:47 am
- Location: Japan
-
- Posts: 395
- Joined: Fri Apr 08, 2005 8:46 pm
The 2 functions to look at are in the CNewtonPlayerController class
They are ApplyPlayerForceEventHandler and SetPlayerMeshTransformEventHandler
In the ApplyPlayerForceEventHandler is the following code
The acceleration vector is what gets this object moving. As to why it skips over small objects and stairs, I haven't a clue. The developers of Newton have a Newton forum post somewhere mentioning that the solver/integrator used can't resolve certain kinds of differences. (Maybe I just dreamt that.)
I think the reason it works is that the stair step is seen as a ramp if the rise and run are small enough. So there is a depencency on the ratio of the player ellipsoid size and the stair tread. I'm pretty sure its just a fluke that it works, but I can't think of any other way to get it to work. Your post on character control on the Newton forum includes that response from others who tried it: there might be a better way, but not an easier one.
So really there isn't any place in the code, other than the absolute sizing of the player object, and then the requirement that the environment have a certain size. I'm planning to size all my future mesh work according to the demo.
They are ApplyPlayerForceEventHandler and SetPlayerMeshTransformEventHandler
In the ApplyPlayerForceEventHandler is the following code
Code: Select all
if (direction != 0.0f)
{
double dx = sin(m_Theta*3.14159/180);
double dz = cos(m_Theta*3.14159/180);
vector3df movevelocity((float) dx, 0.0f, (float) dz);
movevelocity.normalize();
movevelocity *= direction;
NewtonBodyGetVelocity(body,&velocity.X);
goalvelocity = movevelocity * PLAYER_SPEED;
acceleration.X = mass*((goalvelocity.X - velocity.X) / timestep);
acceleration.Z = mass*((goalvelocity.Z - velocity.Z) / timestep);
}
I think the reason it works is that the stair step is seen as a ramp if the rise and run are small enough. So there is a depencency on the ratio of the player ellipsoid size and the stair tread. I'm pretty sure its just a fluke that it works, but I can't think of any other way to get it to work. Your post on character control on the Newton forum includes that response from others who tried it: there might be a better way, but not an easier one.
So really there isn't any place in the code, other than the absolute sizing of the player object, and then the requirement that the environment have a certain size. I'm planning to size all my future mesh work according to the demo.
-
- Posts: 395
- Joined: Fri Apr 08, 2005 8:46 pm
The new and final home for the source is http://www.s-fonline.com/webhosting/dhenton9000
-
- Posts: 395
- Joined: Fri Apr 08, 2005 8:46 pm
I've uploaded an update which includes the following features
Ammo Counter
Use of Irrlicht Animators for timing events (weapon fires 50 times then "cools down" for 2 seconds)
Attached weapon to FPS camera
Newton spheres as bullets--collision is reported via the Newton material callback system.
Love to have someone check it out. The bullets don't do much , but you can see them if you hit the "I" key.
Also included a binary
Files at
http://www.s-fonline.com/webhosting/dhenton9000
Ammo Counter
Use of Irrlicht Animators for timing events (weapon fires 50 times then "cools down" for 2 seconds)
Attached weapon to FPS camera
Newton spheres as bullets--collision is reported via the Newton material callback system.
Love to have someone check it out. The bullets don't do much , but you can see them if you hit the "I" key.
Also included a binary
Files at
http://www.s-fonline.com/webhosting/dhenton9000