Gamestudio Links
Zorro Links
Newest Posts
Zorro version 3.0 prerelease!
by Grant. 02/24/26 22:21
WFO Training with parallel cores Zorro64
by Martin_HH. 02/24/26 19:51
ZorroGPT
by TipmyPip. 02/23/26 21:52
Camera always moves upwards?
by clonman. 02/21/26 09:29
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 02/19/26 13:22
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
0 registered members (), 5,796 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
alx, ApprenticeInMuc, PatrickH90, USER0328, Sfrdragon
19199 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: Torque to Degree of Rotation [Re: A.Russell] #66926
04/02/06 18:30
04/02/06 18:30
Joined: Mar 2003
Posts: 4,427
Japan
A
A.Russell Offline OP
Expert
A.Russell  Offline OP
Expert
A

Joined: Mar 2003
Posts: 4,427
Japan
Hmn, Actually, I think it is working. I had a bodge elsewhere for controling the roll, after taking that out it is much better.

Still wondering, though, in kg*m^2 is "m" the diameter? This was a wild guess. Initially I thought it would be mass, but kg is the same thing, isn't it?

Anyway, I appear to be on the right track, because my entities bounce around okay, though they all finish on funny angles because they think they are spheres.

Re: Torque to Degree of Rotation [Re: A.Russell] #66927
04/03/06 02:33
04/03/06 02:33
Joined: Aug 2002
Posts: 681
Massachusetts, USA
Ichiro Offline
User
Ichiro  Offline
User

Joined: Aug 2002
Posts: 681
Massachusetts, USA
Quote:

Still wondering, though, in kg*m^2 is "m" the diameter? This was a wild guess. Initially I thought it would be mass, but kg is the same thing, isn't it?




That should be (mass) * (distance squared), so you're right -- it's distance. However, that formula is for a point mass that's fixed some distance from its axis of rotation (think of an idealized pendulum, where the mass is not centered at the pivot point). This Wikipedia entry may clear things up. For a sphere you're pushing around its center, the moment of inertia would be (mass)/[(4/3)*pi*(radius)^3] (see the first bit of this link for more).

Quote:

Anyway, I appear to be on the right track, because my entities bounce around okay, though they all finish on funny angles because they think they are spheres.




My gut says that your sphere/point-mass model would be good enough so that you shouldn't notice anything odd. To put it another way, if you simulated the mass collision "perfectly," it'd look about the same to human eyes. So: if it looks wrong to you, you may need to tweak the formula.

I would guess that the calculation is missing a conversion from the incoming object's linear components into angular ones. (You're going from my.velocity, which is linear, to force[3], which is linear, to torque[3], without converting the linear force into an angular one.) However, I may be missing something.


Dejobaan Games - Bringing you quality video games for over 75 years.
Re: Torque to Degree of Rotation [Re: Ichiro] #66928
04/03/06 05:29
04/03/06 05:29
Joined: Mar 2003
Posts: 4,427
Japan
A
A.Russell Offline OP
Expert
A.Russell  Offline OP
Expert
A

Joined: Mar 2003
Posts: 4,427
Japan
Thanks Ichiro,

Yes, the formula only considers collisions with static entities at the moment, so there are no incoming componets. I want make sure I've this working first.

Moment of Inertia is really beating me up. There are about a hundred different formulas for it, all very different, and none of them looks quite right.

I tried yours: moment_of_inertia = my.mass / ((4/3)*pi*pow(diameter,3));
Howver, that gives a huge value, and consequently no noticable angular velocity was added to the object.

I also tried these ones from your links:

Quote:

because of the symmetry of the sphere, each principal moment is the same, so the moment of inertia of the sphere taken about any diameter is I = 2/5mR^2




moment_of_inertia = 2/5 * my.mass * pow(diameter,2));

This gave it too much angular velocity.

Quote:

The moment of inertia of a sphere of uniform density and radius R is
I = (8/15) * pi * density * R^5



