November 12th, 2013, 12:20 PM
Analitical Geometry problem
Hi ! :D
I just started my first game in C++. :cool:
The libraries I use are Box2D (for physics) and Allegro (for graphics).
I made a line that has a point fixed on certain coordinates and the other point following the mouse. :cool:
What I want to do is that when I press the left mouse button , my line will be fixed on an axis made by the mouse and the fixed point and can be moved by the mouse movement on that axis.
My problem is : how can I write that movement ? :confused: I got figured out the mouse button press and any side details I only need advice on the movement on a certain axis.
November 12th, 2013, 01:22 PM
I don't know those libraries. However, a basic principle in computer graphics is that when you want something to move on the display, you erase it from its old location and then you redraw it in its new location. A simple approach to erasing an object is to redraw it with the background color, though this can be complicated by other objects overlapping it. It's been quite a while, but I seem to recall something about XOR'ing the colors.
See what Allegro has to offer for erasing.
November 12th, 2013, 01:30 PM
That's not the problem .My problem is more math related (I think !?)
Originally Posted by dwise1_aol
My problem is how to find out coordinates to move my line on certain axis . The drawing part I got it figured out. I only want to know the math for the algorithm.
November 12th, 2013, 01:40 PM
A ^ B ^ A
certainly is B.
When I tried the xor graphics trick back on the ol' IBM PC my program left speckles of bright "dust" along the path. And to this day I'll swear I used the same algorithm (with same input, to be sure!) for erasure as for original drawing. The coordinates had to have been identical.
[/code] are essential for python code and Makefiles!
November 12th, 2013, 01:56 PM
From what I got from your description, you have a line segment, one end of which is at a fixed point and the other end of which follows the mouse cursor. That's a very common effect that we see in many graphics applications.
I do not know Allegro, but in MFC you use LineTo, which draws a line segment from one point to another. From the MoveMouse event handler that's fired every time the mouse is moved, you get the mouse's current x,y coordinates (which Windows passes to the event handler), so you would simply erase using the fixed point and the mouse's old coordinates (which you would have had to have saved from the last time you did this), redraw the line using the fixed point and the mouse's current coordinates, and save the current coordinates to be the next call's old coordinates. So do that with whatever Allegro gives you to do the same things.
I don't see where any math would be involved. Perhaps you have a different definition for that "axis" than I do; I understand that fixed point to be the axis around which the line segment is moving.
November 12th, 2013, 02:44 PM
dwise1_aol : I understand what functions you use , I use something very similar but from what you wrote you describe me how to make the line to follow my mouse .I got that :D. The problem is to fix the line and move it on a certain angle.
Well maybe I used an ambiguos meaning for axis .But I will explain on a practical example. :)
I want to make a pool game . This ideea of the line will be the cue. What I want is that when i press the left mouse button .The cue will fix on its current angle( maybe angle is a better word :D ) and I drag the cue with my mouse to choose my power of shooting. And on release to have a stronger force if the cue is more distanced by the ball. I hope I transmitted the right idea.
PS: If by chance you guys played the Miniclip ' 8 Ball Pool it's the exactly effect I want . Or on Yahoo Messenger you keep pressed the right mouse button to select the power :D.
PS 2: Sorry if I am being repetitive , I just want to make sure that you understand what i seek advice for :) .