sfTransform is no longer a wrapper around a sf::Transform*, it is a simple structure

This commit is contained in:
Laurent Gomila committed 2012-05-22 17:56:01 +02:00
1 parent bf614690ad
commit bfebe0aab4
30 files changed
+179 -159

No files matched your search

+1 -1
View File
@@ -12,6 +12,7 @@ set(SRC
${SRCROOT}/Color.cpp
${INCROOT}/Color.h
${SRCROOT}/ConvertRenderStates.hpp
${SRCROOT}/ConvertTransform.hpp
${SRCROOT}/ConvexShape.cpp
${SRCROOT}/ConvexShapeStruct.h
${INCROOT}/ConvexShape.h
@@ -49,7 +50,6 @@ set(SRC
${SRCROOT}/TextureStruct.h
${INCROOT}/Texture.h
${SRCROOT}/Transform.cpp
${SRCROOT}/TransformStruct.h
${INCROOT}/Transform.h
${SRCROOT}/Transformable.cpp
${SRCROOT}/TransformableStruct.h
+7 -6
View File
@@ -28,6 +28,7 @@
#include <SFML/Graphics/CircleShape.h>
#include <SFML/Graphics/CircleShapeStruct.h>
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/ConvertTransform.hpp>
#include <SFML/Internal.h>
@@ -156,22 +157,22 @@ void sfCircleShape_scale(sfCircleShape* shape, sfVector2f factors)
////////////////////////////////////////////////////////////
const sfTransform* sfCircleShape_getTransform(const sfCircleShape* shape)
sfTransform sfCircleShape_getTransform(const sfCircleShape* shape)
{
CSFML_CHECK_RETURN(shape, NULL);
shape->Transform.This = shape->This.getTransform();
return &shape->Transform;
shape->Transform = convertTransform(shape->This.getTransform());
return shape->Transform;
}
////////////////////////////////////////////////////////////
const sfTransform* sfCircleShape_getInverseTransform(const sfCircleShape* shape)
sfTransform sfCircleShape_getInverseTransform(const sfCircleShape* shape)
{
CSFML_CHECK_RETURN(shape, NULL);
shape->InverseTransform.This = shape->This.getInverseTransform();
return &shape->InverseTransform;
shape->InverseTransform = convertTransform(shape->This.getInverseTransform());
return shape->InverseTransform;
}
+1 -1
View File
@@ -30,7 +30,7 @@
////////////////////////////////////////////////////////////
#include <SFML/Graphics/CircleShape.hpp>
#include <SFML/Graphics/TextureStruct.h>
#include <SFML/Graphics/TransformStruct.h>
#include <SFML/Graphics/Transform.h>
////////////////////////////////////////////////////////////
+2 -2
View File
@@ -30,7 +30,7 @@
////////////////////////////////////////////////////////////
#include <SFML/Graphics/RenderStates.h>
#include <SFML/Graphics/RenderStates.hpp>
#include <SFML/Graphics/TransformStruct.h>
#include <SFML/Graphics/ConvertTransform.hpp>
#include <SFML/Graphics/TextureStruct.h>
#include <SFML/Graphics/ShaderStruct.h>
@@ -45,7 +45,7 @@ inline sf::RenderStates convertRenderStates(const sfRenderStates* states)
if (states)
{
sfmlStates.blendMode = static_cast<sf::BlendMode>(states->blendMode);
sfmlStates.transform = states->transform ? states->transform->This : sf::Transform::Identity;
sfmlStates.transform = convertTransform(states->transform);
sfmlStates.texture = states->texture ? states->texture->This : NULL;
sfmlStates.shader = states->shader ? &states->shader->This : NULL;
}
@@ -22,22 +22,37 @@
//
////////////////////////////////////////////////////////////
#ifndef SFML_TRANSFORMSTRUCT_H
#define SFML_TRANSFORMSTRUCT_H
#ifndef SFML_CONVERTTRANSFORM_H
#define SFML_CONVERTTRANSFORM_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Transform.h>
#include <SFML/Graphics/Transform.hpp>
////////////////////////////////////////////////////////////
// Internal structure of sfTransform
// Convert sf::Transform to sfTransform
////////////////////////////////////////////////////////////
struct sfTransform
inline sfTransform convertTransform(const sf::Transform& transform)
{
sf::Transform This;
};
const float* m = transform.getMatrix();
sfTransform converted = {m[0], m[4], m[12], m[1], m[5], m[13], m[3], m[7], m[15]};
return converted;
}
#endif // SFML_TRANSFORMSTRUCT_H
////////////////////////////////////////////////////////////
// Convert sfTransform to sf::Transform
////////////////////////////////////////////////////////////
inline sf::Transform convertTransform(const sfTransform& transform)
{
const float* m = transform.matrix;
return sf::Transform(m[0], m[1], m[2],
m[3], m[4], m[5],
m[6], m[7], m[8]);
}
#endif // SFML_CONVERTTRANSFORM_H
+7 -6
View File
@@ -28,6 +28,7 @@
#include <SFML/Graphics/ConvexShape.h>
#include <SFML/Graphics/ConvexShapeStruct.h>
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/ConvertTransform.hpp>
#include <SFML/Internal.h>
@@ -153,22 +154,22 @@ void sfConvexShape_scale(sfConvexShape* shape, sfVector2f factors)
////////////////////////////////////////////////////////////
const sfTransform* sfConvexShape_getTransform(const sfConvexShape* shape)
sfTransform sfConvexShape_getTransform(const sfConvexShape* shape)
{
CSFML_CHECK_RETURN(shape, NULL);
shape->Transform.This = shape->This.getTransform();
return &shape->Transform;
shape->Transform = convertTransform(shape->This.getTransform());
return shape->Transform;
}
////////////////////////////////////////////////////////////
const sfTransform* sfConvexShape_getInverseTransform(const sfConvexShape* shape)
sfTransform sfConvexShape_getInverseTransform(const sfConvexShape* shape)
{
CSFML_CHECK_RETURN(shape, NULL);
shape->InverseTransform.This = shape->This.getInverseTransform();
return &shape->InverseTransform;
shape->InverseTransform = convertTransform(shape->This.getInverseTransform());
return shape->InverseTransform;
}
+1 -1
View File
@@ -30,7 +30,7 @@
////////////////////////////////////////////////////////////
#include <SFML/Graphics/ConvexShape.hpp>
#include <SFML/Graphics/TextureStruct.h>
#include <SFML/Graphics/TransformStruct.h>
#include <SFML/Graphics/Transform.h>
////////////////////////////////////////////////////////////
+7 -6
View File
@@ -28,6 +28,7 @@
#include <SFML/Graphics/RectangleShape.h>
#include <SFML/Graphics/RectangleShapeStruct.h>
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/ConvertTransform.hpp>
#include <SFML/Internal.h>
@@ -153,22 +154,22 @@ void sfRectangleShape_scale(sfRectangleShape* shape, sfVector2f factors)
////////////////////////////////////////////////////////////
const sfTransform* sfRectangleShape_getTransform(const sfRectangleShape* shape)
sfTransform sfRectangleShape_getTransform(const sfRectangleShape* shape)
{
CSFML_CHECK_RETURN(shape, NULL);
shape->Transform.This = shape->This.getTransform();
return &shape->Transform;
shape->Transform = convertTransform(shape->This.getTransform());
return shape->Transform;
}
////////////////////////////////////////////////////////////
const sfTransform* sfRectangleShape_getInverseTransform(const sfRectangleShape* shape)
sfTransform sfRectangleShape_getInverseTransform(const sfRectangleShape* shape)
{
CSFML_CHECK_RETURN(shape, NULL);
shape->InverseTransform.This = shape->This.getInverseTransform();
return &shape->InverseTransform;
shape->InverseTransform = convertTransform(shape->This.getInverseTransform());
return shape->InverseTransform;
}
+1 -1
View File
@@ -30,7 +30,7 @@
////////////////////////////////////////////////////////////
#include <SFML/Graphics/RectangleShape.hpp>
#include <SFML/Graphics/TextureStruct.h>
#include <SFML/Graphics/TransformStruct.h>
#include <SFML/Graphics/Transform.h>
////////////////////////////////////////////////////////////
+3 -3
View File
@@ -28,7 +28,7 @@
#include <SFML/Graphics/Shader.h>
#include <SFML/Graphics/ShaderStruct.h>
#include <SFML/Graphics/TextureStruct.h>
#include <SFML/Graphics/TransformStruct.h>
#include <SFML/Graphics/ConvertTransform.hpp>
#include <SFML/Internal.h>
#include <SFML/CallbackStream.h>
@@ -196,9 +196,9 @@ void sfShader_setColorParameter(sfShader* shader, const char* name, sfColor colo
////////////////////////////////////////////////////////////
void sfShader_setTransformParameter(sfShader* shader, const char* name, const sfTransform* transform)
void sfShader_setTransformParameter(sfShader* shader, const char* name, sfTransform transform)
{
CSFML_CALL(shader, setParameter(name, transform ? transform->This : sf::Transform::Identity));
CSFML_CALL(shader, setParameter(name, convertTransform(transform)));
}
+7 -6
View File
@@ -28,6 +28,7 @@
#include <SFML/Graphics/Shape.h>
#include <SFML/Graphics/ShapeStruct.h>
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/ConvertTransform.hpp>
#include <SFML/Internal.h>
@@ -146,22 +147,22 @@ void sfShape_scale(sfShape* shape, sfVector2f factors)
////////////////////////////////////////////////////////////
const sfTransform* sfShape_getTransform(const sfShape* shape)
sfTransform sfShape_getTransform(const sfShape* shape)
{
CSFML_CHECK_RETURN(shape, NULL);
shape->Transform.This = shape->This.getTransform();
return &shape->Transform;
shape->Transform = convertTransform(shape->This.getTransform());
return shape->Transform;
}
////////////////////////////////////////////////////////////
const sfTransform* sfShape_getInverseTransform(const sfShape* shape)
sfTransform sfShape_getInverseTransform(const sfShape* shape)
{
CSFML_CHECK_RETURN(shape, NULL);
shape->InverseTransform.This = shape->This.getInverseTransform();
return &shape->InverseTransform;
shape->InverseTransform = convertTransform(shape->This.getInverseTransform());
return shape->InverseTransform;
}
+1 -1
View File
@@ -31,7 +31,7 @@
#include <SFML/Graphics/Shape.h>
#include <SFML/Graphics/Shape.hpp>
#include <SFML/Graphics/TextureStruct.h>
#include <SFML/Graphics/TransformStruct.h>
#include <SFML/Graphics/Transform.h>
////////////////////////////////////////////////////////////
+7 -6
View File
@@ -29,6 +29,7 @@
#include <SFML/Graphics/SpriteStruct.h>
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/Image.hpp>
#include <SFML/Graphics/ConvertTransform.hpp>
#include <SFML/Internal.h>
@@ -157,22 +158,22 @@ void sfSprite_scale(sfSprite* sprite, sfVector2f factors)
////////////////////////////////////////////////////////////
const sfTransform* sfSprite_getTransform(const sfSprite* sprite)
sfTransform sfSprite_getTransform(const sfSprite* sprite)
{
CSFML_CHECK_RETURN(sprite, NULL);
sprite->Transform.This = sprite->This.getTransform();
return &sprite->Transform;
sprite->Transform = convertTransform(sprite->This.getTransform());
return sprite->Transform;
}
////////////////////////////////////////////////////////////
const sfTransform* sfSprite_getInverseTransform(const sfSprite* sprite)
sfTransform sfSprite_getInverseTransform(const sfSprite* sprite)
{
CSFML_CHECK_RETURN(sprite, NULL);
sprite->InverseTransform.This = sprite->This.getInverseTransform();
return &sprite->InverseTransform;
sprite->InverseTransform = convertTransform(sprite->This.getInverseTransform());
return sprite->InverseTransform;
}
+1 -1
View File
@@ -30,7 +30,7 @@
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Sprite.hpp>
#include <SFML/Graphics/TextureStruct.h>
#include <SFML/Graphics/TransformStruct.h>
#include <SFML/Graphics/Transform.h>
////////////////////////////////////////////////////////////
+7 -6
View File
@@ -29,6 +29,7 @@
#include <SFML/Graphics/TextStruct.h>
#include <SFML/Graphics/Font.h>
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/ConvertTransform.hpp>
#include <SFML/Internal.h>
@@ -157,22 +158,22 @@ void sfText_scale(sfText* text, sfVector2f factors)
////////////////////////////////////////////////////////////
const sfTransform* sfText_getTransform(const sfText* text)
sfTransform sfText_getTransform(const sfText* text)
{
CSFML_CHECK_RETURN(text, NULL);
text->Transform.This = text->This.getTransform();
return &text->Transform;
text->Transform = convertTransform(text->This.getTransform());
return text->Transform;
}
////////////////////////////////////////////////////////////
const sfTransform* sfText_getInverseTransform(const sfText* text)
sfTransform sfText_getInverseTransform(const sfText* text)
{
CSFML_CHECK_RETURN(text, NULL);
text->InverseTransform.This = text->This.getInverseTransform();
return &text->InverseTransform;
text->InverseTransform = convertTransform(text->This.getInverseTransform());
return text->InverseTransform;
}
+1 -1
View File
@@ -31,7 +31,7 @@
#include <SFML/Graphics/Text.hpp>
#include <SFML/Graphics/FontStruct.h>
#include <SFML/Graphics/Rect.h>
#include <SFML/Graphics/TransformStruct.h>
#include <SFML/Graphics/Transform.h>
#include <string>
+43 -43
View File
@@ -26,58 +26,47 @@
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Transform.h>
#include <SFML/Graphics/TransformStruct.h>
#include <SFML/Graphics/Transform.hpp>
#include <SFML/Graphics/ConvertTransform.hpp>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
sfTransform* sfTransform_create(void)
sfTransform sfTransform_Identity =
{
return new sfTransform;
}
1, 0, 0,
0, 1, 0,
0, 0, 1,
};
////////////////////////////////////////////////////////////
sfTransform* sfTransform_createFromMatrix(float a00, float a01, float a02,
float a10, float a11, float a12,
float a20, float a21, float a22)
sfTransform sfTransform_fromMatrix(float a00, float a01, float a02,
float a10, float a11, float a12,
float a20, float a21, float a22)
{
sfTransform* transform = new sfTransform;
transform->This = sf::Transform(a00, a01, a02, a10, a11, a12, a20, a21, a22);
sfTransform transform = {a00, a01, a02, a10, a11, a12, a20, a21, a22};
return transform;
}
////////////////////////////////////////////////////////////
sfTransform* sfTransform_copy(sfTransform* transform)
{
CSFML_CHECK_RETURN(transform, NULL);
return new sfTransform(*transform);
}
////////////////////////////////////////////////////////////
void sfTransform_destroy(sfTransform* transform)
{
delete transform;
}
////////////////////////////////////////////////////////////
const float* sfTransform_getMatrix(const sfTransform* transform)
{
CSFML_CALL_RETURN(transform, getMatrix(), NULL);
}
////////////////////////////////////////////////////////////
void sfTransform_getInverse(const sfTransform* transform, sfTransform* result)
void sfTransform_getMatrix(const sfTransform* transform, float* matrix)
{
CSFML_CHECK(transform);
if (result)
result->This = transform->This.getInverse();
sf::Transform converted = convertTransform(*transform);
if (matrix)
std::memcpy(matrix, converted.getMatrix(), 16 * sizeof(float));
}
////////////////////////////////////////////////////////////
sfTransform sfTransform_getInverse(const sfTransform* transform)
{
CSFML_CHECK(transform);
return convertTransform(convertTransform(*transform).getInverse());
}
@@ -87,7 +76,7 @@ sfVector2f sfTransform_transformPoint(const sfTransform* transform, sfVector2f p
sfVector2f p = {0, 0};
CSFML_CHECK_RETURN(transform, p);
sf::Vector2f sfmlPoint = transform->This.transformPoint(point.x, point.y);
sf::Vector2f sfmlPoint = convertTransform(*transform).transformPoint(point.x, point.y);
p.x = sfmlPoint.x;
p.y = sfmlPoint.y;
@@ -102,7 +91,7 @@ sfFloatRect sfTransform_transformRect(const sfTransform* transform, sfFloatRect
sfFloatRect rect = {0, 0, 0, 0};
CSFML_CHECK_RETURN(transform, rect);
sf::FloatRect sfmlRect = transform->This.transformRect(sf::FloatRect(rectangle.left, rectangle.top, rectangle.width, rectangle.height));
sf::FloatRect sfmlRect = convertTransform(*transform).transformRect(sf::FloatRect(rectangle.left, rectangle.top, rectangle.width, rectangle.height));
rect.left = sfmlRect.left;
rect.top = sfmlRect.top;
@@ -116,42 +105,53 @@ sfFloatRect sfTransform_transformRect(const sfTransform* transform, sfFloatRect
////////////////////////////////////////////////////////////
void sfTransform_combine(sfTransform* transform, const sfTransform* other)
{
CSFML_CHECK(transform);
CSFML_CHECK(other);
CSFML_CALL(transform, combine(other->This));
*transform = convertTransform(convertTransform(*transform).combine(convertTransform(*other)));
}
////////////////////////////////////////////////////////////
void sfTransform_translate(sfTransform* transform, float x, float y)
{
CSFML_CALL(transform, translate(x, y));
CSFML_CHECK(transform);
*transform = convertTransform(convertTransform(*transform).translate(x, y));
}
////////////////////////////////////////////////////////////
void sfTransform_rotate(sfTransform* transform, float angle)
{
CSFML_CALL(transform, rotate(angle));
CSFML_CHECK(transform);
*transform = convertTransform(convertTransform(*transform).rotate(angle));
}
////////////////////////////////////////////////////////////
void sfTransform_rotateWithCenter(sfTransform* transform, float angle, float centerX, float centerY)
{
CSFML_CALL(transform, rotate(angle, centerX, centerY));
CSFML_CHECK(transform);
*transform = convertTransform(convertTransform(*transform).rotate(angle, centerX, centerY));
}
////////////////////////////////////////////////////////////
void sfTransform_scale(sfTransform* transform, float scaleX, float scaleY)
{
CSFML_CALL(transform, scale(scaleX, scaleY));
CSFML_CHECK(transform);
*transform = convertTransform(convertTransform(*transform).scale(scaleX, scaleY));
}
////////////////////////////////////////////////////////////
void sfTransform_scaleWithCenter(sfTransform* transform, float scaleX, float scaleY, float centerX, float centerY)
{
CSFML_CALL(transform, scale(scaleX, scaleY, centerX, centerY));
CSFML_CHECK(transform);
*transform = convertTransform(convertTransform(*transform).scale(scaleX, scaleY, centerX, centerY));
}
+7 -6
View File
@@ -27,6 +27,7 @@
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Transformable.h>
#include <SFML/Graphics/TransformableStruct.h>
#include <SFML/Graphics/ConvertTransform.hpp>
#include <SFML/Internal.h>
@@ -154,20 +155,20 @@ void sfTransformable_scale(sfTransformable* transformable, sfVector2f factors)
////////////////////////////////////////////////////////////
const sfTransform* sfTransformable_getTransform(const sfTransformable* transformable)
sfTransform sfTransformable_getTransform(const sfTransformable* transformable)
{
CSFML_CHECK_RETURN(transformable, NULL);
transformable->Transform.This = transformable->This.getTransform();
return &transformable->Transform;
transformable->Transform = convertTransform(transformable->This.getTransform());
return transformable->Transform;
}
////////////////////////////////////////////////////////////
const sfTransform* sfTransformable_getInverseTransform(const sfTransformable* transformable)
sfTransform sfTransformable_getInverseTransform(const sfTransformable* transformable)
{
CSFML_CHECK_RETURN(transformable, NULL);
transformable->InverseTransform.This = transformable->This.getInverseTransform();
return &transformable->InverseTransform;
transformable->InverseTransform = convertTransform(transformable->This.getInverseTransform());
return transformable->InverseTransform;
}
+1 -1
View File
@@ -29,7 +29,7 @@
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Transformable.hpp>
#include <SFML/Graphics/TransformStruct.h>
#include <SFML/Graphics/Transform.h>
////////////////////////////////////////////////////////////