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 - Tweezy

Pages: [1] 2 3
1
General / Re: Change origin of rotation
« on: June 29, 2014, 05:29:51 pm »
what is your reasoning behind inverting the rotation?
I noticed that when the target was above, it was vertical, but when you went to the top-right, it leaned left. Also, when you weren't perfectly above (you were slightly to the right), it leaned slightly to the left.

Glad it worked and that I could be of some help :)

You have a keen eye Sir, thank you for pointing it out!

2
General / Re: Change origin of rotation
« on: June 29, 2014, 05:23:16 pm »
Rotation-wise the laser needs to be flipped so you could try inverting the rotation i.e. return -rotationAmount;

For a better understanding of how the laser reacts to different positions, try clicking on points all the way around the emitter ("tank") - not just horizontal and diagonals - and also different distances from it.

Holy moly that worked, I never would of thought to do that, what is your reasoning behind inverting the rotation?

3
General / Re: Change origin of rotation
« on: June 29, 2014, 04:47:39 pm »
That is what I want to move onto, yes. But even then i'm going to have issues with the rotation of the sprite, so I need to get this bit sorted:


http://johns-webdesign.com/movies/My%20Movie.mp4

4
General / Re: Change origin of rotation
« on: June 29, 2014, 04:39:17 pm »
the rotateToTarget just returns an angle to rotate by depending on where i have clicked. I'll create a video, think that'll be the easiest option. Give me 10 minutes to downloads fraps

5
General / Re: Change origin of rotation
« on: June 29, 2014, 04:35:53 pm »
Realised I had done a stupid mistake with my rotate function, it doesn't  (Shouldn't) need to return an x / y, just an amount. Changed that bit of the code to just return a float, not a vector.

Didn't affect the outcome of the rotation though, darn it.

6
General / Re: Change origin of rotation
« on: June 29, 2014, 04:30:50 pm »
Check OP eagle, edited it with the my code.

7
General / Re: Change origin of rotation
« on: June 29, 2014, 04:12:48 pm »
Ah shit, i've found an issue with my rotateToTarget function.

It return -180 to 180 degrees, but whenever it is enabled it keeps shifting the position of the laserShape while actually rotating it. This is strange

8
General / Re: Change origin of rotation
« on: June 29, 2014, 04:09:13 pm »
If you want the bottom, don't divide height by 2; that would give the centre.

Decided the general center of the sprite would be a better location to rotate it by so that it doesn't alter its position as it carries on rotating (Which will screw it up).

Still not helping though, this is damn strange.

9
General / Re: Change origin of rotation
« on: June 29, 2014, 03:55:16 pm »
thanks for the reply Eagle. This doesn't work. Perhaps there is an issue somewhere else. I'll post my code up (See OP)

10
General / Re: Change origin of rotation
« on: June 29, 2014, 01:01:03 pm »
I know I need to set its origin, but whenever I try and change it based of the width and height it always goes really, really strange and weird. This is the code i've tried;


float width = myShape.getGlobalBounds().Width;
float height = myShape.getGlobalBounds().Height;

This returns the width and height of by object. From here I don't know how to actually get the bottom middle point. Think i need a coffee break to logically think about what the hell I'm wanting to do haha

11
General / Change origin of rotation
« on: June 29, 2014, 02:12:08 am »
Hi all. I'm making a little 2D tank game, it works relatively to where you click on the screen. So, when you click on the screen it grabs a current location, desired location, does some ATAN2, normalisation and works out where the click was located, how much to rotate by and then when to shoot.

The tank moves by the perfect amount, stops rotating and then fires it projectile to that position.

I have on issue. The rotation of the projectile isn't correct for where the rotation of the tank sprite is. I know the issue, but I'm not quite sure on how to fix it.

At the moment the projectile is being rotated on the top left corner (Default position). I need some help on how to change it to the bottom middle position, this will make the sprite rotate correctly when I call the rotate function.

How can I accomplish this?

Any help would be really, really helpful!

Thanks :)

-- EDIT --

Code

Projectile class


void projectile::init()
{
        laserShape.setTexture(*laserTexturePointer);
        laserShape.setOrigin(laserShape.getLocalBounds().width/2.0f, laserShape.getLocalBounds().height/2.0f);
        laserShape.setPosition(580,280);
}
void projectile::input(sf::RenderWindow &window)
{
        p.current.x = laserShape.getPosition().x - laserShape.getGlobalBounds().width/2.f;
        p.current.y = laserShape.getPosition().y - laserShape.getGlobalBounds().height/2.f;

        p.desired.x = sf::Mouse::getPosition(window).x;
        p.desired.y = sf::Mouse::getPosition(window).y;
        laserShape.setRotation(p.rotateToTarget(p).x);

        //std::cout<<"X Rotation Amount :"<<p.rotateToTarget(p).x<<std::endl;
}
void projectile::update()
{
        laserShape.move(p.fireTo(p).x, p.fireTo(p).y);
}

