Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1028082 Posts in 41266 Topics- by 32884 Members - Latest Member: schwa

July 30, 2014, 05:08:17 AM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Pendulum with 1 division per cycle alone.
Pages: [1]
Print
Author Topic: Pendulum with 1 division per cycle alone.  (Read 295 times)
PypeBros
Level 0
**


Simplest, but not Simpler


View Profile WWW
« on: April 10, 2013, 12:08:24 AM »

I just finished my pendulum-like movement implementation for my platform game. It's not 100% identical to a physics course pendulum, but I love how it can switch between "free-gravity" and "on string" depending on the presence of external forces.



The full story is here. The code is free of sin, cos or sqrt. Essentially, it's like
Code:
// apply gravity
(vx,vy)=(vx,vy)+g;

// dx,dy is the bob-pivot distance
if (dx*dx+dy*dy<R) return;
if (dx>dy) (cx,cy)=(16,16*dy/dx);
else (cx,cy)=(16*dx/dy,16);

fixes=0;
while (dx*dx+dy*dy>R) {
  (vx,vy)-=(cx,cy);
  (dx,dy)-=(cx,cy);
  if (++fixes==4) break;
}
// use vx,vy to update bob coordinates


Have you ever integrated something alike in your game, or read tutorials on alternatives? I'm curious to know fellow game developers feeling about it.
Logged

JakobProgsch
Level 1
*



View Profile Email
« Reply #1 on: April 10, 2013, 01:00:43 AM »

This is pretty much equivalent to doing verlet integration and enforcing a single distance constraint (http://progsch.net/applets/Physics). With the difference that you do the constraint enforcing part iteratively instead of "normalizing" the distance.
Logged

PypeBros
Level 0
**


Simplest, but not Simpler


View Profile WWW
« Reply #2 on: April 10, 2013, 02:40:03 AM »

I'll dig velvet integration this week-end. Thanks.

and indeed, I could have used "(sqrt(delta)/sqrt(R))-1" instead of "16" and I'd have required no iterative process, but given that the NDS hardware has no direct division support, I opted for iteration instead.
Logged

Polly
Level 4
****


View Profile
« Reply #3 on: April 10, 2013, 03:13:50 AM »

Have you ever integrated something alike in your game, or read tutorials on alternatives? I'm curious to know fellow game developers feeling about it.

Look-up table(s). Can't beat them in terms of performance.
Logged
JakobProgsch
Level 1
*



View Profile Email
« Reply #4 on: April 10, 2013, 08:00:42 AM »

Sure you can, in fact on a lot of modern hardware memory is ultra slow if you can't guarantee your data stays in cache.
Logged

PypeBros
Level 0
**


Simplest, but not Simpler


View Profile WWW
« Reply #5 on: April 10, 2013, 08:07:29 AM »

Look-up table(s). Can't beat them in terms of performance.
Given memory latency and small cache in my case, I wouldn't go for a look-up table here. But it's very likely how they handled it in Sonic the Hedgehog for Boss #1's giant ball, as the cpu:bus cycle ratio was much closer to 1:1 by then.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic