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

Author Topic: Help creating custom shape  (Read 2342 times)

0 Members and 2 Guests are viewing this topic.

legacyblade

  • Newbie
  • *
  • Posts: 25
    • View Profile
Help creating custom shape
« on: March 25, 2014, 11:54:56 pm »
Hello everyone! I'm currently writing a 2D skeletal animation system. Basically, it just skews and rotates quads to simulate perspective. After getting everything in place and mostly functional, I decided to rewrite the class that handles skewing and rotating quads to allow skewing by section. I started with the convex shape class, since it allows me to have any number of points, but it won't stretch or squash the texture to conform to the shape of the polygon, so it won't work for me.

Since I can't access the texCoords of individual vertecies from the convex shape class, I had to write my own class based on the shape class. I'm not getting any errors, but when I render it, there's just a few white dots on screen. I'm not sure why this is.

My code for the my custom shape class (currently named "sf_sectionedSkewable". Any class that I have inherit from SFML, I put in the sf namespace) is as follows:

sectioned_skewable.h
sectioned_skewable.cpp

main.cpp

I'm pretty sure my error lies in the update function of my sectioned_skewable class.

        void SectionedSkewable::update()
        {
           for (unsigned int i = 0; i < m_vertices.getVertexCount(); ++i) {
                        m_vertices[i].position = getPoint(i);
                        m_vertices[i].texCoords = getTextureCoord(i);
                }
        }
 

I've used the debugger to check to make sure each vertex in m_vertices (and their texCoords) were set to what I wanted. So I've no idea why it's just a few white dots. I've been working on this all week, and nothing seems to help. So any advice you can give would be great! I wish the convexShape class just had a setTextureCoord method :P That would have simplified things quite a bit. But I doubt that'd be useful in a lot of situations, so I see why it's not a thing.

-edit I've trimmed down the code to make it a minimal and complete example. It's missing the whole point of the class (the skewing of individual sections), but the error is being reproduced with a lot less code.
« Last Edit: March 26, 2014, 03:27:52 pm by legacyblade »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Help creating custom shape
« Reply #1 on: March 26, 2014, 12:07:52 am »
Can you show a minimal and complete example (please read the link carefully)? But be aware that skewing won't work without perspective correction (i.e. direct OpenGL).

And you shouldn't put your own classes in namespace sf, even if you inherit SFML classes.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

legacyblade

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Help creating custom shape
« Reply #2 on: March 26, 2014, 12:46:51 am »
@Nexus, alright. I took it out of the sf namespace. I also edited the pastbin links with a minimal complete example. It's a small as I can get it while still reproducing the issue.

And I've become very aware of that issue. You can get around it by having only skewing a little bit and adjusting the scale of the object. But (for future reference) is there any way to add perspective correction without delving into openGL and losing the convenience of SFML (I'd rather not have to implement my own version of view, among other things)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Help creating custom shape
« Reply #3 on: March 26, 2014, 07:36:05 am »
Quote
is there any way to add perspective correction without delving into openGL and losing the convenience of SFML
Nop, sorry.
Laurent Gomila - SFML developer

legacyblade

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Help creating custom shape
« Reply #4 on: March 26, 2014, 03:29:34 pm »
@Laurent, alright, that's not too big a deal as you can keep things looking decent if you do it right.


I edited the first post again. I think my issue lies in my update function. Can someone point out what's wrong with it? I'm really not sure x.x

 

anything