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 - Dark Byte

Pages: [1] 2
1
General discussions / Need help with scaling Box2D coords
« on: July 02, 2011, 07:34:12 pm »
Nvm it is fixed  :)

2
General discussions / Need help with scaling Box2D coords
« on: July 02, 2011, 03:51:40 pm »
Hi, I cannot convert the Box2D coords to pixels. Everything I have tried does the same just on a different scale. Does anyone know how to convert them?

3
General / Need help programming GUI
« on: January 02, 2011, 06:53:36 am »
I am writing a GUI and I need help with scroll bars. I have this it works but sometimes if the member contentSize is a certain value it fails (it just freezes the program). I have tried to find the problem but have failed.
Here is the code

Declaration
Code: [Select]

class VScrollBar : public Object
{
int mousepos[2];
bool mousedown;
public:
int pos;
float windowSize;
float contentSize;
float minGripSize;

VScrollBar();
float CalculateGripRatio();
float CalculateGripSize();
float CalculateScrollSize();
float CalculateScrollRatio();
float CalculateGripPosition();
void ValidatePos();
void Draw(sf::RenderWindow*);
protected:
void MouseScroll(int delta)
{
pos -= delta;
}
void MouseHover(float fx, float fy)
{
mousepos[1] = mousepos[0];
mousepos[0] = fy;
if ( mousedown )
{
float gripSize = CalculateGripSize();
float gripPos = CalculateScrollSize() * CalculateScrollRatio();
if ( fy >= gripPos && fy <= gripPos + gripSize )
pos += mousepos[0]-mousepos[1];
}
}

void MousePressed(int i)
{
if ( i == MOUSE_BUTTON_R )
{
/* float mouseRatio = *mousepos/wY;
pos = mouseRatio*contentSize;*/
mousedown = true;
}
}

void MouseReleased(int i)
{
if ( i == MOUSE_BUTTON_R )
mousedown = false;
}

} ;


Definition
Code: [Select]

GUI::VScrollBar::VScrollBar()
{
     wY = 100;
     windowSize = 100;
     contentSize = 200;
     minGripSize = 5;
     pos = 0;
     *(mousepos) = 0;
     *(mousepos + 1) = 0;
     mousedown = false;
}

float GUI::VScrollBar::CalculateGripRatio()
{
     if ( contentSize == 0.f )
          return 0.f;
     return windowSize/contentSize;
}

float GUI::VScrollBar::CalculateGripSize()
{
     float tmp = wY * CalculateGripRatio();
     tmp = tmp < 3?3:tmp;
     return tmp<minGripSize?minGripSize:tmp;
}

float GUI::VScrollBar::CalculateScrollSize()
{
     return wY - CalculateGripSize();
}

float GUI::VScrollBar::CalculateScrollRatio()
{
     return pos/contentSize;
}

void GUI::VScrollBar::ValidatePos()
{
     if ( pos < 0 ) pos = 0;
     float gripPos = CalculateScrollSize() * CalculateScrollRatio();
     while ( gripPos > CalculateScrollSize() )
     {
          pos--;
          gripPos = CalculateScrollSize() * CalculateScrollRatio();
     }
}

void GUI::VScrollBar::Draw(sf::RenderWindow* RENW)
{
     ValidatePos();
     int gripSize = (int) CalculateGripSize();
     gripSize = gripSize < minGripSize?minGripSize:gripSize;
     float gripPos = CalculateScrollSize() * CalculateScrollRatio();
     sf::Shape grip = sf::Shape::Rectangle(pX+2, pY + gripPos, pX+wX-1,pY+gripPos+gripSize,sf::Color(70,70,70),true,sf::Color(200,200,200));
     sf::Shape track = sf::Shape::Rectangle(pX+1, pY, pX+wX,pY+wY,sf::Color(200,200,200),true,sf::Color(70,70,70));
     RENW->Draw(track);
     RENW->Draw(grip);
}

4
General / Separating Axis Theorem
« on: December 05, 2010, 07:53:47 pm »
Alright thanks.

5
General / Separating Axis Theorem
« on: December 05, 2010, 04:11:30 am »
I have already searched google I found this http://www.gamedev.net/reference/programming/features/2dRotatedRectCollision/page2.asp

Step two reads: "[...] project the vectors representing the four corners of each rectangle onto each of the axes. [...]"

I know how to project them onto the axes. But somehow I am stuck I have this:

Code: [Select]

