Game with dynamically changing terrain

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Game with dynamically changing terrain

Postby zorgblaubaer » Fri Aug 07, 2009 4:00 am

Hey,
i figured i'd better start a new thread than asking my questions all over the forum in old threads.

i am looking into newton game dynamics because i need to write a game (or a basis for a game) in which it is necessary to dynamically change the terrain. there will be a ball rolling over this terrain and thats what the game is about. so when i lift the terrain at one point of the map i want the ball to stay on top of that and eventually roll down. i'm not making this to learn newton. i need that special functionality (i am working at a university and this is part of a microsoft challenge). is it even possible with the engine?
i thought using a heightmap and changing it dynamically would be the best way of doing it but until now it seems that the ball falls through the map as soon as i lift it up. any other ways of doing it? or am i just missing a point? i think it is quite easy if you know how to do it. so please help me, i am kinda lost ;)

edit: the heightmap seems to work now, but its confusing because the texture does not stick to it when i change the elevation values. also sometimes the ball keeps on hopping up and down what looks really silly....
zorgblaubaer
 
Posts: 10
Joined: Thu Aug 06, 2009 2:16 am

Re: Game with dynamically changing terrain

Postby JernejL » Fri Aug 07, 2009 6:19 am

You are changing the heightmap INSTANTLY (think of teleporting floor above a object), not moving the actual bumps in it, i don't think that heightmap currently supports dynamic movement of height points in any physics engine and have bodies on it react as if it actually moved, you would need to use dynamic objects for ground to do such a thing.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Game with dynamically changing terrain

Postby zorgblaubaer » Fri Aug 07, 2009 6:50 am

yeah that sounds reasonable!

but you think the project would be possible with dynamic objects? i will try to figure that out. there is no sdk sample about dynamic objects isnt there?

thanks already!
zorgblaubaer
 
Posts: 10
Joined: Thu Aug 06, 2009 2:16 am

Re: Game with dynamically changing terrain

Postby JernejL » Fri Aug 07, 2009 9:07 am

Maybe a soft mesh / cloth would help you, i believe Julio was working on it for newton 2.0.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Game with dynamically changing terrain

Postby Julio Jerez » Fri Aug 07, 2009 9:52 am

If you are going to move teh terration in real time you will ne to move all of teh bodies in eh area by teh same amont
you can do somthing like this:

Code: Select all
MoveTerrai ()
{
  // collect the bopdies on teh terration before chnegoin tarrain;
   // amek sure you use a filter to skep the terrain nody
   count = NewtonForEachBodiInAABB(bodyArray);

   // set a flag to indicate of the body was hitting the terrain, als also collect teh closest hit point on the terrain
   for (i = 0; i < countInList; i ++) {
           for (NewtonJoint* contact = NewtonBodyGetFirstContactJoint (bodyList[i]); contact; contact =   NewtonBodyGetNextContactJoint (bodyList[i]),  contactJoint) {
                   //the body was hettin teh terrain if oen of eth bodie in teh joint is teh terrain body
                    if (NewtonJointGetBody0 (joint) == TerraionBody || NewtonJointGetBody1 (joint) == TerraionBody ) {
                          FlagBodyNeed TranlsationFlag[i] = 1;
                          NewtonConveCast  (Body, ....
                          HitPosition[i] = BodyGetHitPoistionFormConvexCast
                          break
                    }
           }
     }

    // now muve the terrain points inside the aabbBox 
    ...


    // nwo you ne to set teh matrix of each nod tha wa affected
     for (i = 0; i < countInList; i ++) {
            // there are theee posibility
           // if a body was over terration and was touchiong it

          NewtonConveCast  (Body, ....
          // calculate the new hit position

          BodyGetMatrix (bodyList[i]), matrix)
          // remove all alevation
           matrix.mPosit  -=  updir.Scale (matrix.mPosit.Posit % updir);

          // tranlet to new elevation
          matrix.mPosit += updir.Scale (ParametinCastPoint);

           if (FlagBodyNeed TranlsationFlag[i] = 1) {
                  BodySetMatrix (bodyList[i]), matrix)
           } else {
               // the Body was close to the terrain and the terrain modification touch it
                Collision = NewtonBodyGetCollision (bodyList[i])
             
                // test the collsiion  at the new matrix position
                NetwonCollide (Collision, Terrain Collision, matrix, ...)
 
                if (Ther was a collision) {
                    BodySetMatrix (bodyList[i]), matrix)
              }
           }
     }
}
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Game with dynamically changing terrain

Postby zorgblaubaer » Thu Aug 13, 2009 5:56 am

thanks already for your helps.

i still have questions ;)

@julio: i don't really get what you try to tell me, sorry. I only have one ball, so only one object on the terrain

@delfi: are there any examples on "dynamic obejcts" because i can't find any information on that. but do i get you right, that i need a body which is moving at a given speed so that the ball will be pushed constantly away by the ground?
zorgblaubaer
 
