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

Pages: 1 ... 4 5 [6]
76
Is it possible with the bmp format ?

Quote
An alpha channel (for transparency) may be stored in a separate file


http://en.wikipedia.org/wiki/Windows_bitmap

77
Quote
If you want a perfect alpha channel then just setup your image properly before loading it. Creating the mask at runtime is a helper tool if you want fast results, but it's not the right way of doing things at the end.


Can you explain what is the right way ?

78
General / SFML and Box2D
« on: April 15, 2009, 09:13:00 am »
Toolbox is a class of mine. It provides static methods such as meter to pixel

Code: [Select]

float ToolBox::toPix(float meters)
{
return meters*FACTOR;
}


Where FACTOR is a static float of 30.0f to convert from box2D coordinates in meters to SFML in pixels.

As said before, Box2D uses rads and SFML uses degrees so you need to convert too :


Code: [Select]

this->myDrawable->SetPosition(ToolBox::b2VecToSfVec(this->myBody->GetPosition())); this->myDrawable->SetRotation(-ToolBox::getInstance()->toDegree(this->myBody->GetAngle()));

79
General / SFML and Box2D
« on: April 14, 2009, 05:15:23 pm »
I'm using it this way :

Code: [Select]

if((*shape).GetNbPoints()<=8)
{// box2D can handle shapes with 8 points max

b2PolygonDef shapeDef;
shapeDef.vertexCount = (*shape).GetNbPoints();

// we set the shape at 0,0 so that the global SFML coordinates fit the Box2D coordinates system

(*shape).SetPosition(0,0);

for(unsigned int j=0; j<(unsigned int)shapeDef.vertexCount; ++j)
{// for each point of the shape
shapeDef.vertices[j].Set(ToolBox::toMeter((*shape).TransformToGlobal((*shape).GetPointPosition(j)).x),ToolBox::toMeter((*shape).TransformToGlobal((*shape).GetPointPosition(j)).y));
}

// we set the common shape params
// set the box density
shapeDef.density = density;

// override the default friction
shapeDef.friction = friction;

// finally we add the shape to the body
this->myBody->CreateShape(&(shapeDef));
}
else
{// SFML circle has more than 8 points ... if your shape has more than 8 points it'll be considered as a circle

// circle definition
b2CircleDef circleShape;

float centerPosX, pointPosX, centerPosY, pointPosY;

centerPosX = (*shape).GetPosition().x; // we set the xpos of the center
centerPosY = (*shape).GetPosition().y; // we set the y pos of the center

pointPosX = (*shape).GetPointPosition(1).x; // xpos of a point of the circle
pointPosY = (*shape).GetPointPosition(1).y; // ypos of the same point

// we calculate the radius sqrt((XA-XB)²+(YA-YB)²)
circleShape.radius = ((centerPosX-pointPosX)*(centerPosX-pointPosX));
circleShape.radius +=  ((centerPosY-pointPosY)*(centerPosY-pointPosY));
circleShape.radius = ToolBox::toMeter(sqrt(circleShape.radius));

// we set the density
circleShape.density = density;

// we set the friction
circleShape.friction = friction;

// finally we create the shape from the circleShape
this->myBody->CreateShape(&(circleShape));

}

Pages: 1 ... 4 5 [6]