sf::Vector2f Project (sf::Vector2f& v1, sf::Vector2f& v2)
{
sf::Vector2f vec;

float x_ = v1.x * v2.x;
float y_ = v1.y * v2.y;
float d = pow(v2.x, 2) + pow(v2.y, 2);
x_ = (x_ + y_)/d;

vec.x = x_ * v2.x;
vec.y = x_ * v2.y;

return vec;
}

float Dot (sf::Vector2f& v1, sf::Vector2f& v2)
{
return v1.x * v2.x + v1.y * v2.y;
}

sf::Rect<sf::Vector2f> GetRectanglePoints (sf::Shape& Obj)
{
if ( Obj.GetNbPoints() == 4 )
{
sf::Rect<sf::Vector2f> ret;
ret.Top = Obj.GetPointPosition(0); // top-left corner
ret.Right = Obj.GetPointPosition(1); // top-right corner
ret.Bottom = Obj.GetPointPosition(2); // bottom-right corner
ret.Left = Obj.GetPointPosition(3); // bottom-left corner

return ret;
}
}

bool RectsCollide (sf::Rect<sf::Vector2f>& rect1, sf::Rect<sf::Vector2f>& rect2)
{
// Find the axis
sf::Vector2f Axis[4];
Axis[0].x = rect1.Right.x - rect1.Top.x;
Axis[0].y = rect1.Right.y - rect1.Top.y;
Axis[1].x = rect1.Right.x - rect1.Bottom.x;
Axis[1].y = rect1.Right.y - rect1.Bottom.y;
Axis[2].x = rect2.Top.x - rect2.Left.x;
Axis[2].x = rect2.Top.y - rect2.Left.y;
Axis[3].x = rect2.Top.x - rect2.Right.x;
Axis[3].y = rect2.Top.y - rect2.Right.y;

// Project the vectors onto the axis


Now what do I do? I mean do I for each vertex in both rects project them to each axis? or only to a specific one?

6
General / Separating Axis Theorem
« on: December 05, 2010, 02:36:30 am »
Where can I learn how to implement the Separating Axis Theorem into one of my projects?

7
Graphics / [Win API] Can I use an image resource as sf::Image?
« on: December 04, 2010, 07:27:41 am »
Is that possible?

8
Network / Entry Point not Found
« on: December 03, 2010, 02:14:49 am »
No it is certainly 1.6. As 1.6 is the only version I have ever installed.

9
Network / Entry Point not Found
« on: December 02, 2010, 07:40:22 am »
Every compiled program that uses sfml-network gives me this this runtime error: The procedure entry point _ZN2sf9IPAddressC1Ev could not be located in the DLL sfml-network.dll

10
Graphics / is it possible to get fonts size in pixles?
« on: November 06, 2010, 09:56:58 pm »
Yes that is it thanks.

11
Graphics / is it possible to get fonts size in pixles?
« on: November 06, 2010, 05:27:09 pm »
Is it possible to get the width and height of an sf::String object dependent on the font and size in pixels?

12
General / 50% of CPU used to power a simple program
« on: October 24, 2010, 07:40:52 pm »
Oh lol thanks.

13
General / 50% of CPU used to power a simple program
« on: October 24, 2010, 02:25:53 am »
I wanted to know why so much CPU is required to run this
Code: [Select]

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>

int main()
{
sf::RenderWindow App(sf::VideoMode(800,600,32), "Test app");
sf::Image Back;
if ( !Back.LoadFromFile("background.png") )
App.Close();

sf::Sprite BackSPR;
BackSPR.SetImage(Back);
while ( App.IsOpened() )
{
App.Clear();
sf::Event Event;
while ( App.GetEvent(Event) )
{
if ( Event.Type == sf::Event::Closed )
App.Close();
}
App.Draw(BackSPR);

App.Display();
}

return 0;
}


The compiled program uses about 50% of my CPU.
Some computer info:
RAM 8gb
HDD 1tb
processor 2.6ghz

I am using MinGW to compile.

14
Graphics / need help with image manager.
« on: October 16, 2010, 05:01:46 pm »
I found the problem. It is with RetrieveImage. I made the map public and when I use something like
Code: [Select]

Sprite.SetImage( IM.Data["gfx/player.bmp"] );


It works. So I need to find the problem with RetrieveImage.

15
Graphics / need help with image manager.
« on: October 15, 2010, 11:45:36 pm »
Does anyone know why the images are white? With the correct width and height.

Pages: [1] 2
anything