realistic "space" physics?

Blitz3D Forums/Blitz3D Programming/realistic "space" physics?

AdsAdamJ(Posted 2005) [#1]
I'm currently trying to make a simple little 3D Asteroids clone for programming practice, but I've hit a major snag; I need to simulate realistic space physics for the player controlled ship.

I've tried a bit of a 'cheat' method by recording the old position of the ship, moving and rotating it, then measuring the distance it's moved, moving it back and translating the ship the distance it's moved. Thinking this over, it's pretty obvious why it doesn't work! I'm sure it *is* possible doing it this way with a bit of modification, but my brains are just not working at the moment.

The alternative is to get maths heavy and perform vertex calculations, etc. I'll admit that my geometry isn't brilliant with this sort of thing. Essentially, all I need to do is add the thrust vector to the velocity vector. Sounds simple enough I guess, but I don't really know where to start.

Any ideas? Articles I can read? (that isn't written in double-dutch!)

Thanks. :)

EDIT: Adding vertices isn't the problem by the way. When they are using rectagular coords (XYZ, etc.) it's easy! It's much harder when it involves angles and velocities though which is what blitz uses...


AdsAdamJ(Posted 2005) [#2]
I did it. :D

I acheived it by parenting the ship mesh to a pivot. Here's the code I used:

	Local mxspd#, myspd#, zoom#
	Local xspd#, yspd#, zspd#	
	
	; Mouse rotation
	mxspd = MouseXSpeed() * .2
	myspd = MouseYSpeed() * .2
	
	MoveMouse GraphicsHeight()/2, GraphicsWidth()/2
	
	If MouseDown(2) Then
		TurnEntity player\obj, myspd, 0, mxspd
	Else
		TurnEntity player\obj, myspd, -mxspd, 0
	End If
	
	If KeyDown(KEY_S) Then
		MoveEntity player\obj, 0, 0, .01
	
		xspd = EntityX(player\obj)
		yspd = EntityY(player\obj)
		zspd = EntityZ(player\obj)
	
		MoveEntity player\obj, 0, 0, -.01
	
		player\h = player\h + xspd
		player\v = player\v + yspd
		player\d = player\d + zspd
	End If

	TranslateEntity player\piv, player\h, player\v, player\d


This probably isn't the best way of doing it, but it sure does work!


Jeppe Nielsen(Posted 2005) [#3]
You can also use the TformVector command:


	If KeyDown(KEY_S) Then

		TFormVector 0, 0, 0.01,player\obj,0
	
		player\h = player\h + TFormedX()
		player\v = player\v + TFormedY()
		player\d = player\d + TFormedZ()

	End If




AdsAdamJ(Posted 2005) [#4]
Very useful, thanks!

(nice site, btw)


Picklesworth(Posted 2005) [#5]
I did a space physics thing with Sweeney's Tokamak wrapper... you could give that a shot.
I have code and media here:
http://www.blitzbasic.com/Community/posts.php?topic=52824
Just play with the linear damping if you want to make it more asteroids-ish