Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] quick and EZ 2d camera

Author
Message
Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 1st Jul 2010 06:08
I decided to make a 2d camera that could be used "plug and play", without much if any work to integrate it into your program. Basically, you tell the camera whether to move up and down, or zoom in and out, and it (using eye pleasing velocity/friction/acceleration methods) supplies you with this function:
cs_transformPointToScreen(x as float, y as float)
which returns (in a UDT global vector2 "ret") the new coordinates on the screen

The best thing about this is the self-contained camera code. If you had a tech demo or a little project using cs_transformPointToScreen (I would assume anyone in a serious project would take the time to write their own, better stuff ), you could easily change the transformation code to include translation or other transformations to your heart's content.



Is't life, I ask, is't even prudence, to bore thyself and bore thy students?
swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 8th Jul 2010 01:40
d3d_init, d3d_circle, and log seem to cause errors for me.

swis
Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 14th Jul 2010 00:21
Neuro Fuzzy, That's really neat and efficient, only needs rotation and you've got a perfect 2d camera for quick implementation into any project, not that it isn't great already. I'd love to know where you learn all you math skills, cause though I understand all this, it's knowing what needs to be coded beforehand to achieve this, like that 'SNormInv' function, there's no way in hell I would of thought up that when thinking about how to do this.

swissolo, It requires IanM's Matrix1Utils and Cloggy's D3DFunc plugins to run. Believe me, your going to want these if you want to do anything efficient in DBP.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
GIDustin
15
Years of Service
User Offline
Joined: 30th May 2008
Location:
Posted: 14th Jul 2010 02:05
Overlooked this before. This is really neat! How would go about setting the limits, such as left/right/up/down boundaries as well as zoom in/out boundaries? Would also need a way to be timed in sync with the program, such as passing a TBM variable to the update function.

This could be neat to play with though...

Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 14th Jul 2010 05:18
@ sasuke:
that SNormInv function doesn't do much - its basically to provide the objects a nice spread around the origin. It basically gives a random point, whose probability of being at any one point is the height on this graph:

(my description isn't totally accurate but its good enough )
Basically... its some complex math stuff to find estimates of (it can't be solved for directly) the inverse of the cumulative normal distribution. I don't know the math, and its complicated - I found the math for that function somewhere on the internet, and all it does for me is provide a nice function for getting random points around the origin

I did make a post a while ago that did transformations with rotation and stuff: http://forum.thegamecreators.com/?m=forum_view&t=157447&b=6

Yeah, I've already used this a couple times when I want a nice smooth view of some points or something, but don't want to spend any time messing around with camera code


Is't life, I ask, is't even prudence, to bore thyself and bore thy students?
swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 16th Jul 2010 00:01
@ Sasuke:
I have IanM's Matrix1Utils but I never bothered with Cloggy's D3D functions. I have tended to avoid anything I don't need, keep everything clean , I guess there's a reason now. (I suspected D3D was for Cloggy's D3D functions, but I never bothered to install them.)

swis
sadsack
20
Years of Service
User Offline
Joined: 27th Nov 2003
Location: here
Posted: 16th Jul 2010 00:30
d3d_init, d3d_circle is a bad lines for me, will not compile.
renny

Life is not fair, so deal with it.
http://www.gusroundtable.com/
Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 16th Jul 2010 05:54
Quote: "It requires IanM's Matrix1Utils and Cloggy's D3DFunc plugins to run."


d3d lines and circles are *waaay waaaay* faster than dbpro's built in circle and line commands. I've had things speed up 10x switching over.

Wait... Holy crap... I added "sync on" to the top of the code and chagned sync rate to 0. d3d circle program still running at ~30 fps for me. then I changed this line:
"d3d_circle ret.x,ret.y,cs_linScale(1),0"
to this:
"circle ret.x,ret.y,cs_linScale(1)" (using DBPro built in circles)
and the program ran at like 150 fps.

Has d3d failed me? Regardless, d3d lines are way way faster.


Is't life, I ask, is't even prudence, to bore thyself and bore thy students?
Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 17th Jul 2010 05:50
Very cool, I will definitely keep this in mind for when I need a 2D camera


Guns, cinematics, stealth, items and more!

Login to post a reply

Server time is: 2024-04-19 17:18:43
Your offset time is: 2024-04-19 17:18:43