Java Physics - Bumping


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: Java Physics - Bumping

Hybrid View

  1. #1
    Join Date
    Jul 2005
    Posts
    3

    Java Physics - Bumping

    Hello! I'm programming a game, and now i'm in the part that i need to bump my player with the obstacles (the objects).
    I dont really understand how to do it.

    Any help will be appreciated.

    thanks.

  2. #2
    Join Date
    Oct 2004
    Posts
    3
    When I was a student, I used the following for physics routines.

    Docs:
    http://ocw.mit.edu/OcwWeb/Electrical...il/classes.htm
    Source:
    http://ocw.mit.edu/NR/rdonlyres/Elec.../0/physics.zip

    Basically you need to calculate the time from impact from various surfaces and calculate the rebounds from the surface with the smallest 'time until impact'.

    Read through the docs and look at the code and you should be able to figure it out.
    Last edited by themoffster; 07-26-2005 at 02:26 PM.

  3. #3
    Join Date
    Aug 2003
    Posts
    313
    Collisions, most of the time, will be computed using Newtons laws. Mainly conservation of momentum and conservation of kenetic energy (depending on the type of collision). Check out
    http://hyperphysics.phy-astr.gsu.edu/hbase/elacol.html
    For information on inelastic and elastic collisions.

    Hope this helps.
    ~evlich

  4. #4
    Join Date
    Mar 2004
    Posts
    635
    What type of collision are you looking for? (AABB, OBB, full blown polygon collision)
    What type of collision response are you looking for? Simply stop moving, or bounce and richochet off using proper reflections? Or perhaps you want the sliding collision seen in common FPS games like quake, where a player slides down a wall rather than stopping or bouncing off.

  5. #5
    Join Date
    Jul 2005
    Posts
    3
    all what i want is the simpelest collision - an the playe with hit something and then will stop.

  6. #6
    Join Date
    Aug 2003
    Posts
    313
    If its actually the code to detect that a collision occured, then what type of entities are you working with? If they are just rectangles then the algorithm is pretty simple, if the shapes are more complex, of course the algorithm gets a little more difficult.
    ~evlich

  7. #7
    Join Date
    Mar 2004
    Posts
    635
    Probably the simpliest method is using bounding spheres. Let's say each object contains a bounding sphere class.

    Code:
        public class BoundingSphere
        {
            //origin of center of sphere
            private float X;
            private float Y;
            //radius of sphere
            private float radius;
            
            public BoundingSphere(float x, float y, float r)
            {
                this.setPosition(x,y);
                this.setRadius(r);
            }
    
            public void setPosition(float x, float y)
            {
                this.X = x;
                this.Y = y;
            }
            
            public void setRadius(float r)
            {
                this.radius = r;
            }
            
            public float getX()
            {
                return this.X;
            }
            
            public float getY()
            {
                return this.Y;
            }
            
            public float getRadius()
            {
                return this.radius;
            }
            
            public boolean overlaps(BoundingSphere bs)
            {
                float a = this.X - bs.getX();
                float b = this.Y - bs.getY();
                float sqDist = a*a + b*b;
                float sqRange = (this.radius + bs.getRadius())*(this.radius + bs.getRadius());
                
                return (sqDist < sqRange);
            }
        }

    Then use it somewhat like this:

    Code:
        if (ObjectA.overlaps(ObjectB))
        {
            ObjectA.stop();   
        }

  8. #8
    Join Date
    Jul 2005
    Posts
    3
    I'll not have OVALS i'll have images, so i guess it will be squars

Similar Threads

  1. Replies: 2
    Last Post: 06-14-2006, 03:16 PM
  2. Java vs. .Net. A questionnaire
    By Basil in forum .NET
    Replies: 1
    Last Post: 05-13-2005, 06:46 AM
  3. DevX does seem one sideded
    By Rob Abbe in forum Talk to the Editors
    Replies: 44
    Last Post: 01-13-2003, 02:57 PM
  4. learning c# very confusing.
    By Mike Tsakiris in forum .NET
    Replies: 11
    Last Post: 10-04-2002, 05:32 PM
  5. Re: VB vs. Visual Age for Java
    By JJ in forum Enterprise
    Replies: 1
    Last Post: 07-06-2000, 04:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center