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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - legacyblade

Pages: [1] 2
1
Graphics / Re: Help creating custom shape
« 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

2
Graphics / Re: Help creating custom shape
« 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)

3
Graphics / 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.

4
Graphics / Re: image deformation (skewing/perspective)
« on: February 07, 2014, 07:57:14 pm »
@eXpl0it3r, All I wanted to do was shrink one edge and grow the other. So it does exactly what I need it to! I need to make sure to read the documentation more often XD

@Golden Eagle, didn't know that! Guess it's a good thing I decided to check back on this topic. I guess I'll either have an image with the top,left, and right textures in it, or a whole sprite sheet. (I'd have each row be a new tile texture, with each column being a different side of the cube) I'm excited to try that out sometime!

5
Graphics / Re: image deformation (skewing/perspective)
« on: February 07, 2014, 07:36:32 pm »
Oh o.o I didn't know I could have multiple quads in a vertex array. If I ever decide to make an isometric tile game, that would simplify things quite a bit. I could have three quads that take flat textures and build a cube from the proper perspective. The documentation talks about how to make a custom drawable using quads, so I could just do something like

tile newTile("left_texture.png", "right_texture.png","top_texture.png");
newTile.set_position(2,3,5); //position 2,3 with a height of 5

Thanks for showing me that it could do that. I can see this knowledge being super useful in the future lol.

6
Graphics / Re: Help with texture coordinates on a vertex array
« on: February 07, 2014, 07:31:01 pm »
Ah ok. That makes a lot of sense.

Well now that I'm armed with a full knowledge of how the texture coordinates work, time to make a custom drawable!

Thanks again!

7
Graphics / Re: image deformation (skewing/perspective)
« on: February 07, 2014, 07:21:51 pm »
The quad did exactly what I wanted, lol. Thanks for pointing that out to me Golden Eagle. I only stumbled across the concept of a quad trying to figure out how to do it in openGL, XD You're very helpful :D

8
Graphics / Re: Help with texture coordinates on a vertex array
« on: February 07, 2014, 07:20:44 pm »
*facepalm* I can't believe I forgot to change the lines[0] to the appropriate number each time. I feel dumb XD

Thanks so much for helping me! I honestly don't think I would have ever noticed, and I would have just tried completely rewriting it eventually and never understood what I'd done wrong the first time.

Out of curiosity, why am I subtracting 1 from the size each time? What's going on there?

9
Graphics / Help with texture coordinates on a vertex array
« on: February 07, 2014, 06:53:47 pm »
Hello everyone! For something I'm doing (giving a sprite perspective by skewing parts of the image), I need to map an image to a vertexArray (specifically the sf::Quad variety). I've read the tutorials, looked at pretty much all the questions that have been answered concerning vertexArrays. But I still don't even remotely understand what numbers I should plug into the vertex's texCoords variable.

For testing purposes, I'm trying to map this image to a square



but it comes out looking like this



my code is as follows

sf::Texture texture;
texture.loadFromFile("boxie.png");
sf::Vector2u size = texture.getSize();

sf::VertexArray lines(sf::Quads, 4);

lines[0].position = sf::Vector2f(0, 0);
lines[1].position = sf::Vector2f(0, 100);
lines[2].position = sf::Vector2f(100, 100);
lines[3].position = sf::Vector2f(100, 0);

lines[0].texCoords = sf::Vector2f(size.x/2,size.y/2);
lines[0].texCoords = sf::Vector2f(size.x/2,size.y);
lines[0].texCoords = sf::Vector2f(size.x,size.y);
lines[0].texCoords = sf::Vector2f(size.x,size.y/2);

I know that this must be something obvious that I'm missing. But I just can't figure out what numbers I should plug in to get the top left corner of the square to be the top left of the image, the bottom left to be the bottom left, etc. Does anyone know what I'm doing wrong? (and have some sort of explanation as to WHY that's the case?

Ultimately, I hope to have the upper-torso from the front,back, and side in a single file, then use the texCoords to select the appropriate part of the image for the direction the entity is moving (and adjust the shape of the quad to give perspective during certain parts of the animation). But I'm just completely stuck when it comes to the texCoords.

Thanks for reading!

10
Graphics / Re: image deformation (skewing/perspective)
« on: February 07, 2014, 04:26:53 pm »
Alright. Any advice on where to start?

