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.


Topics - wasabi

Pages: [1]
1
General / sf::Unicode::Text::Text problem with Qt?
« on: September 10, 2010, 07:14:51 pm »
After a good time away from it, I'm back on my Qt / SFML program and have progressed far faster than I'd imagined, but now I have a problem with sf::String::SetText().

Code: [Select]
class MyCanvas : public QSFMLCanvas
{
Q_OBJECT
public :
MyCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size);
MyCanvas();
public slots:
void OpenFile(QString str);
private :
        QFile pl;
        QTextStream _pl;
sf::View CurrentView;
sf::View GlobalView;
Point MouseCoords;
std::vector<Line> faults;  
std::vector<Line> horizons;
std::vector<Point> points;  
void ChangeView_Key();
void ChangeView_Pan(QMouseEvent* e);
void DesignFault();
void DesignLine(Point pt1, Point pt2);
    Line* NewLine();
void OnInit();
    void OnUpdate();
void SaveFaultPoints(int elevation,int n);
void SaveFaultSegments();
protected:
void keyPressEvent(QKeyEvent* e);
void mouseMoveEvent(QMouseEvent* e);
void mousePressEvent(QMouseEvent* e);
void wheelEvent(QWheelEvent* e);
};

void MyCanvas::OnUpdate()
{
    std::string coords("(");
    sf::String Coords;
    char coord[16];
    //Clear();
    sprintf_s(coord,16,"%.0f",MouseCoords.coord.x);
    coords+= coord;
    coords+= ",";
    sprintf_s(coord,16,"%.0f",MouseCoords.coord.y);
    coords+= coord;
    coords+= ")";
    Coords.SetFont(sf::Font::GetDefaultFont());
    Coords.SetSize(30.f);
    Coords.SetText(coords);
    Clear();
    for(std::vector<Line>::iterator it=faults.begin();it<faults.end();it++)
        Draw(it->shape);
    for(std::vector<Point>::iterator it=points.begin();it<points.end();it++)
        Draw(it->shape);
    for(std::vector<Line>::iterator it=horizons.begin();it<horizons.end();it++)
        Draw(it->shape);
    SetView(GetDefaultView());
    SetView(CurrentView);
    Display();
}


Should I try to compile it, however, I get the following error:
Code: [Select]
1>MyCanvas.obj : error LNK2019: unresolved external symbol "public: __thiscall sf::Unicode::Text::Text(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0Text@Unicode@sf@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "private: virtual void __thiscall MyCanvas::OnUpdate(void)" (?OnUpdate@MyCanvas@@EAEXXZ)
1>debug\QT.exe : fatal error LNK1120: 1 unresolved externals


However, if I comment out the .SetText() command, it compiles correctly.

2
General / Qt / SFML interface
« on: August 09, 2010, 03:08:34 pm »
This sounds like a really, really stupid issue (probably because it is), but I for some reason can't include SFML files into my Qt program (I'm having to bind the SFML program I've built with Qt for its added modular windows [open file, etc] functionality).

For instance, if I write
Code: [Select]
#include <SFML/Graphics.hpp>
I get the build error "Cannot open include file: 'SFML/Graphics.hpp': No such file or directory"

I'm using VC++ 2008 Express and making everything as a makefile, since Qt misbehaves if you do it any other way. However, in the solution properties window, I have "Include search path: [my SFML file path]", just as I have my Qt file path. As well, I find this particularly annoying since it clearly can open the .hpp since VC's Intellisense is working just fine. I type sf:: and it shows me all the possible choices I have. But then I try to build and it goes "wait, what? what file is that?!"

I feel like a shmuck, but why doesn't this work?

3
Graphics / shape.GetPointPosition error
« on: July 30, 2010, 07:03:16 pm »
Lo and behold, another zoom issue coming from me.

I'm trying to create an "infinite line," one that stretches out no matter how far you zoom. I thought the easy way of doing that would be:

Code: [Select]

CurrentView.Zoom(0.9f);
shape.SetPointPosition(1,sf::Vector2f(CurrentView.GetCenter().x-CurrentView.GetHalfSize().x,950);
shape.SetPointPosition(2,sf::Vector2f(CurrentView.GetCenter().x+CurrentView.GetHalfSize().x,950);


This way, the horizontal line, which was created originally with CurrentView.GetRect().Left and CurrentView.GetRect().Right for it's coordinates' x-values, would be resized at every zoom. I didn't use .Left and .Right this time because myRect is only updated with an App.Draw(), not with .Clear(), .Display() or .SetView(), and I have nothing to draw before these corrections. Plus, I checked the math and .GetCenter() - .GetHalfSize() is equivalent to .GetRect() after the update.

However, while the line works fine when originally generated using .Left and .Right, the resize doesn't. The line is drastically reduced in length if zooming out and vanishes if zooming in. It still appears just fine if I pan without zooming, though, so it's not a problem involving my use of App.Draw().

4
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?

5
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);

6
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]