void projectile::draw(sf::RenderWindow &window)
{
        window.draw(laserShape);
}

Rotation function


vector2D position::rotateToTarget(position p)
{
        delta.x = desired.x - current.x;
        delta.y = desired.y - current.y;

        rotationAmount = atan2(delta.x, delta.y)*180/PI;

        return rotationAmount;
}

How I call it all


      
if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
                {      
                        bullet.input(window);  
                        bulletVec.push_back(bullet);
                        std::cout<<bulletVec.size()<<std::endl;
                }

Then in my update function I just iterate over my bulletObject vector to call the projectile::update() function.

The code it pretty simple, not much happening at the moment.

12
Graphics / Re: Run-Time Check Failure #2 - Corrupted Stack error
« on: March 11, 2014, 12:47:57 am »
Thanks for the in-depth response.
You are welcome.

That function is being put into an update() function which is constantly updated while the window is open, so that shouldn't be an issue. It will only be destroyed when the window is closed.
I think you misunderstand.
What I mean is
void func() {
 int a = 42;
 // pass a pointer or reference to "a" to someone else
} // At this point "a" is destroyed, so that pointer or reference you passed to some other function is now invalid.
 
Variables declared on the stack only live until they go out of scope (in this case the scope being the function). It doesn't matter if you call the function from somewhere else continuously.
For example:

void f(int a) {
  int b = 5;
  int c = a * b;
  std::cout << "c is " << c << std::endl;
}

int main() {
  for (int i = 0; i < 10; ++i) {
    f(i);
  }
}
 
In the above program, the variables "b" and "c" are going to be created and destroyed 10 times each - once every time the function is called. It doesn't matter that "f()" is called inside the loop until the program exits - the variables inside the function are not kept alive from one invocation to the next.
This is fairly basic C++ knowledge btw.

Ohh and one other thing; concerning what Nexus said:
You want to make sure that you are not building your application in debug mode but linking to the release mode libraries or building in release mode but linking to the debug libraries. That's what's meant by "mixing debug and release".

Thanks for the link and increasing my warning levels, will try them and report back.
Looking forward to hear what you find :-)

Yes I did misunderstand haha sorry, been programming for like 12-14 hours each day for the past week (Uni assignment) so I'm a tad mind dead! Basically declaring things locally, once you move from the class they are destroyed - can't believe I missed that! Moved my sf::font and sf::text to my header file, issue fixed! I'm such a numpty haha :') Thanks!

13
Graphics / Re: Run-Time Check Failure #2 - Corrupted Stack error
« on: March 11, 2014, 12:24:11 am »
well, your "defaultFont" is a stack (automatic) variable in the game::gui() function, so as soon as that function exits it is going to be destroyed and any reference to it past that point is going to go bad. Could that be your problem?

If not, then perhaps try running your code under a tool like Valgrind (http://www.valgrind.org/) or do a build with gcc (4.8+) or clang (3.4+) with -fsanitize=address enabled (read more here: http://clang.llvm.org/docs/AddressSanitizer.html) and see what that finds. Both those tools are rather excellent in tracking down memory corruption bugs.

Ohh and before you do that, bump you compilers warning level to the max and check/fix all the warnings - most compilers are pretty good at spotting silly mistakes as long as you let them (by upping their warning level).

Thanks for the in-depth response. That function is being put into an update() function which is constantly updated while the window is open, so that shouldn't be an issue. It will only be destroyed when the window is closed.

Thanks for the link and increasing my warning levels, will try them and report back.

14
Graphics / Re: Run-Time Check Failure #2 - Corrupted Stack error
« on: March 11, 2014, 12:19:38 am »
How would I go about recompiling SFML? I've never mixed the Release/Debug.

15
Graphics / Run-Time Check Failure #2 - Corrupted Stack error
« on: March 11, 2014, 12:03:13 am »
SFML 2.0
VS2012

Bug - Run-Time Check Failure #2 - Stack around the variable 'defaultFont' was corrupted.

Code in question:

void game::gui()
{
        //Lives string
        //Time string
       
        sf::Font defaultFont;
        if(!defaultFont.loadFromFile("arial.ttf"));
        sf::Text playerScore;
        playerScore.setFont(defaultFont);
        //Display them
}

I'm making a simple gui for my platformer game, but i'm having a really strange bug whenever I use the SFML2.0 sf::Text function.
I would also like to point out that I do not have this error when I comment out all of  the sf text and font.

I've double checked my references and double checked it against the build type. I'm building in debug mode, and the references have -d.

I've done a little bit of research, and from what i've collected I come to the conclusion that either:
- Using Memory that isn't there.
- Too much data being put on the stack

If these are the issue, i've never been taught memory management so not too sure how to rectify it.

Really confused about this and I need to develop my GUI.

Thanks guys

Pages: [1] 2 3
anything