Scaling the space of the spatial joint

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Scaling the space of the spatial joint

Postby agi_shi » Mon Jul 06, 2009 10:08 am

Hi. Julio, I'm not sure if you remember, but previously you helped me with a wonderful "spatially connected" joint. As a result, this was possible:


However, now I have a new request: is it possible to scale the space of the connected body?

For example, you've connected body A and body B with the spatial joint. Is it possible that for every 2m body A moves, body B moves only 1m? In this case, the "spatial scale" would be 2:1 for A:B (thus, body B would be in a 2x smaller world than body A). Do you understand what I'm trying to get at?

Many thanks!
Last edited by agi_shi on Sun Aug 23, 2009 7:09 pm, edited 1 time in total.
agi_shi
 
Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

Re: Scaling the space of the spatial joint

Postby Julio Jerez » Mon Jul 06, 2009 3:30 pm

agi_shi wrote:However, now I have a new request: is it possible to scale the space of the connected body?

For example, you've connected body A and body B with the spatial joint. Is it possible that for every 2m body A moves, body B moves only 1m? In this case, the "spatial scale" would be 2:1 for A:B (thus, body B would be in a 2x smaller world than body A). Do you understand what I'm trying to get at?


Absolutlly!
I am getting déjà vu because I think we did that before.
It is actually quite simple, is that the code for the joint?
I will post the change is pseudo code later.

BTW is is quite nice to see hwo you use such simple joint to make such incredible visual effects in your game. :mrgreen:
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Scaling the space of the spatial joint

Postby agi_shi » Mon Jul 06, 2009 4:04 pm

Julio Jerez wrote:
agi_shi wrote:However, now I have a new request: is it possible to scale the space of the connected body?

For example, you've connected body A and body B with the spatial joint. Is it possible that for every 2m body A moves, body B moves only 1m? In this case, the "spatial scale" would be 2:1 for A:B (thus, body B would be in a 2x smaller world than body A). Do you understand what I'm trying to get at?


Absolutlly!
I am getting déjà vu because I think we did that before.
It is actually quite simple, is that the code for the joint?
I will post the change is pseudo code later.

Indeed I believe we did this before, but with the update of the forums and everything I cannot quite find the old topic :| Take your time, the help is much appreciated :mrgreen:

BTW is is quite nice to see hwo you use such simple joint to make such incredible visual effects in your game. :mrgreen:

Yup, thanks :D Newton all the way :mrgreen:
agi_shi
 
Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

Re: Scaling the space of the spatial joint

Postby Julio Jerez » Tue Jul 07, 2009 2:53 pm

Ok I think this is what you need to do.

Code: Select all
class portalJoint
{
                    ...
                    ...
   float m_ScaleFactor;

   void SetSetScaleFactor;
};



    void portalJoint::SubminUserRow (const dVector& dir0_, const dVector& dir1_, dFloat timestep) const
    {
        dFloat time;
        dFloat relAccel;
        dVector veloc0;
        dVector veloc1;
        dFloat jacobian0[6];
        dFloat jacobian1[6];

        const dVector dir0 = dir0_;
        jacobian0[0] = dir0.m_x;
        jacobian0[1] = dir0.m_y;
        jacobian0[2] = dir0.m_z;
        jacobian0[3] = 0;
        jacobian0[4] = 0;
        jacobian0[5] = 0;

        dVector dir1 (dir1_.Scale (-1.0f));
        jacobian1[0] = dir1.m_x;
        jacobian1[1] = dir1.m_y;
        jacobian1[2] = dir1.m_z;
        jacobian1[3] = 0;
        jacobian1[4] = 0;
        jacobian1[5] = 0;

        // add a angular constraint
        NewtonUserJointAddGeneralRow (m_joint, jacobian0, jacobian1);


        time = timestep;
        NewtonBodyGetVelocity(m_body0, &veloc0[0]);
        NewtonBodyGetVelocity(m_body1, &veloc1[0]);

       // this moves the two bodies at a different Scales in the different spaces.
      // for example if the space one is twice as big the m_ScaleFactor should be 0.5
       // that way when Body in space zero goes at 1 m/s, body in space 1 most be moving at 2 m/s do that the relative velocity is zero
        relAccel = -1.0 * (veloc0 % dir0 + (veloc1 % dir1) * m_ScaleFactor) / time;

        // set the desired angular acceleration between the two bodies
        NewtonUserJointSetRowAcceleration (m_joint, relAccel);



        jacobian0[0] = 0;
        jacobian0[1] = 0;
        jacobian0[2] = 0;
        jacobian0[3] = dir0.m_x;
        jacobian0[4] = dir0.m_y;
        jacobian0[5] = dir0.m_z;
        jacobian1[0] = 0;
        jacobian1[1] = 0;
        jacobian1[2] = 0;
        jacobian1[3] = dir1.m_x;
        jacobian1[4] = dir1.m_y;
        jacobian1[5] = dir1.m_z;

        // add a angular constraint
        NewtonUserJointAddGeneralRow (m_joint, jacobian0, jacobian1);

        NewtonBodyGetOmega(m_body0, &veloc0[0]);
        NewtonBodyGetOmega(m_body1, &veloc1[0]);
        relAccel = -1.0 * (veloc0 % dir0 + veloc1 % dir1) / time;

        // set the desired angular acceleration between the two bodies
        NewtonUserJointSetRowAcceleration (m_joint, relAccel);
    }

    void portalJoint::SubmitConstrainst(dFloat timestep, int threadIndex)
    {
        dMatrix matrix0;
        dMatrix matrix1;

        dMatrix bodyMatrix0;
        dMatrix bodyMatrix1;
        NewtonBodyGetMatrix(m_body0, &bodyMatrix0[0][0]);
        NewtonBodyGetMatrix(m_body1, &bodyMatrix1[0][0]);

        SubminUserRow (bodyMatrix0.m_front, bodyMatrix1.m_front, timestep);
        SubminUserRow (bodyMatrix0.m_up,   bodyMatrix1.m_up, timestep);
        SubminUserRow (bodyMatrix0.m_right, bodyMatrix1.m_right, timestep);
    }


