GPWiki.org
GPWiki.org
It is currently Sun May 19, 2013 1:16 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Fri Jan 21, 2011 8:08 am 
Harmlessness does no harm
User avatar

Joined: Tue Sep 14, 2004 8:37 pm
Posts: 3804
Location: Ferriday, LA, US
I need some info on drawing 2D sprites in a pseudo-3D perspective (similar to billboards).

The API I am using (HTML5 Canvas) is capable of scaling images. Scale is 1.0 for normal size, 0.5 for half size, 2.0 for double size, and so on. I need some help on getting object farther away from the "camera" to be smaller (and scroll more slowly) than objects that are closer. Assume that the horizon is on the center of the screen (in this case, the center value would be 240).

As always, my arsenal of mathematical awesomeness consists of a rusty BB pellet, and a sling shot with a bent prong. Any and all help is appreciated!

_________________
What most people don't understand about "enlightenment" is that it is not an end-goal; but where you find yourself just before taking a new "first step."


Top
 Profile  
 
PostPosted: Fri Jan 21, 2011 12:23 pm 
Corpse Bride
User avatar

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2216
Location: England
You'll need to define one distance as being normal distance. (eg distance dn=100) and have other distances relative to that. So a distance of d=50 would be twice as close, and a distance of d=200 would be twice as far. Everything is inversely proportional to distance away. The magic scaling figure is msf = (dn / d).

-- If the height (or width) of an object at normal distance (d=dn) is L, then at other distances it is L*msf

-- If the parallax drift velocity for things at normal distance (d=dn) is V, then at other distances it is V*msf

-- Where a sprite is drawn will depend on where the vanishing point of the scene is. So if the position of a sprite is (X,Y) at normal distance, then at other distances it is: (X*msf + FX*(1-msf) , Y*msf + FY*(1-msf) ) where (FX,FY) is the screen coordinates of the vanishing point.

_________________
I ain't pushing no moon buttons.


Top
 Profile  
 
PostPosted: Mon Jan 24, 2011 10:26 am 
Harmlessness does no harm
User avatar

Joined: Tue Sep 14, 2004 8:37 pm
Posts: 3804
Location: Ferriday, LA, US
Hey Jasmine, thanks for that. Finally got around to trying it out last night, and got it going. Woot! :)

_________________
What most people don't understand about "enlightenment" is that it is not an end-goal; but where you find yourself just before taking a new "first step."


Top
 Profile  
 
PostPosted: Fri Feb 04, 2011 11:58 am 
Harmlessness does no harm
User avatar

Joined: Tue Sep 14, 2004 8:37 pm
Posts: 3804
Location: Ferriday, LA, US
Just thought I'd give you a little update:

I applied the technique I learned here to points in space, rather than sprites. With the line-drawing functions in Canvas, it's now pretty easy to get a very simple 3D game running. It took me maybe 20 minutes to get a spinning cube working, and it's running pretty smoothly. :)

(Well, technically a spinning rectangle, but whatever. :P)

_________________
What most people don't understand about "enlightenment" is that it is not an end-goal; but where you find yourself just before taking a new "first step."


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group