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.

Dark GDK / 2d Camera

Author
Message
Greg_C
14
Years of Service
User Offline
Joined: 22nd May 2010
Location:
Posted: 1st Jun 2010 09:51
I was looking at a tutorial in xna on making a 2d camera and I don't really know xna but I was wondering if a camera like that would be possible in dark GDK? I personally don't want a scrolling backdrop I want to be able to move the character around rather than the world move and the character stays.


Here is the link to the xna tut http://www.paradeofrain.com/tutorials/xna-camera-2d/

Could anyone help me get this working or at least send me in the right direction.
haliop
User Banned
Posted: 1st Jun 2010 10:46
you can always make the 2D sprites into a Plain Objects then actually working in 3D
Greg_C
14
Years of Service
User Offline
Joined: 22nd May 2010
Location:
Posted: 1st Jun 2010 10:52
well I am usign a 2d physics engine so thats why I don't want to move all my objects in the world I rather just move my character around on the physics objects.
Is there anyway to that in dark gdk?
How is it going
17
Years of Service
User Offline
Joined: 18th Sep 2007
Location: California
Posted: 1st Jun 2010 18:05
well as far as I know you have to create the illusion of moving a camera. so that would mean drawing the player in the middle of the screen and then moving the world... I don't do much 2d w/ DarkGDK I use SDL instead... so I know thats what I did for SDL... GDK might have a 2d camera function but thats up to you to find it... if there is one...
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 1st Jun 2010 20:34 Edited at: 1st Jun 2010 20:56
You can create your own class or whatever to have your own 2d camera system, i have never done anything 2d to be honest, but i can think of doing it really easily.

take a look at the following example


Something like this.
note that you can use the above example like:


no dbSprite commands at all, it's done by the class, all you do is call Render method, also, to change a sprite's property or something just do, for example : dbSizeSprite ( sprite.GetID ( ), ...whatever.. );

the example is very very simple, you can add ALOT of stuff to it

hope it helps, sorry for the lack of comments, that's my bad habit =(

[EDIT] modified a bit

Greg_C
14
Years of Service
User Offline
Joined: 22nd May 2010
Location:
Posted: 3rd Jun 2010 06:33
hey Hassan,
So I got the camera to work and I just changed a few things around to fit my project but how would I go about zooming in and out with the camera class example that you gave me.
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 4th Jun 2010 01:57
Hey I have the same question. I got the camera to draw all of my objects based off its position but how would you scale it and rotate it and all that good stuff.

Thanks in advanced
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 4th Jun 2010 10:23 Edited at: 4th Jun 2010 10:24
Hmm, you should add a variable to the zoom ammount, and scale the sprites according to it, i have no formula in my mind or something at the moment, i'll look into it and reply back soon (hopefully)

Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 4th Jun 2010 10:52 Edited at: 4th Jun 2010 10:53
Ok i figured out a way, code should be modified to the following:


note that this code might also be full of errors, as i wrote it here, and didnt test it

Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 4th Jun 2010 23:00
Hey Hassan,
Thanks for the response I will try and get this code going in my project and respond back if I have any major problems.
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 7th Jun 2010 07:01 Edited at: 7th Jun 2010 07:02
Okay I am having some problems not with what you gave me but more to do with scaling my animated sprites down. So let me explain what my problem is and hopefully there is another way to do scaling in Dark GDK. Here is a little test that I did to try and understand what is going on.



So here is what happens. First off when I run this code the image gets scaled across the entire size of the image rather than just sizing down the section that I am drawing. Then it hits the update code and quickly gets scaled down correctly without expanding across the entire image size. Now if you comment out the dbSprite() in the while loop you will see that when the image scales it scales across the entire image size rather than it drawing that single frame at the new scale size. So how can I scale an animated sprite without having these issues. I have to be able to update the scale of my animated sprites because of the code examples you gave but I can't because the scaling doesn't work with them.

Also I have tried dbSizeSprite and I just get weird outcomes I have attached the test project so you guys can see what I'm talking about but I would greatly appreciate any help.

Attachments

Login to view attachments
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 7th Jun 2010 08:07
i didn't test out the above code because... I'm too lazy to compile stuff, but I can help you out a lot with a "2d camera"
Check out this code

Basically, the whole concept is a distinction between "world coordinates" and "screen coordinates". When you make a cube, it's center could be at (1,0,3). However, you can't just output a dot at (1,0) or something on the screen; that would just be weird. You have to transform the world coordinates into screen coordinates.

What I wrote in the thread I linked to above is this:
Quote: "1. Take all the units with their world coordinates
2. Translate all those points so that the camera is at 0,0
3. Rotate all those points so that the camera has 0 rotation
4. Divide those units by the scale factor (units per screen width) to get Screen widths, and add half a screen width to that.
5. Multiply that by pixels per screen width, and you have coordinates of any object in world coordinates, on the screen!
Rotation and translation:
x'=cos(-camtheta)*(x-camx)-sin(-camtheta)*(y-camy)
y'=sin(-camtheta)*(x-camx)+cos(-camtheta)*(y-camy)
Throw in unit conversion...
x'=width*((cos(-camtheta)*(x-camx)-sin(-camtheta)*(y-camy))/scale)+0.5*width
y'=width*((sin(-camtheta)*(x-camx)+cos(-camtheta)*(y-camy))/scale)+0.5*height
"

where the camera is at (camx,camy), rotation of camtheta, and the point in question is at (x,y). (camx,camy) and (x,y) are both in world coordinates, and the result - (x',y') is in screen coordinates (so you could say dbDot(x',y'); or something.)
If you don't want rotation, then camtheta=0, so replace cos(-camtheta) with 1, and sin(cametheta) with 0.
Also, "scale" in this code is weird. The larger it gets, the more zoomed out it is, and the closer it gets to zero, the more zoomed in it is. What I've found better is to - instead of dividing by scale, multiply by 10^scale. This way, you can change scale linearly, and scale can be as large or as small as you want without having weird asymptotes (like 1/0 :\)


Is't life, I ask, is't even prudence, to bore thyself and bore thy students?
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 9th Jun 2010 00:06 Edited at: 9th Jun 2010 00:07
Hassan,
So I was testing what you gave and I have ran into some problems. First off in my project I am already scaling some of my objects when I create them. My constructor kind of looks like this:



I have it take a reference to the camera and every time I create a box it adds it to the render list. Now as you can see I have a sprite scale there already and a good majority of my sprites are using this scale in order to scale correctly. Here is my box class and its update with your code. a few things that I had to change to get it to work with a zoom of 0.

Now where I am confused is this line:



I had to add m_SpriteWidth and Height because for some reason when I used dbSpriteWidth and height it was giving me some crazy numbers like in the thousands. So I set it ahead of time. If you could just look through some of the code and maybe see something that I am doing wrong I would greatly appreciate it.





As I said before it works when my zoom amount is just zero but when you start to put in a zoom amount it doesn't work.
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 9th Jun 2010 14:05 Edited at: 9th Jun 2010 14:08
Ohh i see, i totally forgot about the actual sprite's scale

100 is the sprite scale there (100 = normal size)
you can change that 100 to a variable that you can modify, which will be considered as the actual sprite's scale

Login to post a reply

Server time is: 2024-11-19 23:25:35
Your offset time is: 2024-11-19 23:25:35