It is currently Thu Jun 20, 2013 4:51 am

 All times are UTC

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Object placement in 3D perspectivePosted: Fri Jan 21, 2011 8:08 am
 Harmlessness does no harm

Joined: Tue Sep 14, 2004 8:37 pm
Posts: 3858
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

 Post subject: Re: Object placement in 3D perspectivePosted: Fri Jan 21, 2011 12:23 pm
 Corpse Bride

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2217
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

 Post subject: Re: Object placement in 3D perspectivePosted: Mon Jan 24, 2011 10:26 am
 Harmlessness does no harm

Joined: Tue Sep 14, 2004 8:37 pm
Posts: 3858
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

 Post subject: Re: Object placement in 3D perspectivePosted: Fri Feb 04, 2011 11:58 am
 Harmlessness does no harm

Joined: Tue Sep 14, 2004 8:37 pm
Posts: 3858
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. )

_________________
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

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 4 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: Google [Bot] and 1 guest

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

Search for:
 Jump to:  Select a forum ------------------ Forums    Forum Rules and Posting Guidelines Wiki Discussion    Help    Content Issues Game Programming Discussion    C and C++ Game Programming    Java Game Programming    Language Agnostic Programming    .NET Game Programming    VB Game Programming    Mobile Game Programming    Web-Based Game Programming    Other Languages    OpenGL Development    Direct X Development Game Development Discussion    Game Design    Game Media Off-Topic Discussion    Announcements    Off-Topic    Community Projects    News