Просмотр исходного кода

Added 2D camera mode functions

Removed BeginDrawingEx()
Added Begin2dMode() and End2dMode()
pull/114/head
Ray 9 лет назад
Родитель
Сommit
fa98289ddb
2 измененных файлов: 29 добавлений и 18 удалений
  1. +27
    -17
      src/core.c
  2. +2
    -1
      src/raylib.h

+ 27
- 17
src/core.c Просмотреть файл

@ -524,23 +524,6 @@ void BeginDrawing(void)
// NOTE: Not required with OpenGL 3.3+
}
// Setup drawing canvas with 2d camera
void BeginDrawingEx(Camera2D camera)
{
BeginDrawing();
// Camera rotation and scaling is always relative to target
Matrix matOrigin = MatrixTranslate(-camera.target.x, -camera.target.y, 0.0f);
Matrix matRotation = MatrixRotate((Vector3){ 0.0f, 0.0f, 1.0f }, camera.rotation*DEG2RAD);
Matrix matScale = MatrixScale(camera.zoom, camera.zoom, 1.0f);
Matrix matTranslation = MatrixTranslate(camera.offset.x + camera.target.x, camera.offset.y + camera.target.y, 0.0f);
Matrix matTransform = MatrixMultiply(MatrixMultiply(matOrigin, MatrixMultiply(matScale, matRotation)), matTranslation);
rlMultMatrixf(MatrixToFloat(matTransform));
}
// End canvas drawing and Swap Buffers (Double Buffering)
void EndDrawing(void)
{
@ -569,6 +552,33 @@ void EndDrawing(void)
}
}
// Initialize 2D mode with custom camera
void Begin2dMode(Camera2D camera)
{
rlglDraw(); // Draw Buffers (Only OpenGL 3+ and ES2)
rlLoadIdentity(); // Reset current matrix (MODELVIEW)
// Camera rotation and scaling is always relative to target
Matrix matOrigin = MatrixTranslate(-camera.target.x, -camera.target.y, 0.0f);
Matrix matRotation = MatrixRotate((Vector3){ 0.0f, 0.0f, 1.0f }, camera.rotation*DEG2RAD);
Matrix matScale = MatrixScale(camera.zoom, camera.zoom, 1.0f);
Matrix matTranslation = MatrixTranslate(camera.offset.x + camera.target.x, camera.offset.y + camera.target.y, 0.0f);
Matrix matTransform = MatrixMultiply(MatrixMultiply(matOrigin, MatrixMultiply(matScale, matRotation)), matTranslation);
rlMultMatrixf(MatrixToFloat(matTransform));
}
// Ends 2D mode custom camera usage
void End2dMode(void)
{
rlglDraw(); // Draw Buffers (Only OpenGL 3+ and ES2)
rlLoadIdentity(); // Reset current matrix (MODELVIEW)
}
// Initializes 3D mode for drawing (Camera setup)
void Begin3dMode(Camera camera)
{

+ 2
- 1
src/raylib.h Просмотреть файл

@ -576,9 +576,10 @@ void DisableCursor(void); // Disables cursor
void ClearBackground(Color color); // Sets Background Color
void BeginDrawing(void); // Setup drawing canvas to start drawing
void BeginDrawingEx(Camera2D camera); // Setup drawing canvas with 2d camera
void EndDrawing(void); // End canvas drawing and Swap Buffers (Double Buffering)
void Begin2dMode(Camera2D camera); // Initialize 2D mode with custom camera
void End2dMode(void); // Ends 2D mode custom camera usage
void Begin3dMode(Camera camera); // Initializes 3D mode for drawing (Camera setup)
void End3dMode(void); // Ends 3D mode and returns to default 2D orthographic mode
void BeginTextureMode(RenderTexture2D target); // Initializes render texture for drawing

Загрузка…
Отмена
Сохранить