SFML community forums

Help => Graphics => Topic started by: legacyblade on March 25, 2014, 11:54:56 pm

Title: Help creating custom shape
Post by: legacyblade 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 (http://pastebin.com/Y54HCzjr)
sectioned_skewable.cpp  (http://pastebin.com/t77TwjgH)

main.cpp (http://pastebin.com/1TmHiWFW)

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.
Title: Re: Help creating custom shape
Post by: Nexus on March 26, 2014, 12:07:52 am
Can you show a minimal and complete example (http://minimal and complete example) (please read the link carefully)? But be aware that skewing won't work without perspective correction (http://www.xyzw.us/~cass/qcoord/) (i.e. direct OpenGL).

And you shouldn't put your own classes in namespace sf, even if you inherit SFML classes.
Title: Re: Help creating custom shape
Post by: legacyblade 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)
Title: Re: Help creating custom shape
Post by: Laurent 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.
Title: Re: Help creating custom shape
Post by: legacyblade 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