Circle (Sin,Cos) functions, Train movement etc.

If you're looking for mapping help or you reckon you're a mapping guru, post your questions / solutions here

Moderator: Moderators

Post Reply
Condor
Colour Sergeant
Posts: 82
Joined: Mon Apr 09, 2007 3:19 pm
Location: Bavaria (Germany)

Circle (Sin,Cos) functions, Train movement etc.

Post by Condor »

Hi,

im currently working on another MOH-technical realisation. It is a subway train, controlled by a player (triggeruse for brake/accelerate), moving on a circle:

Image

The new position is calculated by an for(i,0,359) loop, with X=aSin[360-i] * TunnelRadiusFromMapCentre and Y=aCos[360-i] * TunnelRadiusFromMapCentre.
and then

Code: Select all

$Train time level.trainspeed
$Train moveTo (X Y level.trainZ)
$Train waitmove
thread trainrotate

trainrotate:
$Train time level.trainspeed
$Train rotateYdown 1
end
Three Problems:
First:
All the things work, but i have to calculate an array for Sinus from 0 to 90.
Any way to calculate a Sinus/Cosinus-Value on demand? My script file is full of

Code: Select all

...
level.aSin[48] = ...
level.aSin[49] = 0.754709580222771
level.aSin[50] = 0.766044443118977
level.aSin[51] = 0.77714596145697
level.aSin[52] = 0.788010753606721
level.aSin[53] = 0.798635510047292
level.aSin[54] = 0.809016994374947
level.aSin[55] = 0.819152044288991
level.aSin[56] = ....
...
:? :(

Next Problem: If the trainspeed is smaller than 0.3 everytime I hit anything inside the train, the camera begins to "shiver" - Can I manipulate the movement in any way, that the collision of the train and my player charakter is properly calculated.

Last but not least: Why can't I store my level background music (like EAGAMES\MOHAA\mainta\sound\amb_stereo\Amb_t1l3_BoatDock.mp3)
not in a .pk3 file, any way to make the .mus file run properly with a mp3 file stored in the .pk3?
User avatar
ViPER
General
Posts: 1058
Joined: Fri Jan 14, 2005 5:48 pm
Location: California
Contact:

Post by ViPER »

Why not just place a script origin in the center radius and give it a target name like $centerpoint

Code: Select all

$train bind $centerpoint

$centerpoint speed 5
$centerpoint rotatey 5
Condor
Colour Sergeant
Posts: 82
Joined: Mon Apr 09, 2007 3:19 pm
Location: Bavaria (Germany)

Post by Condor »

Hm....thats good...i'd just would have to place the train in the editor on the rails bevor I bind it. Thank you :)

But if any maths freak is around, id still like to know how to get a sin() or cos() on demand, I also need it for my HUD and innovative, useless other stuff :lol:

Edit: Just tried out with the rotating origing - works smoother, faster, and acceleration is more realistic now :) :)
User avatar
ViPER
General
Posts: 1058
Joined: Fri Jan 14, 2005 5:48 pm
Location: California
Contact:

Post by ViPER »

That's Cool, Simple is usually best. But if for some reason you had to go the difficult route I am sure JV could do it. :D
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

lol, yup :P

These are reasonable approximations for sin(x) and cos(x), note that x should be specified in radians.

x_in_rad = x_in_deg/180*pi

Code: Select all

level.PI = 3.1415926

// sin(x), x in rad
sin local.x:
end (waitthread cos(local.x - 0.5 * level.PI))

// cos(x), x in rad
cos local.x:
	// reduce to [0,2pi]
	if(local.x > 2.0 * level.PI)
	{
		local.x -= (int (local.x / (2.0 * level.PI))) * 2.0 * level.PI
	}
	else if(local.x < 0.0)
	{
		local.x += ((int ( -local.x / (2.0 * level.PI))) + 1) * 2.0 * level.PI
	}	
	
	// reduce to [-pi,pi]
	if(local.x > level.PI)
	{
		local.x -= 2.0 * level.PI
	}
	
	local.x2 = local.x * local.x
	local.x4 = local.x2 * local.x2
	local.x6 = local.x4 * local.x2
	local.x8 = local.x6 * local.x2
	local.x10 = local.x8 * local.x2
	local.cosx = 1.0 - local.x2 / 2.0 + local.x4 / 24.0 - local.x6 / 720.0 + local.x8 / 40320.0 - local.x10 / 3628800.0
	
	if(local.cosx > 1.0)
	{
		local.cosx = 1.0
	}
	else if(local.cosx < -1.0)
	{
		local.cosx = -1.0
	}
end local.cosx
Image
Condor
Colour Sergeant
Posts: 82
Joined: Mon Apr 09, 2007 3:19 pm
Location: Bavaria (Germany)

Post by Condor »

Thanks a lot :D :D I already gave up searching for approximations.... Taylor chain things are so difficult :?

I dont get why they dont provide native trigonometric functions...
Post Reply