Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: 3D camera library/code available?  (Read 7518 times)

0 Members and 1 Guest are viewing this topic.

SuperV1234

  • SFML Team
  • Full Member
  • *****
  • Posts: 190
    • View Profile
3D camera library/code available?
« 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: 3D camera library/code available?
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: 3D camera library/code available?
« Reply #2 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.
« Last Edit: November 28, 2012, 12:44:28 am by masskiller »
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: Re: 3D camera library/code available?
« Reply #3 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...). ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: 3D camera library/code available?
« Reply #4 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

SuperV1234

  • SFML Team
  • Full Member
  • *****
  • Posts: 190
    • View Profile
Re: 3D camera library/code available?
« Reply #5 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?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: 3D camera library/code available?
« Reply #6 on: November 28, 2012, 02:26:30 pm »
You can take a look at the documentation of sf::Vertex and sf::VertexArray.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Acrobat

  • Full Member
  • ***
  • Posts: 153
    • View Profile
Re: 3D camera library/code available?
« Reply #7 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)

gyscos

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
Re: 3D camera library/code available?
« Reply #8 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
« Last Edit: November 28, 2012, 03:38:54 pm by gyscos »

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: 3D camera library/code available?
« Reply #9 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.

« Last Edit: November 28, 2012, 03:38:04 pm by masskiller »
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: 3D camera library/code available?
« Reply #10 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: