Jump to content
  • Advertisement

Guy Leonard Thomas

  • Content Count

  • Joined

  • Last visited

Community Reputation

3 Neutral

About Guy Leonard Thomas

  • Rank

Personal Information

  • Interests

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Guy Leonard Thomas

    Simple trig problem driving me crazy

    I agree, this is actually what I'm doing. I was previous passing down the position and rotation of the parent object, and moving the sub-objects around to suit the new position. Having a proper transformation matrix makes this really easy now as I simply pass a reference to the parent transform, far fewer lines of code!
  2. Guy Leonard Thomas

    Simple trig problem driving me crazy

    Thanks all, as promised a working gif. I ended up using transforms in the end, I didn't realize they were implemented so well in SFML (doh!) Thanks also to @Scouting Ninja for a great response
  3. Guy Leonard Thomas

    Simple trig problem driving me crazy

    Yeah I feel like I really should've been using transforms from the beginning - didn't know SFML had them! (Didn't look for them to be fair). Oh well silly me Thanks for the input folks, will post a working image once I've fixed it
  4. Guy Leonard Thomas

    Simple trig problem driving me crazy

    Hey mate, No probs, I should've explained. So basically the offset parameters are supplied via a config file, and describe the offset in pixels, from the centre of the sprite, that the component sprite(s) should be rendered. So for example, the exhaust jet for this particular sprite is at offset (-50,-14) from the center of the sprite. When the sprite rotates, the sub-sprite should too
  5. Guy Leonard Thomas

    Simple trig problem driving me crazy

    This sounds entirely like a good idea, I'll look into transforms, thanks!
  6. Guy Leonard Thomas

    Simple trig problem driving me crazy

    Hah, Thanks! yeah I think you're right. Problem still persists though sadly. Still wonky but better! Anyone else have any ideas what might be causing this?
  7. Hello folks, I am fighting with a really simple problem that has been driving me nuts. I'm usually fairly confident with trigonometry and I'm pretty sure the issue here is not the math but in some behavior behind the scenes. A bit of background - basically I'm developing my own little 2D game engine using C++, in my free-time for fun. I work with game technology and simulation products IRL so for the most part this has been plain sailing. I am using Box2D for physics, and SFML for rendering. My game at current has a few space ships flying around via keyboard and AI input. These space ships need exhausts! So I'm currently in the process of getting a 'component' system in place, however my problem is that the animated exhaust sprites are not going where I want them to. When the base GameObject class runs it's update method, it does the following: Queries the physics object for a position Converts the physics position to a pixel position (x10 scale factor) Moves the sprite to the new position Passes new position to all 'component' objects into their 'UpdateComponent' method Components move their sprite to the correct position However the exhaust sprites seem to wander around all over the place, in no way representing where I actually want them to be! This should have been a simple case of: newPosition = (sin(rotationRadians) * offsetX, cos(rotationRadians) * offsetY) + oldPosition Here is the current code: void Exhaust::UpdateComponent(const Vec2f & position, float rotationDegrees, float deltaTime) { float angleRad = DEGREES_TO_RADIANS(rotationDegrees); float offsetX = sin(angleRad) * mOffset.x; float offsetY = cos(angleRad) * mOffset.y; sf::Vector2f newPos(position.x + offsetX, position.y + offsetY); mSprite->SetRotation(rotationDegrees); mSprite->SetPosition(newPos); mSprite->Update(deltaTime); #ifdef _DEBUG sf::Vector2f p(position.x, position.y); stringstream ss; ss << rotationDegrees; DebugUtils::DrawCross(p, 8, sf::Color::Green, ss.str()); DebugUtils::DrawCross(newPos, 8, sf::Color::Green); DebugUtils::DrawLine(p, newPos, sf::Color::Green); cout << rotationDegrees << endl; DebugUtils::DrawSpriteOutline(*mSprite->GetGraphic(), sf::Color::Green); #endif // _DEBUG } And here is a gif of it all going wrong! (link below) Gif of game engine problem Any help would be much appreciated, even if it is just a thought of where the problem might be originating from! Thanks!
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!