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

Pages: 1 [2]
16
Window / HUD interface
« on: July 30, 2010, 05:24:38 pm »
I've posted here a few times and every single time (that I can recall), my problems have been related to zooming.

Surprise, surprise, no surprise here. I've finally had quite a bit of success with the zoom function, but now I need to know how to disable it on part of the screen.

I've created a function so that the mouse's global (as opposed to view) coordinates are displayed on the top-right corner of the screen, however, whenever I zoom in or out, the text itself is also resized. Is there a way to prevent this? I know there's the SetSize() function which I can use to adjust the font's size with every zoom, but is there a way of fixing the size relative to the size of the window, instead of the view?

17
Graphics / Adjust thickness of a line
« on: July 22, 2010, 11:00:27 pm »
I hate myself.

But thank you. :p

18
Graphics / Adjust thickness of a line
« on: July 22, 2010, 10:34:41 pm »
Here you go. Just press any key to zoom out. It takes a few steps for it to start to fade until finally vanishing far too early. And I apologize for all the global variables, I promise my real code isn't like this. :p

Also, I'm using SFML1.6.

Code: [Select]
#include <SFML/Graphics.hpp>
sf::RenderWindow App(sf::VideoMode(100,100),"TEST");
sf::View view;
sf::Shape shape = sf::Shape::Line(0,0,100,50,1,sf::Color(0,255,255));

void KeyPressed(sf::Event::KeyEvent e)
{
float t;
view = App.GetView();
view.Zoom(.9f);
App.SetView(view);
t=App.GetView().GetHalfSize().x/App.GetDefaultView().GetHalfSize().x;
shape.SetOutlineWidth(t);
}

int main()
{
sf::Event e;
sf::View View;
while(App.IsOpened())
{
App.Clear();
App.Draw(shape);
App.Display();
while(App.GetEvent(e))
{
if(e.Type == sf::Event::KeyPressed)
KeyPressed(e.Key);
if(e.Type == sf::Event::Closed)
App.Close();
}
}
return 0;
}

19
Graphics / Adjust thickness of a line
« on: July 22, 2010, 07:09:42 pm »
Sorry for returning to this problem, but I've finally been able to sit down and (try to) work on this program again, so I've got new doubts.

I tried the following code:
Code: [Select]
float t = CurrentView.GetHalfSize().x/App.GetDefaultView().GetHalfSize().x;
shape.SetOutlineWidth(t);


It is my understanding that this would give me the "ratio" between the current view and the default, where thickness = 1 implies thickness = 1 pixel. This way, should CurrentView be zoomed out from DefaultView (by half), then the thickness would have to be 2. And since CurrentView's HalfSize is double DefaultView's, this should work, right?

I mean, I've tried it and it doesn't, but...

Obs: Playing with it, I just tried doing that with .SetOutlineWidth(20*t) and almost everything vanished. Only a few line-segments remained...

20
Graphics / Adjust thickness of a line
« on: July 14, 2010, 05:52:41 pm »
Sorry for the double post, but I just realized what I wrote was quite wrong.

SetScale is actually not very useful in this case because the scale is defined in the global X and Y. This means that I can't alter the scale to make the line thicker without also deforming it length-wise (for any inclined line). Well, I could, but that would require a fair share of trigonometry, which isn't friendly to one's processing speed.

It would seem one must use SetOutlineWidth in this case so that the deformation is perpendicular to the line itself.

21
Graphics / Adjust thickness of a line
« on: July 14, 2010, 04:05:00 pm »
Thanks guys.

SetOutlineWidth works great, but I'm just having a bit of trouble with the following. Whenever I use view::zoom(), all my continuous lines dissipate, as I said earlier, to the extent of the image becoming like this:


(Sorry for the large image, but resizing it makes most of the visible lines disappear)

Using SetScale instead (with the thickness changing by 1/zoom-factor, so that the lines get thicker if you zoom out and thinner if you zoom in), the problem is reduced, but still quite visible.

Is there a trick to avoid this?

22
Graphics / Adjust thickness of a line
« on: July 13, 2010, 08:21:50 pm »
As far as I can tell, there is no way of altering the thickness of a shape once it has been set. Is this true?

My program involves an awful lot of zooming in and out from a 1:1 view to a 1:4 view on occasion, which means that the line thicknesses need to be altered quite often (thickness 1 works fine when zoomed in, but "dissipates" when zoomed out, in which case thickness 4 works best. However, thickness 4 on 1:1 is very thick).

Would I therefore have to regenerate any existing shapes each time there is a view change, i.e.:
Code: [Select]
//considering the existence of a previous sf::Shape a, a line of thickness 1
sf::Shape b = sf::Shape::Line(a.GetPointPosition(1),a.GetPointPosition(2),4,sf::Color(0,128,128));


I was hoping there was a simple a.Thickness(4) which would change the property after a RenderWindow::Draw(a);

23
Graphics / Object selection on screen.
« on: May 31, 2010, 09:01:11 pm »
I am about to start a program that will involve the creation of 2D objects (mainly lines). These objects will then need to be selected and altered in various ways. I'm looking for a library with which to create this program and SFML seems very simple to use, but I haven't found any tutorials or functions that deal with object selection. Also, it would have to permit selection off the vertices (that is, in the case of a line composed of two vertices, selection can be done by clicking the line itself, not just its vertices). Also, intersections would have to be dealt with and, worst of all, enclosed areas would have to be selectable (if you have four independent lines creating a square, the square would have to be selectable). Should there be an efficient method of dealing with intersections, creating the area would be simple(ish).

Code: [Select]
if(LineA_intersects_B && B_intersects_C && C_intersects_A)
{
   sf::Shape Area;
   Area.AddPoint(A_intersection_B);
   Area.AddPoint(B_intersection_C);
   Area.AddPoint(C_intersection_A);
}


That is, of course, pseudo-code.

However, I then face the same problem with such an area. I'd have to be able to select the area by clicking on it, not merely on its vertices.

I just want to know if SFML has some function I don't know of which'd make this problem simpler or if you guys have any clever ideas of how to do this with an efficient algorithm.

The only algorithms I can think of are:
(1) launching an imaginary vector in one direction until it hits either the page border (and is thus not enclosed) or until it hits a line, at which point it'd then have to follow the line until it hits it's final vertex (implying the point selected is not enclosed) or another line intersects it, in which case it'd follow that line. This process would be repeated until the vector reaches its starting point. However, doing this for each mouse click sounds hardly efficient.
(2) saving, along with each object, a mathematical description of it (in the case of a line, its equation; in the case of a polygon, a series of equations that represent its borders). The point would then be compared to the mathematical description of each existing object. This seems far more efficient, especially for smaller models. However, it'd also be very inefficient for larger models.

This would be done by creating a series of classes, such as this brutish example:

Code: [Select]
class Line
{
   sf::Shape line;
   pair <pair<float,float>,pair<float,float>> vertices;
   bool f(pair<float,float>);
}

Where function f is the mathematical function that defines the line. Thus, by inputting the coordinates of the click, it returns true if the point is contained within the line.

However, as I said, this would also kinda stink.

Pages: 1 [2]
anything