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

Pages: [1]
1
narf :\

thank you sir, now the edge is drawn and moved correct.

2
Hello,
I'm drawing a Line by placing (drawables I've created) 2 Vertice Objects and an Edge Object with a mouse click at mouse position, then when moving the mouse I move the 2nd vertice to the mouse position. A 2nd mouse click releases the 2nd vertice.

While the 2nd vertice is being moved the Width of the RectangleShape of the Edge Object and the Rotation of the drawing Sprite of the Edge Object need to be updated.

Creating the Edge works fine but applying new distance and rotation doesn't. Well sort of. Something is generally wrong with the way I get the rotation angle, but that shouldn't also fiddle with the distance.

For clearance, the way i draw:
Control : Transformable, Drawable (containing a Sprite, a RenderTexture and a List<Drawable>
   Each Update all Drawables are drawn to the RenderTexture which is shown with the Sprite.
Edge : Control (containing a RectangleShape in the List<Drawables> and links to two Vertices)

http://gfycat.com/ThoroughBetterBarebirdbat
first Edge (Vertice A at lower left, Vertice B at upper right)
second Edge (Vertice A at upper right, Vertice B at lower left)
third Edge: placement demonstration

I know it could be that just my math is wrong but when I fiddle with sprites and shapes in sfml I allways step into problems like this. Maybe you see what's wrong here?

I'm coding DotNet:

//Control Creator
public Control(uint _width, uint _height) {
   enabled = true;
   visible = true;
   hovered = false;
   pressed = false;
   surface = new RenderTexture(_width, _height);
   drawables = new List<Drawable>();
   sprite = new Sprite(surface.Texture);
   sprite.Position = Position;
   sprite.Origin = Origin;
   clearColor = defaultClearColor;
}

//Control manipulation
public virtual void SetSize(Vector2u _size) {
   surface = new RenderTexture(_size.X, _size.Y);
   sprite = new Sprite(surface.Texture);
   sprite.Position = Position;
   sprite.Origin = Origin;
}
public void SetPosition(Vector2f _position) {
   Position = _position;
   sprite.Position = _position;
}
public void SetOrigin(Vector2f _origin) {
   Origin = _origin;
   sprite.Origin = _origin;
}
public void SetRotation(float _angle) {
   Rotation = _angle;
   sprite.Rotation = _angle;
}

//Edge Creator
public Edge(Vertice _a, Vertice _b) : base(0, 0) {
   _a.Edges.Add(this);
   _b.Edges.Add(this);
   a = _a;
   b = _b;
   thickness = defThickness;
   color = defColor;

   float distance = (float)Vertice.Distance(a, b);
   base.SetSize(new Vector2u((uint)distance, (uint)thickness));
   SetPosition(a.Position);
   SetOrigin(new Vector2f(0, thickness / 2));
   float angle = (float)Vertice.Angle(a, b);
   SetRotation(angle);
   shape = new RectangleShape(new Vector2f(distance, thickness));
   shape.FillColor = color;
   Drawables.Add(shape);
}

//Edge manipulation
public void SetVerticeA(Vertice _a) {
   if (_a != a && a != null) a.Edges.Remove(this);
   if (!_a.Edges.Contains(this)) _a.Edges.Add(this);
   a = _a;

   float distance = (float)Vertice.Distance(a, b);
   base.SetSize(new Vector2u((uint)distance, (uint)thickness));
   SetPosition(a.Position);
   SetOrigin(new Vector2f(0, thickness / 2));
   float angle = (float)Vertice.Angle(a, b);
   SetRotation(angle);
   shape.Size = new Vector2f(distance, thickness);
}
public void SetVerticeB(Vertice _b) {
   if (_b != b && b != null) b.Edges.Remove(this);
   if (!_b.Edges.Contains(this)) _b.Edges.Add(this);
   b = _b;

   float distance = (float)Vertice.Distance(a, b);
   base.SetSize(new Vector2u((uint)distance, (uint)thickness));
   float angle = (float)Vertice.Angle(a, b);
   SetRotation(angle);
   shape.Size = new Vector2f(distance, thickness);
}

Math:
public static double Distance(Vertice _a, Vertice _b) {
   return Math.Sqrt(Math.Pow((_a.X - _a.Y), 2) + Math.Pow((_b.X - _b.Y), 2));
}
public static double Angle(Vertice _a, Vertice _b) {
   double radians = Math.Atan((_b.Y - _a.Y) / (_b.X - _a.X));
   return  radians * 180 / Math.PI;
}

MouseHandling:
private void WindowOnMouseClick(object sender, EventArgs e) {
   if (!inPlacement) {
      inPlacement = true;

      SFML.System.Vector2i mouse = SFML.Window.Mouse.GetPosition(window.Real);
      placementA = new Vertice(new SFML.System.Vector2f(mouse.X, mouse.Y));
      placementA.SetEnabled(false);
      placementB = new Vertice(new SFML.System.Vector2f(mouse.X, mouse.Y));
      placementB.SetEnabled(false);
      placementEdge = new Edge(placementA, placementB);
      placementEdge.SetEnabled(false);
      window.Controls.Add(placementEdge);
      window.Controls.Add(placementA);
      window.Controls.Add(placementB);
   }
   else inPlacement = false;
}
private void WindowOnMouseMove(object sender, SFML.Window.MouseMoveEventArgs e) {
   if (inPlacement) {
      SFML.System.Vector2i mouse = SFML.Window.Mouse.GetPosition(window.Real);
      placementB.SetPosition(new SFML.System.Vector2f(mouse.X, mouse.Y));
      placementEdge.SetVerticeB(placementB);
   }
}

3
Window / Re: Interprocess Comunication (SendMessage / GetMessage)
« on: March 22, 2016, 11:13:33 pm »
Delphi Pascal, but that doesn't matter because would like to use the Windows Messaging System.

I need my SFML application to provide a way so that any other application has a way to talk to it.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms644927%28v=vs.85%29.aspx#handling
https://msdn.microsoft.com/en-us/library/windows/desktop/ms632593%28v=vs.85%29.aspx

I'm open for anything that works. Friend of mine, who will be coding the other end application allready suggested it could be possible to do it via shared memory. But so far that's way out of my league

4
Window / Re: Interprocess Comunication (SendMessage / GetMessage)
« on: March 22, 2016, 10:40:54 pm »
The application would run on a Windows machine. It should have to do with SFML. Because SFML is providing the window. So I need to add this functionality somehow. From your post it seems you don't know how to do that. Or do you?

5
Window / Interprocess Comunication (SendMessage / GetMessage)
« on: March 22, 2016, 05:35:10 pm »
I'm trying very hard to find out, how to implement (atleast) the functionality to send messages to my SFML application from another application. It allready seems very hard to find a standard example, that is somewhat useful or at all a tutorial. I've never done this before in any other framework, especially not in SFML.


I personally want to realize this using the DotNet Bindings but I couldn't even find an SFML solution in c++, so I thought I should post this topic here.


Anyone here knows how this would be done?

edit: The application would run on a Windows machine.

6
DotNet / Re: creating a control (button) class
« on: March 22, 2016, 12:17:11 am »
okay, got it working.

public virtual void Update(SFML.Window.Window _window) {...

Vector2i mouse = Mouse.GetPosition(_window);

Needed to get the mouse position relative to my window.

7
DotNet / creating a control (button) class
« on: March 21, 2016, 11:06:48 pm »
Hey,
I'm trying to ceate a control (button) class, by following this c++ example:
http://alexanderx.net/create-simple-button/

But my Update method doesn't seem to operate:
public virtual void Update(RenderTarget _target) {
   if (enabled) {
      if (hovered) {
         if (Mouse.IsButtonPressed(Mouse.Button.Left)) {
            if (!pressed) {
               RaiseMouseDown();
               pressed = true;
            }
         }
         else {
            if (pressed) {
               RaiseMouseUp();
               RaiseMouseClick();
               pressed = false;
            }
         }
      }
      Vector2i mouse = Mouse.GetPosition();
      if (mouse != prevMouse) {
         prevMouse = mouse;
         FloatRect body = new FloatRect(Position + Origin, new Vector2f(Size.X, Size.Y));
         if (body.Contains(mouse.X, mouse.Y)) {
            if (!hovered) {
               RaiseMouseEnter();
               hovered = true;
            }
            RaiseMouseMove();
         }
         else if (hovered) {
            RaiseMouseLeave();
            hovered = false;
         }
      }
   }
}

Complete Class (containing button class):
http://pastebin.com/fAMj2t3s

How do I make this work?

8
DotNet / Re: problem with examples/opengl/opengl.cs @55
« on: March 20, 2016, 01:50:14 pm »
I Managed to compile the downloaded example, which didn't work earlier.

Now Visual Studio is saying:
Quote
'Glu' is obsolete: 'Use OpenTK math functions instead.'

OpenTK.Graphics.Glu.Build2DMipmap(OpenTK.Graphics.TextureTarget.Texture2D, (int)PixelInternalFormat.Rgba, (int)image.Size.X, (int)image.Size.Y, OpenTK.Graphics.PixelFormat.Rgba, OpenTK.Graphics.PixelType.UnsignedByte, image.Pixels);

what exactly does that mean? An equivalent doesn't seem to be present in that context, so how do I do what would have been done with the 'Glu' context?

9
DotNet / problem with examples/opengl/opengl.cs @55
« on: March 20, 2016, 12:45:30 pm »
Hello,
I'm trying to get an sfml opengl application to run. I've built a state-engine and made it work with sfml. Now I want to add opengl functionality, so I went down to test the opengl example.

The example from the Download doesn't compile for me. (What is "Glu.Build2DMipmap.."?)
So I went to GitHub and took the example from there wich has ALOT of changes in it.

This example would compile but Visual Studio throws me the following exception at line 55, when running the code:

Quote
An unhandled exception of type 'System.AccessViolationException' occurred in OpenTK.dll

Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

using (Image image = new Image("resources/texture.jpg")) {
   GL.GenTextures(1, out texture);
   GL.BindTexture(TextureTarget.Texture2D, texture);
   // Here's the line:
   GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)image.Size.X, (int)image.Size.Y, 0, PixelFormat.Rgba, PixelType.UnsignedByte, image.Pixels);
   GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
   GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
}

Note: I have no idea what I'm doing here yet. OpenGL is a complete new field for me.

To the GitHub-Page: https://github.com/SFML/SFML.Net/tree/master/examples/opengl

10
Feature requests / Inline instead of Outline
« on: January 30, 2015, 01:43:17 pm »
It's kinda hard to align multiple shapes along the way, when using an OutlineThickness larger than 2px. Using an "Inline" instead of an "Outline" should be able to solve that.

I can think of a way to realize this by myself for now. But only for RectangleShapes. And I also need this for ConvexShapes.

Pls add Inlines! :(

Pages: [1]