Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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  
  Camera - rubberband effect  (Read 697 times)
0 Members and 1 Guest are viewing this topic.
Offline rmdire

Junior Member





« Posted 2004-10-19 21:21:58 »

Hi All,

Anybody know how to add the Rubberband effect
to a camera.
so that a camera following a moved model will drift to its position behind that model after a short time.


Thanks

Rmdire
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #1 - Posted 2004-10-19 22:30:47 »

A dead easy way to get a smooth drift into position is to get the new position by a weighted avarage of the current position and the target position. Do that every frame with a sufficiently high weight (about 0.98 usually works well) and it'll gently drift into place.

One snag is that this method depends on your framerate. Theres a slightly complex way to make it framerate-independant but I can't remember that off hand (don't usually need it though).

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline rmdire

Junior Member





« Reply #2 - Posted 2004-10-22 12:19:03 »

Hi - I've tried to implement a weighted average on the view - as follows:
<code>

public Vector3f getWeightedDistance(float weighting,Vector3f modelPosition,Vector3f correctDistance,Vector3f cameraPosition)
{
           float xDistance = 0.0f;
           float yDistance = 0.0f;
           float zDistance = 0.0f;
     
           float xWeightedDistance=0.0f;
           float yWeightedDistance=0.0f;
           float zWeightedDistance=0.0f;
           
           
 
        xDistance = modelPosition.x-cameraPosition.x;
        yDistance = modelPosition.y-cameraPosition.y;
        zDistance = modelPosition.z-cameraPosition.z;
 
       if(xDistance>correctDistance.x)
       {
           xWeightedDistance=(correctDistance.x + xDistance)/2*weighting;
       }
       if(yDistance>correctDistance.y)
       {
           yWeightedDistance=(correctDistance.y + yDistance)/2*weighting;
       }
       if(zDistance>correctDistance.z)
       {
           zWeightedDistance=(correctDistance.z + zDistance)/2*weighting;
       }
 
       if(xDistance<correctDistance.x)
           {
             xWeightedDistance=(correctDistance.x + xDistance)/2*1.2f;
           }
           if(yDistance<correctDistance.y)
           {
             yWeightedDistance=(correctDistance.y + yDistance)/2*1.2f;
           }
           if(zDistance<correctDistance.z)
           {
             zWeightedDistance=(correctDistance.z + zDistance)/2*1.2f;
           }
 
     cameraPosition.x+=xWeightedDistance;
       cameraPosition.y+=yWeightedDistance;
       cameraPosition.z+=zWeightedDistance;
       
     
       
       
       
       return cameraPosition;
       }

}



</code>


and then used View.getTransform.lookAt()

as follows

<code>
view.getTransform().lookAt(getWeightedDistance(0.98f,characterControl.getXYZ(),new Vector3f(5.0f,1.0f,5.0f), v), new Vector3f((float)characterControl.getXYZ().x, 1.0f, (float)characterControl.getXYZ().z ),new Vector3f(0, 1, 0));

</code>

this seems to work - but how can I apply this to rotating the camera around the model position?

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

Junior Member





« Reply #3 - Posted 2004-10-22 13:58:43 »


*note* - in reference to above code,

the method  :

characterControl.getXYZ()

returns a vector3f of the model current position.

Thanks for your Help

rmdire
Offline rmdire

Junior Member





« Reply #4 - Posted 2004-10-23 10:38:27 »

I found the following link - which appears to do what I want - in c/c++.

http://www.firestorm.go.ro/Tutorial1.htm

If people want it - after I  convert the code , I'll post a Java version.


Rmdire
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.

pw (22 views)
2014-07-24 01:59:36

Riven (20 views)
2014-07-23 21:16:32

Riven (17 views)
2014-07-23 21:07:15

Riven (20 views)
2014-07-23 20:56:16

ctomni231 (48 views)
2014-07-18 06:55:21

Zero Volt (44 views)
2014-07-17 23:47:54

danieldean (35 views)
2014-07-17 23:41:23

MustardPeter (38 views)
2014-07-16 23:30:00

Cero (53 views)
2014-07-16 00:42:17

Riven (52 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!