Hey you should call that joint Entanglement
Look it up on the internet to see what I mean. :wink:
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Scaling the space of the spatial joint

Postby agi_shi » Thu Jul 09, 2009 11:38 am

Yup, seems to be exactly what I need :mrgreen: Thanks!

Image

Now, since I do not quite understand the maths behind all of this (I just finished my first year of high school, and the math we learn here * :| ), I have a question: what happens to the mass of the connected objects? I've noticed that the "primary" object seems to get more massive - it's harder to push around with other objects, etc (the body's mass matrix remains the same, it just "feels" more massive). Yet, the "secondary" object doesn't seem to get more massive. What should I do to make the two objects behave the same (essentially, as if they were the same object)?
agi_shi
 
Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

Re: Scaling the space of the spatial joint

Postby Julio Jerez » Thu Jul 09, 2009 3:22 pm

agi_shi wrote:I have a question: what happens to the mass of the connected objects? I've noticed that the "primary" object seems to get more massive - it's harder to push around with other objects, etc (the body's mass matrix remains the same, it just "feels" more massive). Yet, the "secondary" object doesn't seem to get more massive. What should I do to make the two objects behave the same (essentially, as if they were the same object)?


Isn’t that great? I love when the simple simulation reduce an effect that is exactly like the presentation of the Law of physic.
The body should feel heavier in a space that is more compressed, if the laws of physic on that space are the same as the one in the space that the body came from.
If you ask me I will show the effect and be proud of the fact that when the space is compressed the Body feel heavier, trust me this is very, very good.

Now since this is a video game and you want the behaviors to be similar in both spaces, then you must change the physic property of the Space, or of the Body.

You can establish simple relations like the equality of potential energy most maintained in both spaces.
That is the potential energy on a body in one space in the same is the potential as the potencial energy of the same body in the second space.

P = M * G * H

Threfore in each space this realtion must be satisfied.

M1 * G1 * H1 = M2 * G2 * H2

You know that distances in space1 are scaled in space2

H1 = S * H2

You can substitute that equation into the energy equation.

M1 * G1 * S * H2 = M2 * G2 * H2

M1 * G1 * S = M2 * G2

Now you must select what property you want to change, the property of space that is change Gravity, or the Physics of the body wjhich is chance the Mass.
I do no think changing the mass is a good idea because that goes against so many laws of physics that I would even try.
I would go for the Gravity,
So you set M1 = M2

M1 * G1 * S = M1 * G2

which lead to:

G1 * S = G2

So the gravity in the secund space must be scaled by the space factor.
This solution I like because it seems to obey the laws of physic

To test it, let us say that a box in one space at some high, the time the box will take to reach the floor will be

h1 = ½ * g 1/ t1^2
t1 = sqrt (2 * h1 / g1)

if the box materialize in a secund space where the distances are scaled by say a facto S, the time the box takes to reach the floor must still be the same that it takes to reacj teh floor in teh first space.
( This is a newtonian world Space-time has nothing to do with this, do not get any ideas)

So in the secund space

t2 = sqrt (2 * h2 / g2)

But
h2 = s * h1
g2 = s * g1

So we get

t2 = sqrt (2 * s * h1 / s * g1) = sqrt (2 * h1 / g1) = t1

And what do you know they take the same amound of time to reach the floor
Had you selected the mass and the body will take different time to reach the floor which is wrong.

I guess that the solution is to have the Space scale factor as part of the force call back.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Scaling the space of the spatial joint

Postby agi_shi » Thu Jul 09, 2009 4:12 pm

Julio Jerez wrote:
agi_shi wrote:I have a question: what happens to the mass of the connected objects? I've noticed that the "primary" object seems to get more massive - it's harder to push around with other objects, etc (the body's mass matrix remains the same, it just "feels" more massive). Yet, the "secondary" object doesn't seem to get more massive. What should I do to make the two objects behave the same (essentially, as if they were the same object)?


Isn’t that great? I love when the simple simulation reduce an effect that is exactly like the presentation of the Law of physic.
The body should feel heavier in a space that is more compressed, if the laws of physic on that space are the same as the one in the space that the body came from.
If you ask me I will show the effect and be proud of the fact that when the space is compressed the Body feel heavier, trust me this is very, very good.

I see. However, I'm talking about the joint in particular when the spaces are not scaled relative to one another (m_Scale = 1).

The primary body seems to be more massive (harder to push around and stuff) than the secondary body. See this video at about 1:00:

Notice how the primary body seems to drag in a much heavier fashion than the secondary body.

Is this expected?
agi_shi
 
Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

Re: Scaling the space of the spatial joint

Postby Julio Jerez » Thu Jul 09, 2009 4:27 pm

like I said the you nee to kepp track ha teh space and store the Scale fo rteh Gravoty an doteh forces.

you save the Scale bodie with you object, for example

Code: Select all
void forceCallback (body)
{
  Object* NetwonBodyGetUserData(body)
 
  Space * spaca =  Object->GetSpaceInfoI()

  force = Ma * Gravity * SpaceScale;
}


when you create the portal you save teh Scale of the secund Space with the portal, and each time a body pass thrugh the portal to thr secund space you save the Scale of that space with the body,

for example say in the scale the scale is one,
when the body goes to a space that is 0.5 then then efectuve gravityt will be 0.5 * g which means it will feel lighter by the correct amount,
Friction will be lighter, and the body will drag in the same way as if it was on the first space.

Hey you can even cascade Portals, like a body going thruoght one portal and passing to another portal inside that one, I beleive it shoud work fine, but I am getting ahead of myself here.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Scaling the space of the spatial joint

Postby Julio Jerez » Thu Jul 09, 2009 4:39 pm

Oh I see what you say.
If I understand the video, you have on space and you put two radios,
the you put a portal that connect the two different around of the same space.
Now the port have the effect that it affect the scale if the body going thought the portal but it say nothing to the bodies that are already in each side of the spaces.
Is that right?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Scaling the space of the spatial joint

Postby agi_shi » Thu Jul 09, 2009 4:53 pm

Julio Jerez wrote:Oh I see what you say.
If I understand the video, you have on space and you put two radios,
the you put a portal that connect the two different around of the same space.
Now the port have the effect that it affect the scale if the body going thought the portal but it say nothing to the bodies that are already in each side of the spaces.
Is that right?

If I understand you right, then right. In that video, there is no scaling going on (so, basically, even the old non-scaling version of this joint can be used). The secondary body seems much lighter than the primary body (look at the video at around 55 seconds and on - the primary body seems heavier when dragging around).
agi_shi
 
Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

Re: Scaling the space of the spatial joint

Postby Julio Jerez » Thu Jul 09, 2009 5:02 pm

I am confused, you say the scale is one in both sides.

what is the function of the white Box that looks like a radio, in forn of the green Box?
Is the gree box pushong teh white box?
Does it feel ok if the white Boz was not in the scene?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Scaling the space of the spatial joint

Postby agi_shi » Thu Jul 09, 2009 5:14 pm

Julio Jerez wrote:I am confused, you say the scale is one in both sides.

what is the function of the white Box that looks like a radio, in forn of the green Box?
Is the gree box pushong teh white box?
Does it feel ok if the white Boz was not in the scene?

The white box/radio is just there to show that there is nothing invisible behind the portal when the object goes through (in Valve's Portal, you can collide with stuff behind the portal, it's only visually clipped).

Here is a quick video I recorded to show this problem: http://www.MegaShare.com/1212173

Both portals have the same scale, so there is no scaling going on (m_Scale = 1).

Notice that dragging one end of the object (the "secondary" body) is much more responsive than dragging the other end of the object (the "primary" body). It seems like the primary body has more mass - it also behaves like this when other objects push it around, as if it has more mass.
agi_shi
 
Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

Re: Scaling the space of the spatial joint

Postby Julio Jerez » Thu Jul 09, 2009 5:36 pm

I check tonight, I can no download stuff form some site here, the filter do not let me.

Is this a new problems or something was there for some time?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Scaling the space of the spatial joint

Postby agi_shi » Thu Jul 09, 2009 5:37 pm

Julio Jerez wrote:I check tonight, I can no download stuff form some site here, the filter do not let me.

Cool, no problem :mrgreen:
agi_shi
 
Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

Re: Scaling the space of the spatial joint

Postby agi_shi » Sun Aug 23, 2009 7:41 pm

This is still an issue. I've PM'd you a demo you can try out to see the issue first-hand.
agi_shi
 
Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 6 guests