moment_of_inertia = (8/15)*pi* (my.mass/((4/3)*pi* pow(radius,3));

Again, it span out of control.


At the moment the only objects collided with are static, like the ground or buildings.

Last edited by A.Russell; 04/03/06 05:36.
Re: Torque to Degree of Rotation [Re: A.Russell] #66929
04/03/06 06:04
04/03/06 06:04
Joined: Mar 2003
Posts: 4,427
Japan
A
A.Russell Offline OP
Expert
A.Russell  Offline OP
Expert
A

Joined: Mar 2003
Posts: 4,427
Japan
Nevermind, I think I've got it:

moment_of_inertia = 2/5 * power(my.mass * radius, 2);

At least it't the best so far.

I found a useful chart of common moments of inertia: http://hyperphysics.phy-astr.gsu.edu/HBASE/mi.html

Thanks for explaining and pointing me in the right direction.

Re: Torque to Degree of Rotation [Re: A.Russell] #66930
04/03/06 06:30
04/03/06 06:30
Joined: Aug 2002
Posts: 681
Massachusetts, USA
Ichiro Offline
User
Ichiro  Offline
User

Joined: Aug 2002
Posts: 681
Massachusetts, USA
I steered you wrong; I'm sorry. What I gave you was the mass density. (I blame my sleep-deprived mind.) The formula for the the moment of inertia of a solid sphere of constant density is, as you mentioned, I=2.0/5.0 * my.mass * pow(diameter,2.0)). This is equivalent to I=(8/15) * pi * density * R^5, but you don't need the latter equation, because you already know the object's mass.

> moment_of_inertia = 2/5 * power(my.mass * radius, 2);

You'll want the mass outside the power() function, or your objects will really fly out of control if their mass is substantially below 1; and they'll become increasingly too resistant to your torque effects if they're above 1. You may not be inclined to believe the babblings of someone who gave you mass density instead of moment of inertia(!), but I believe that if your object is acting strangely despite using I=2.0/5.0 * my.mass * pow(diameter,2.0)), there's a gremlin somewhere else in the algorithm.


Dejobaan Games - Bringing you quality video games for over 75 years.
Re: Torque to Degree of Rotation [Re: Ichiro] #66931
04/03/06 14:24
04/03/06 14:24
Joined: Mar 2003
Posts: 4,427
Japan
A
A.Russell Offline OP
Expert
A.Russell  Offline OP
Expert
A

Joined: Mar 2003
Posts: 4,427
Japan
Hmn, I thought that looked wrong, but it worked at the time.

I am at a loss now. This is the meat of it. Can anyone see what I might be doing wrong?
Code:

//moment of inertria, I = 2/5MR^2
moment_of_inertia = (2/5) * my.mass* pow(radius,2);
.
.
//distance_from_centre, centre of object to point hit
vec_diff(temp, my.x, target);
distance_from_centre = vec_length(temp);
.
.
//Force, velocity * mass
vec_set(temp, my.velocity);
vec_scale(temp, my.mass);
vec_set(force, temp);


//torque = force * distance_from_centre;
vec_set(temp, force);
vec_scale(temp, distance_from_centre);
vec_set(torque,temp);
.
.
//rot_a = torque/moment_of_inertia
if(moment_of_inertia) //don't divide by zero
{
rot_a.pan = torque.pan / moment_of_inertia;
rot_a.tilt = torque.tilt / moment_of_inertia;
rot_a.roll = torque.roll / moment_of_inertia;
}
.
.
//convert from radians to degrees
vec_set(temp,rot_a);
vec_scale(temp, 57.296);
vec_set(angular_momentum_change,temp);
.
.
//angular_momentum_change = your_angular_formula * sin(theta)
//not confident about this at all, though I knkow sin(180-dot_product) was correct for theta in the linear equation
vec_scale(angular_momentum_change, sin(180 - dot_product));
.
.
//Now add that to the ship's angular velocity
ang_add(my.ROT_VELOCITY, angular_momentum_change);
.



Re: Torque to Degree of Rotation [Re: A.Russell] #66932
04/03/06 18:21
04/03/06 18:21
Joined: Aug 2002
Posts: 681
Massachusetts, USA
Ichiro Offline
User
Ichiro  Offline
User

Joined: Aug 2002
Posts: 681
Massachusetts, USA
This provides a pile of info and also has a nice applet:

http://www.myphysicslab.com/collision.html

That's probably more material than you need right now, but it may prove useful when you're adding in the linear effects. Some good Google terms are +elastic +collision +angular +momentum (or +velocity).

I think I'm being more of a detriment to you than a help. Surely there must be a young fellow here who's studying Intro to Classical Mechanics?


Dejobaan Games - Bringing you quality video games for over 75 years.
Re: Torque to Degree of Rotation [Re: Ichiro] #66933
04/03/06 18:58
04/03/06 18:58
Joined: Mar 2003
Posts: 4,427
Japan
A
A.Russell Offline OP
Expert
A.Russell  Offline OP
Expert
A

Joined: Mar 2003
Posts: 4,427
Japan

Actually Ichiro, you have been a big help. This doesn't seem like it should be a big thing, but then perhaps everyone else just uses the physic's engine.

I've done a lot of searches and read a lot of sites today. Your link looks like a good one, as they've got a working example with a detailed explanation.

Re: Torque to Degree of Rotation [Re: A.Russell] #66934
04/08/06 16:56
04/08/06 16:56
Joined: Mar 2003
Posts: 4,427
Japan
A
A.Russell Offline OP
Expert
A.Russell  Offline OP
Expert
A

Joined: Mar 2003
Posts: 4,427
Japan
For anyone who is interested, I think I worked out a solution. Seems to work fairly well. anyway:

Code:

//(moment of inertia) I = kg * m^2
//moment_of_inertia = my.mass * pow(45,2);
//whoops this on is for a point mass
//moment_of_inertia = (2/5) * MR^2;
moment_of_inertia = (2/5) * my.mass* pow(my.diameter/2,2);



//distance_from_centre
vec_diff(distance_from_centre,target,my.x);

//determin which side of the ship that is
vec_rotate(distance_from_centre, my.pan);



//calculate difference in angle
//between direction traveling and direction facing
vec_to_angle(temp2, my.velocity);
vec_diff(temp, temp2, my.pan);




//local veloctiy
local_velocity.x = vec_length(my.velocity);
local_velocity.y = 0;
local_velocity.z = 0;

vec_rotate(local_velocity, temp);



//Force
vec_set(temp, local_velocity);
vec_scale(temp, my.mass);
vec_set(force, temp);



//torque = force * distance_from_centre;

torque.tilt = force.x * distance_from_centre.z
+force.z * distance_from_centre.x;
torque.pan = force.x * distance_from_centre.y
+force.y * distance_from_centre.x;
torque.roll = force.z * distance_from_centre.y
+force.y * distance_from_centre.z;




//rot. a = torque / I, or
//torque = I*(rot. a)

//rot_a = torque/moment_of_inertia

if(moment_of_inertia) //don't divide by zero
{
rot_a.pan = (torque.pan / moment_of_inertia);
rot_a.tilt = (torque.tilt / moment_of_inertia);
rot_a.roll = (torque.roll / moment_of_inertia);
}


//convert from radians to degrees
vec_set(temp,rot_a);
vec_scale(temp, 57.296);
vec_set(angular_momentum_change,temp);



//angular_momentum_change = your_angular_formula * sin(theta)
vec_scale(angular_momentum_change, sin(180 - dot_product));



//phew! Now add that to the ship's angular velocity
ang_add(my.ROT_VELOCITY, angular_momentum_change);





Page 2 of 2 1 2

Moderated by  HeelX, Spirit 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1