11
Graphics / Re: Does anyone use the built in sf move function?
« on: February 07, 2014, 07:25:54 am »
move() saves a few lines of code if you're just doing something really simple. Granted, I've never used the function (as I usually have an entity who's position the sprite mirrors every frame, I have my own implementation of move() in the entity) . It helps with swift prototyping, and is just pretty convenient when you're getting started.

12
Graphics / image deformation (skewing/perspective)
« on: February 07, 2014, 03:50:20 am »
Hello everyone. I'm working on making a (super basic) 2D skeletal animation system. However, I'm not sure how to skew an image. My plan is to have each piece of the body chopped up from the front, left, right, and back. Animating things on the side view will be pretty simple. I've become very familiar lately with how to move/rotate images relative to other images :P

From a couple hours of googling, it seems doing this used to be impossible because older versions of SFML didn't support vertex shaders. But after poking around in the documentation, I notice those have been added.

How would I go about skewing an image? I'm unfamiliar with shaders in general, so if anyone could post some code to get me going in the right direction that'd be awesome. I just want to be able to shrink/grow the edges of the image in real time to simulate perspective.

Thanks for reading :) I appreciate any advice you can leave.

13
Graphics / Rotate sprites relative to their position in a "container"
« on: November 11, 2013, 09:12:07 pm »
Hello. I'm working on building a game engine. One problem I'm having deals with a class that contains multiple sprites. I need to be able to position individual sprites within this container class. When moving, rotating, or scaling the container class, every sprite contained needs to keep their relative position and rotation.

I retooled some old code of mine, but I'm getting unexpected results when handling rotation. If the child sprite is not in the exact center of the container, it spins around wildly and ends up in a semi-random location.

The code for the method setting all the sprites position and rotation relative to the container's current angle is as follows:

void sprite::render_children_angle()
        {
                for(unsigned int i = 0; i < drawables.size(); i++) {
                        drawable*& child = graphicSystem.get_drawable(drawables[i].first);

                        std::pair<float,float> childPos = child->get_pos();

                        float radius   = std::sqrt( (xPos - childPos.first)*(xPos - childPos.first) + (yPos - childPos.second)*(yPos - childPos.second));
                        float angle = atan2(yPos - childPos.second, xPos - childPos.first);

                        float newAngle = angle - (cAngle * 3.14/180);

                        float newX = radius * std::cos(newAngle);
                        float newY = radius * std::sin(newAngle);

                        child->set_pos(xPos - newX, yPos - newY);
                        child->set_angle(drawables[i].second->angleOffset + cAngle);
                }
        }
 

cAngle is the container's angle. The "drawables[ i ].second->angleOffset" is the individual sprite's rotation. Both are set outside this method, and I've verified that they're the proper values. I've no idea what's causing the problem. I've spent quite awhile tweaking the code, but nothing seems to produce any results.

Any help you could give me with this would be great. Geometry is a subject I've never been very good at, so I'm not sure how to go about even figuring out what went wrong or why.

14
Graphics / Re: Issue with vector of sprites
« on: January 31, 2013, 09:23:48 pm »
Just wanted to let ya know I got darkshadow's method working. :D Works great, and now I don't have to have my OCD nagging me that I'm using more memory than I need XD Dunno if it was something in my implantation, but it didn't work if my sprites were pointers. I'd get an error when calling it like this "window.draw(heartContainer.sprites);" (where heartContainer is an instance of Sprite_Holder and i is an existing index). But it works like a charm :D

@Ruckamongus, Oooo. I'm going to have to check out the unique_ptr later on. Sometimes it's a pain to implement the functionality to delete all the pointers, so that might save me a lot of time.

@xDarkShadowKnightX, thanks again for the help. And thanks for the wish of good luck. I really appreciate the help.

@eigenbom, even though I'm not using it here, I'm pretty sure the "reserve" function is going to come in handy somewhere down the line. I don't think I would have ever stumbled across that one, so thanks a ton for showing it to me!

15
Graphics / Re: Issue with vector of sprites
« on: January 31, 2013, 03:29:14 am »
Wheew! Thanks for the replies. I really appreciate the fast help.

@Eigenbom's suggestion worked perfectly (thanks so much ^.^), but I'm going to try xDarkShadowKnightx's suggestion with the pointers, since I'd rather not have to allocate an arbitrary amount of memory whether I need that much or not.

@xDarkShadowKnightx, I've had bad luck trying to work with textures as pointers though (as sprites can't accept a pointer to a texture in their setTexture method usually), so I'm not sure if I'll be able to get that to work. But I hope it will. And I'll keep in mind to delete the sprite first. I'll just set up a destructor method for Sprite_Holder that loops through the vectors and deletes everything. If I can't get it to work, though, I'll definetly take you up on that PM offer :)

Thanks again guys. This really helped me out.



Pages: [1] 2