SFML community forums

Help => Graphics => Topic started by: SuperV1234 on November 27, 2012, 11:08:34 pm

Title: 3D camera library/code available?
Post by: SuperV1234 on November 27, 2012, 11:08:34 pm
Sorry if this has been asked before, but is there a way to create a "3D camera" in SFML?
I want to look at a RenderTexture from a different perspective. And rotate the camera around it, in order to give a pseudo-3D effect to my game.

Is there any user-made code that does this?
Title: Re: 3D camera library/code available?
Post by: eXpl0it3r on November 28, 2012, 12:30:34 am
SFML is a 2D library, thus you won't find any 3D stuff... ;)
If you want 3D then use your own OpenGL code.
Title: Re: 3D camera library/code available?
Post by: masskiller on November 28, 2012, 12:40:33 am
I've heard that you can also use some 3D graphic engines such as irrlicht, I've only used raw OpenGL so far so I can't really say if there are problems or not. Be aware though that as SFML doesn't support 3D you can't use SFML's renderTexture for it, you'll have to implement your own version of renderTexture using OpenGL or use whatever a 3D engine grants for that so that you can take benefit from 3D transforms.
Title: AW: Re: 3D camera library/code available?
Post by: eXpl0it3r on November 28, 2012, 10:58:45 am
Be aware though that as SFML doesn't support 3D you can't use SFML's renderTexture for it, you'll have to implement your own version of renderTexture using OpenGL or use whatever a 3D engine grants for that so that you can take benefit from 3D transforms.
Don't take my word for it, since I've no idea about OpenGL, but you should easily be able to extract the texture from the render texture and call bind() on it to get it working with OpenGL, but maybe I'm mistaken (or one can't call bind() on the const ref texture...). ;)
Title: Re: 3D camera library/code available?
Post by: Nexus on November 28, 2012, 12:56:31 pm
Why a render texture? A texture doesn't have a direct graphical representation, it exists in the video memory. Do you mean you want to view a sprite from a 3D perspective?

What you can do with SFML, is to take a vertex array and to calculate the vertex positions according to the perspective transform.
Title: Re: 3D camera library/code available?
Post by: SuperV1234 on November 28, 2012, 02:22:53 pm
Why a render texture? A texture doesn't have a direct graphical representation, it exists in the video memory. Do you mean you want to view a sprite from a 3D perspective?

What you can do with SFML, is to take a vertex array and to calculate the vertex positions according to the perspective transform.

Yeah sorry, I meant a sprite having a rendertexture as its texture.
The seconds part sounds interesting - is there any article on the subject?
Title: Re: 3D camera library/code available?
Post by: Nexus on November 28, 2012, 02:26:30 pm
You can take a look at the documentation of sf::Vertex and sf::VertexArray.
Title: Re: 3D camera library/code available?
Post by: Acrobat on November 28, 2012, 03:28:45 pm
If you realy want to do this with sfml, there is two ways :
1. rewrite sfml math
2. write your own math, manual calculate screen space coordinates, path them to target draw (i did that, but thats a bad choice)
(not sure about raw openGl, i remember there was some problems with that)

Or you can look at osg or else (there are many choices)
Title: Re: 3D camera library/code available?
Post by: gyscos on November 28, 2012, 03:33:02 pm
Quote
What you can do with SFML, is to take a vertex array and to calculate the vertex positions according to the perspective transform.
As mentioned in other threads, this can be tricky. Trapezoidal transformations on quad do not work as expected ; this is because quads are acutally made of 2 triangles. The result is _not_ what one would expect of a perspective view.

http://en.sfml-dev.org/forums/index.php?topic=9466.msg64262#msg64262
Title: Re: 3D camera library/code available?
Post by: masskiller on November 28, 2012, 03:33:50 pm
Quote
Don't take my word for it, since I've no idea about OpenGL, but you should easily be able to extract the texture from the render texture and call bind() on it to get it working with OpenGL, but maybe I'm mistaken (or one can't call bind() on the const ref texture...).

You can generally do that in OpenGL unless you want to define mipmaps.

What I meant with your own version was precisely that, just use your normal renderTexture, bind it's texture with OpenGL and transform it as you may like according to the type of view system you may be using. You can have class that does all that.

Quote
As mentioned in other threads, this can be tricky. Trapezoidal transformations on quad do not work as expected ; this is because quads are actually made of 2 triangles. The result is _not_ what one would expect of a perspective view.

What you get is that a part of the texture overlaps with the other so it looks like a folded paper rather than an object with perspective. And if you transform it, it just gets weirder.

Title: Re: 3D camera library/code available?
Post by: Nexus on November 28, 2012, 07:22:19 pm
As mentioned in other threads, this can be tricky. Trapezoidal transformations on quad do not work as expected ; this is because quads are acutally made of 2 triangles. The result is _not_ what one would expect of a perspective view.
Indeed, trapezoids (central perspective) won't work. However, parallelograms (parallel perspective) are still possible.