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 / [GDK] - Panorama / Cylindrical Camera in DarkGDK

Author
Message
The Tall Man
10
Years of Service
User Offline
Joined: 16th Nov 2013
Location: Earth
Posted: 9th Dec 2013 07:33 Edited at: 10th Dec 2013 18:10
The way this works is that several cameras are all in the same position, but rotated horizontally. They are each rendered to a different sprite, which is positioned on a different location on the screen. You could expand this to make a spherical camera if you wanted to (of course that would square the number of cameras you would need for the same quality). One idea would be to use a spherical mesh as a template to compute your rotation angles. You'd have to make sure the images fit properly together.

Screenshot: 360 degrees horizontal, 45 degrees vertical, 32 cameras


The setup function call is in two forms:


As you can see, you can tell it how many cameras you wish it to use. The less you use, the more seams will be visible. All the cameras' images line up perfectly, but because DirectX does perspective rendering, we are having to approximate the cylinder much like as in a mesh. The more cameras you have, the smoother-looking your final output, but it does cost some performance. For example, having 36 cameras cuts my frame-rate down to about a third. You probably will not need that many unless you are doing a full 360 degrees or something like that.

Width and height are those of your output. You can enter in your screen dimensions.

Normally when you call the dbSetCameraFOV() command, it is the field of view of the Y (vertical) axis. Here you can set the field of view for the X and Y axes individually. So if you would like your height to be as though you had called dbSetCameraFOV(45), then set fovY = 45. You can set fovX to anything you would like (well probably 0 would not work ).

Or if you would like to just have a cylindrical camera for your normal scene instead of the flat perspective camera provided by DirectX, you can call the Alt function, with fovY and aspectRatio the same as you would pass to the regular db commands.

Here is the main initialization function:


Here is the Alt function:



And lastly, the Camera Update Function, to be called each frame, or each time the camera is to move:



I actually included these functions in a class, which I removed for this sharing. So the variables that begin with capital letters, treat them here as global variables:

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-03-29 00:49:26
Your offset time is: 2024-03-29 00:49:26