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

Pages: [1]
1
Graphics / Making a player change direction??
« on: September 13, 2011, 07:21:35 am »
yeah, thats way easier to understand, probably faster too.
so to keep from repeating work, since he does need the angle
Code: [Select]

float angle = atan2(motion.x,motion.y)*180/M_PI;

will get you there.

2
Graphics / Making a player change direction??
« on: September 12, 2011, 04:43:36 am »
its kind of dense reading if you aren't up to snuff on your highschool geometry. The use of atan2 is to get an angle in radians from the difference of 2 points. So to use atan2 you'd subtract the origin x, from the dest x, then the origin y from the dest y, and then atan2(diffx,diffy), to get the angle in radians.

sf::Drawable::setRotation doesn't accept angle in radians though, so if you tried just using the raw output of atan2, you'd get some goofy results; degrees from radians is = radians * (180/PI).

Now for movement you need sine and cosine. to calculate where you would land on the line, at some speed, you
Code: [Select]

newx = speed * cos(radians); //cosine calculates the x movement from speed
newy = speed * sin(radians); // sine calculates y movement from speed

repeat until the sprite is approximately at the coordinates of the mouse click.

3
Graphics / Conceptual clarification of Views
« on: September 12, 2011, 01:18:01 am »
Alright, well then maybe this question will shed some light on it. Ive tried searching the forums, and ive looked through the documentation and tutorials. What happens when you switch between views? I've boiled my confusion down to a small subset of the sample code. Im not confused about any of the sprite stuff, or the centering of the secondary view. Mainly just how everything is drawn.
Code: [Select]

     // Set the view
        App.SetView(View);

        // Clear screen
        App.Clear();

        // Draw background
        App.Draw(Background);

So we are drawing the background here, 'in relation to' View, correct?
Code: [Select]

        // Draw cursor
...
        App.Draw(Cursor);

 basically the same thing is going on here.
Code: [Select]

        // Reset to the default view to draw the interface
        App.SetView(App.GetDefaultView());

        // Draw some instructions
        App.Draw(Text);

 and now we draw the interface... 'in relation to' the default view
Code: [Select]

        // Finally, display rendered frame on screen
        App.Display();


and here its all flipped out to the hardware for rendering

Is this a reasonable assessment of how things are happening here? If this is the case, then the camera analogy is what lost me.

edit:

basically, drawing is done with regard to the position of the view. The 2d world this is kind of confusing too, because the views arent 'of' the 2d world, per se, they are used to build it up. the position and size of the 'View' view is just used to determine what part of the background (both size and position within the image) are drawn.  I think ive got it. I think a projector is a better analogy than a camera. Again I am way green on SFML in general, and this is a much different concept than a 3d camera, which is not very much about construction, and more about rendering perspective.

4
Graphics / Conceptual clarification of Views
« on: September 11, 2011, 10:02:35 am »
I'm very new to SFML, and am trying to wrap my head around how views are supposed to be used/understood.

Mostly I am a confused about point of reference, and relationship between SFML objects. I went through the view tutorial, and then downloaded and compiled the source at the bottom of the tutorial.

In the example, it says that the sizes of the two views (the user created, and default view) are the same. However, the background sprite is resized so that it is larger than both. My question, is where is the background 'drawn to', and what is the point of 2 views if you only ever actually 'view' one of them.

The ordering is throwing me off. First you create the background sprite, and its resized. Then you create the alternate view, with the same dimensions as the RenderWindow. Then you move the alternate view (im guessing in relation to the default view). You set the alternate as the default, and then draw to the window (or the view?). Right here everything starts breaking down for me. First, theres no room for the background sprite if we are drawing to a view, so I imagine the edges would be lopped off. But they are not.

Now we switch back to the default view, and draw the overlay (to the view?).

In the comments, when the alternate view is created, theres a mention of setting the center and halfsize's in relation to the background sprite. Why I see the relationship between the dimensions used, and the positions... but this all begs the question, what are these views views of? I am not seeing a clear relationship between the two views (if its a child-parent relationship).

If I had a few more examples of view scrolling maybe i'd understand.

Pages: [1]