Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Create smooth curve with interpolation (Vecmath) ?  (Read 1068 times)
0 Members and 1 Guest are viewing this topic.
Offline Bombadil

Senior Devvie





« Posted 2004-11-10 17:29:29 »

I use the Vecmath method: Tuple3d.interpolate(Tuple3d t1, Tuple3d t2, double alpha)
.. to interpolate between some tuples. It's a linear interpolation.
What I'd like to have however is some kind of curve interpolation, like Sinus/Cosinus, Bezier, etc.

How to achieve this, please?

For example, this little table contains a value followed by the time key. Ignoring the Z axis:

# x-axis: value, time
1  0
2  1
3  3
6  6
8 10
9 11

# y-axis: value, time
1  0
4  1
5  3
1  6
3 10
2 11  

The result should look like this (it's a Lightwave animation curve) :


PS: Maybe Java3d's behaviour does do this, I don't know... however I'm not using Java3d, just Jogl plus Vecmath (the free Japanese version).
Offline Bombadil

Senior Devvie





« Reply #1 - Posted 2004-11-11 04:18:49 »

There's even one more value per time key: rotation. So it's actually:
<Time key>, <xyz-position>, <xyz-rotation>

All of them I'd like to interpolate so that I can move smoothly with small time steps.

I'm also scanning some math and 3d graphics sites for such thing (which is quite common in 3d I guess) but I asked here because maybe there's some direct way to use Vecmath or some other Java libs (Java2d?).
Offline Trond_A

Senior Newbie




Java games rock!


« Reply #2 - Posted 2004-11-11 11:00:45 »

To draw a (cubic) bezier curve you'll need at least four control points, since each section will make use of four of them to approximate the curve. (EDIT: bad sentence)

In the following code, we're inside a loop calculating each curvepoint based on the controlpoints. First controlpoint is p_start, and the last is p_start+3. The variable l_t is the interpolator from the bezier curve section start and the bezier curve section end. The interpolator must be increased by the delta distance per curvesegment, which will be 1/sectionsegments.

The next bezier section (not to be confused with a curve-section here) will start at p_start+3 and end at p_start+6, four points. (EDIT: I wrote +7...)

To understand the bezier equation completely, you should make a google search on it.

1  
2  
3  
4  
5  
6  
7  
8  
m_curvepoints[l_curpoint].x = (int)(m_controlpoints[p_start+0].x*(1-l_t)*(1-l_t)*(1-l_t)
                                    + m_controlpoints[p_start+1].x*3.0*l_t*(1-l_t)*(1-l_t)
                                    + m_controlpoints[p_start+2].x*3.0*l_t*l_t*(1-l_t)
                                    + m_controlpoints[p_start+3].x*l_t*l_t*l_t);
                        m_curvepoints[l_curpoint].y = (int)(m_controlpoints[p_start+0].y*(1-l_t)*(1-l_t)*(1-l_t)
                                    + m_controlpoints[p_start+1].y*3.0*l_t*(1-l_t)*(1-l_t)
                                    + m_controlpoints[p_start+2].y*3.0*l_t*l_t*(1-l_t)
                                    + m_controlpoints[p_start+3].y*l_t*l_t*l_t);


If this doesn't help, or doesn't make any sense, I can upload the entire source so you can read through it yourself Smiley

Was this even close to what you were thinking of?

-Trond
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Bombadil

Senior Devvie





« Reply #3 - Posted 2004-11-11 13:00:09 »

Quote
Was this even close to what you were thinking of?

Yes, thanks, this is a good start.
On the Bezier topic I found http://mathworld.wolfram.com/BezierCurve.html which I'll have to read (plus some of its links like NURBS curve etc).

Skol. ;-)
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (23 views)
2014-12-14 19:50:38

BurntPizza (49 views)
2014-12-09 22:41:13

BurntPizza (83 views)
2014-12-08 04:46:31

JscottyBieshaar (44 views)
2014-12-05 12:39:02

SHC (58 views)
2014-12-03 16:27:13

CopyableCougar4 (56 views)
2014-11-29 21:32:03

toopeicgaming1999 (122 views)
2014-11-26 15:22:04

toopeicgaming1999 (112 views)
2014-11-26 15:20:36

toopeicgaming1999 (32 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!