Posts: 10
Joined: Thu Aug 06, 2009 2:16 am

Re: Game with dynamically changing terrain

Postby Julio Jerez » Thu Aug 13, 2009 9:18 am

well I am sorry then,
you will have to find out by someone else then.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Game with dynamically changing terrain

Postby kallaspriit » Thu Aug 13, 2009 6:05 pm

zorgblaubaer, I suggest you read Julio's post again, he gave you some great pointers :wink:
kallaspriit
 
Posts: 216
Joined: Sun Aug 14, 2005 6:31 pm

Re: Game with dynamically changing terrain

Postby zorgblaubaer » Fri Aug 14, 2009 4:31 am

hm yes i think you are right. in fact its exactly what i need when i skip the iteration over every body, for i only have one single body (the ball)

at the moment i am trying to figure out how to translate julios pseudo code into a working code.

maybe someone with more experience could help me?
so when i want to change the terrain i will first test the ball for the smallest distance between terrain and ball, saving the point on the tearrain that is member of this distance.
then i do my terrain change
and now i am extremely puzzled. according to the change of relation between the ball and the terrain i have to move the ball, i think?

thanks already for your help ;)

edit: i understand there a three cases which i have to deal with: first, the ball was on the piece of terrain which i moved (which will be the case always, i think.. thats what the game is about) so i have to move the ball by the same amount.
second the ball was above the terrain and after the change isnt anymore, so i have to higher the ball so that it is lying on the terrain afterwards
third the ball was above the terrain before and after the change. nothing to do

is that right?
zorgblaubaer
 
Posts: 10
Joined: Thu Aug 06, 2009 2:16 am

Re: Game with dynamically changing terrain

Postby zorgblaubaer » Tue Aug 18, 2009 7:57 am

Hey it's me again ;)

this is my last try with Newton. If I won't get it to work, my PhD will write an Engine on his own.
So I will try to explain exactly what I need to to.

I told you already what the game will be about. This is a view of the game just after getting started
Image

This is an example of a terrain which has been changed during run time
Image

And the last picture shows the problem i still have. Whenever I change the terrain during run time (or better: outside of the HeightFieldPrimitive constructor) this happens (when you can't see it that good: the ball will not be on top of the new terrain, it will look like there is "mud" half as high as the ball. This stays the same when the terrain is even higher. The ball will not ball through the terrain but won't correctly accept the new surface)
Image


I will attach the 2 important files of the project. The first is a modified HeightFieldPrimitive which was shipped with the sdk samples. The second is the class that holds the "game".

Your help is highly appreciated

greetings from Germany ;)
Attachments
Archive.zip
(7.36 KiB) Downloaded 136 times
zorgblaubaer
 
Posts: 10
Joined: Thu Aug 06, 2009 2:16 am

Re: Game with dynamically changing terrain

Postby Julio Jerez » Tue Aug 18, 2009 10:52 am

zorgblaubaer wrote:this is my last try with Newton. If I won't get it to work, my PhD will write an Engine on his own.


Well when it gets to the threatening point it usually means the problems are irreconciliable,
I already told you what to do but you do not understand me, so there is nothing I can do about that
Given the circumstance I think the best for you it to write your own or find another solution, physics engines now are a dime a dozen.
Good luck
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Game with dynamically changing terrain

Postby JernejL » Tue Aug 18, 2009 1:17 pm

zorgblaubaer: I'm affraid you do not understand that this is not a newton problem, this is how the heightmap works - it is not intended to be used to raise surface - only lower it, as in that case the heightmap will always move away from bodies and not into them. When you change it - it changes instantly, it's like teleporting one static body into another, dynamic one, if you want to do this without the glitch you need to handle moving the affected bodies properly yourself, or as you mentioned - write your own physics engine, but please understand that this is not a bug, heightmap modifications to my knowledge works this way in all physics engines.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Game with dynamically changing terrain

Postby zorgblaubaer » Tue Aug 18, 2009 6:37 pm

just to clarify things, i did by no means try to threat anyone or anything like that. i am thankfull people give their software away for free and than even give support for that!

and about the glitch: i am totally aware of the instant-rising-terrain-into-ball problem. but that is not what the screenshots show. i can see that i didnt tell that in my post but what i did was highering the terrain when the ball was not even near the node i highered. after that i roll the ball to that position and it will sink into the surface a little (as in the picture).
and that was the problem i was talking about, it was not about highering the terrain with the ball on it...
zorgblaubaer
 
Posts: 10
Joined: Thu Aug 06, 2009 2:16 am

Re: Game with dynamically changing terrain

Postby kallaspriit » Wed Aug 19, 2009 4:09 am

Cant see the debug lines on the modified terrain, are you sure NGD representation of the changed world is the same as your graphics?
kallaspriit
 
Posts: 216
Joined: Sun Aug 14, 2005 6:31 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron