this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Added x and y zoom control to GPU_Camera. Split camera matrix and fixed get_camera_matrix() math so that it represents just a View matrix. Added GPU_ResetProjection() to reset the orthographic projection that the camera uses by default. Added camera-matrix test.

+332 -81
+6 -2
include/SDL_gpu.h
··· 328 328 { 329 329 float x, y, z; 330 330 float angle; 331 - float zoom; 331 + float zoom_x, zoom_y; 332 332 float z_near, z_far; // z clipping planes 333 + bool use_centered_origin; // move rotation/scaling origin to the center of the camera's view 333 334 } GPU_Camera; 334 335 335 336 ··· 1050 1051 /*! Resets the given target's viewport to the entire target area. */ 1051 1052 DECLSPEC void SDLCALL GPU_UnsetViewport(GPU_Target* target); 1052 1053 1053 - /*! \return A GPU_Camera with position (0, 0, 0), angle of 0, zoom of 1, and near/far clipping planes of -100 and 100. */ 1054 + /*! \return A GPU_Camera with position (0, 0, 0), angle of 0, zoom of 1, centered origin, and near/far clipping planes of -100 and 100. */ 1054 1055 DECLSPEC GPU_Camera SDLCALL GPU_GetDefaultCamera(void); 1055 1056 1056 1057 /*! \return The camera of the given render target. If target is NULL, returns the default camera. */ ··· 1381 1382 1382 1383 /*! Allocate new matrices for the given stack. */ 1383 1384 DECLSPEC void SDLCALL GPU_InitMatrixStack(GPU_MatrixStack* stack); 1385 + 1386 + /*! Reapplies the default orthographic projection matrix, based on camera and coordinate settings. */ 1387 + DECLSPEC void SDLCALL GPU_ResetProjection(void); 1384 1388 1385 1389 /*! Changes matrix mode to either GPU_PROJECTION or GPU_MODELVIEW. Further matrix stack operations manipulate that particular stack. */ 1386 1390 DECLSPEC void SDLCALL GPU_MatrixMode(int matrix_mode);
+1 -1
src/SDL_gpu.c
··· 894 894 895 895 GPU_Camera GPU_GetDefaultCamera(void) 896 896 { 897 - GPU_Camera cam = {0.0f, 0.0f, 0.0f, 0.0f, 1.0f, -100.0f, 100.0f}; 897 + GPU_Camera cam = {0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, -100.0f, 100.0f, true}; 898 898 return cam; 899 899 } 900 900
+18
src/SDL_gpu_matrix.c
··· 68 68 } 69 69 70 70 71 + void GPU_ResetProjection(void) 72 + { 73 + GPU_Target* target = GPU_GetContextTarget(); 74 + if(target == NULL) 75 + return; 76 + 77 + GPU_bool invert = (target->image != NULL); 78 + 79 + // Set up default projection 80 + float* projection_matrix = GPU_GetProjection(); 81 + GPU_MatrixIdentity(projection_matrix); 82 + 83 + if(!invert ^ GPU_GetCoordinateMode()) 84 + GPU_MatrixOrtho(projection_matrix, 0, target->w, target->h, 0, target->camera.z_near, target->camera.z_far); 85 + else 86 + GPU_MatrixOrtho(projection_matrix, 0, target->w, 0, target->h, target->camera.z_near, target->camera.z_far); // Special inverted orthographic projection because tex coords are inverted already for render-to-texture 87 + } 88 + 71 89 // Column-major 72 90 #define INDEX(row,col) ((col)*4 + (row)) 73 91
+36 -23
src/renderer_GL_common.inl
··· 1154 1154 1155 1155 static GPU_bool equal_cameras(GPU_Camera a, GPU_Camera b) 1156 1156 { 1157 - return (a.x == b.x && a.y == b.y && a.z == b.z && a.angle == b.angle && a.zoom == b.zoom); 1157 + return (a.x == b.x && a.y == b.y && a.z == b.z && a.angle == b.angle && a.zoom_x == b.zoom_x && a.zoom_y == b.zoom_y && a.use_centered_origin == b.use_centered_origin); 1158 1158 } 1159 1159 1160 1160 static void changeCamera(GPU_Target* target) ··· 1171 1171 { 1172 1172 GPU_CONTEXT_DATA* cdata = (GPU_CONTEXT_DATA*)GPU_GetContextTarget()->context->data; 1173 1173 GPU_Target* target = cdata->last_target; 1174 - GPU_bool invert = cdata->last_camera_inverted; 1175 1174 float offsetX, offsetY; 1176 1175 1177 1176 GPU_MatrixIdentity(result); 1178 1177 1179 - // Now multiply in the projection part 1180 - if(!invert ^ GPU_GetCoordinateMode()) 1181 - GPU_MatrixOrtho(result, target->camera.x, target->w + target->camera.x, target->h + target->camera.y, target->camera.y, target->camera.z_near, target->camera.z_far); 1182 - else 1183 - GPU_MatrixOrtho(result, target->camera.x, target->w + target->camera.x, target->camera.y, target->h + target->camera.y, target->camera.z_near, target->camera.z_far); // Special inverted orthographic projection because tex coords are inverted already for render-to-texture 1184 - 1185 - // First the modelview part 1186 - offsetX = target->w/2.0f; 1187 - offsetY = target->h/2.0f; 1188 - GPU_MatrixTranslate(result, offsetX, offsetY, 0); 1178 + GPU_MatrixTranslate(result, -target->camera.x, -target->camera.y, -target->camera.z); 1179 + 1180 + if(target->camera.use_centered_origin) 1181 + { 1182 + offsetX = target->w/2.0f; 1183 + offsetY = target->h/2.0f; 1184 + GPU_MatrixTranslate(result, offsetX, offsetY, 0); 1185 + } 1186 + 1189 1187 GPU_MatrixRotate(result, target->camera.angle, 0, 0, 1); 1190 - GPU_MatrixTranslate(result, -offsetX, -offsetY, 0); 1191 - 1192 - GPU_MatrixTranslate(result, target->camera.x + offsetX, target->camera.y + offsetY, 0); 1193 - GPU_MatrixScale(result, target->camera.zoom, target->camera.zoom, 1.0f); 1194 - GPU_MatrixTranslate(result, -target->camera.x - offsetX, -target->camera.y - offsetY, 0); 1195 - 1188 + GPU_MatrixScale(result, target->camera.zoom_x, target->camera.zoom_y, 1.0f); 1189 + 1190 + if(target->camera.use_centered_origin) 1191 + GPU_MatrixTranslate(result, -offsetX, -offsetY, 0); 1196 1192 } 1197 1193 1198 1194 ··· 1206 1202 float cam_matrix[16]; 1207 1203 get_camera_matrix(cam_matrix); 1208 1204 1209 - GPU_MultiplyAndAssign(m, cam_matrix); 1205 + GPU_MultiplyAndAssign(cam_matrix, m); 1210 1206 1211 1207 glMatrixMode(GL_PROJECTION); 1212 1208 glLoadMatrixf(p); ··· 1605 1601 target->camera = GPU_GetDefaultCamera(); 1606 1602 target->use_camera = GPU_TRUE; 1607 1603 1604 + 1608 1605 target->use_depth_test = GPU_FALSE; 1609 1606 target->use_depth_write = GPU_TRUE; 1610 1607 ··· 1708 1705 #if defined(SDL_GPU_USE_FIXED_FUNCTION_PIPELINE) || defined(SDL_GPU_USE_ARRAY_PIPELINE) 1709 1706 glColor4f(1.0f, 1.0f, 1.0f, 1.0f); 1710 1707 #endif 1711 - 1708 + 1709 + 1712 1710 // Set up camera 1713 1711 applyTargetCamera(target); 1712 + 1713 + // Set up default projection 1714 + // Maybe replace with GPU_ResetProjection()? 1715 + float* projection_matrix = target->context->projection_matrix.matrix[0]; 1716 + if(!cdata->last_camera_inverted ^ GPU_GetCoordinateMode()) 1717 + GPU_MatrixOrtho(projection_matrix, 0, target->w, target->h, 0, target->camera.z_near, target->camera.z_far); 1718 + else 1719 + GPU_MatrixOrtho(projection_matrix, 0, target->w, 0, target->h, target->camera.z_near, target->camera.z_far); // Special inverted orthographic projection because tex coords are inverted already for render-to-texture 1720 + 1714 1721 1715 1722 renderer->impl->SetLineThickness(renderer, 1.0f); 1716 1723 ··· 2234 2241 2235 2242 return is_fullscreen; 2236 2243 } 2237 - 2238 2244 2239 2245 static GPU_Camera SetCamera(GPU_Renderer* renderer, GPU_Target* target, GPU_Camera* cam) 2240 2246 { ··· 4809 4815 { 4810 4816 float mvp[16]; 4811 4817 4812 - // MVP = P * MV 4813 - GPU_MatrixMultiply(mvp, GPU_GetProjection(), GPU_GetModelView()); 4818 + // MVP = P * V * M 4819 + 4820 + // P 4821 + GPU_MatrixCopy(mvp, GPU_GetProjection()); 4822 + 4814 4823 4824 + // V 4815 4825 if(dest->use_camera) 4816 4826 { 4817 4827 float cam_matrix[16]; ··· 4819 4829 4820 4830 GPU_MultiplyAndAssign(mvp, cam_matrix); 4821 4831 } 4832 + 4833 + // M 4834 + GPU_MultiplyAndAssign(mvp, GPU_GetModelView()); 4822 4835 4823 4836 glUniformMatrix4fv(context->current_shader_block.modelViewProjection_loc, 1, 0, mvp); 4824 4837 }
+3
tests/CMakeLists.txt
··· 158 158 add_executable(depth-test depth/main.c) 159 159 target_link_libraries (depth-test ${TEST_LIBS}) 160 160 161 + add_executable(camera-matrix-test camera-matrix/main.c) 162 + target_link_libraries (camera-matrix-test ${TEST_LIBS}) 163 + 161 164 add_executable(video-test video/main.c) 162 165 target_link_libraries (video-test ${TEST_LIBS})
+209
tests/camera-matrix/main.c
··· 1 + #include "SDL.h" 2 + #include "SDL_gpu.h" 3 + #include <math.h> 4 + #include "compat.h" 5 + #include "common.h" 6 + 7 + #define PI 3.14159265359 8 + 9 + 10 + int main(int argc, char* argv[]) 11 + { 12 + GPU_Target* screen; 13 + 14 + GPU_Log("Running \"%s\"\n", argv[0]); 15 + printRenderers(); 16 + 17 + screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS); 18 + if(screen == NULL) 19 + return -1; 20 + 21 + printCurrentRenderer(); 22 + 23 + { 24 + Uint32 startTime; 25 + long frameCount; 26 + Uint8 done; 27 + SDL_Event event; 28 + SDL_Color red = {255, 0, 0, 255}; 29 + SDL_Color black = {0, 0, 0, 255}; 30 + GPU_Image* img; 31 + GPU_Image* buffer; 32 + GPU_Target* target; 33 + const Uint8* keystates; 34 + GPU_Camera camera; 35 + float dt; 36 + 37 + startTime = SDL_GetTicks(); 38 + frameCount = 0; 39 + 40 + 41 + 42 + img = GPU_LoadImage("data/test3.png"); 43 + buffer = GPU_CreateImage(800, 600, GPU_FORMAT_RGBA); 44 + GPU_LoadTarget(buffer); 45 + 46 + target = screen; 47 + 48 + keystates = SDL_GetKeyState(NULL); 49 + 50 + camera = GPU_GetDefaultCamera(); 51 + 52 + dt = 0.010f; 53 + done = 0; 54 + while(!done) 55 + { 56 + while(SDL_PollEvent(&event)) 57 + { 58 + if(event.type == SDL_QUIT) 59 + done = 1; 60 + else if(event.type == SDL_KEYDOWN) 61 + { 62 + if(event.key.keysym.sym == SDLK_ESCAPE) 63 + done = 1; 64 + else if(event.key.keysym.sym == SDLK_r) 65 + { 66 + camera = GPU_GetDefaultCamera(); 67 + } 68 + else if(event.key.keysym.sym == SDLK_RETURN) 69 + { 70 + if(target == screen) 71 + target = buffer->target; 72 + else 73 + target = screen; 74 + } 75 + else if (event.key.keysym.sym == SDLK_SPACE) 76 + { 77 + if(screen->using_virtual_resolution) 78 + GPU_UnsetVirtualResolution(screen); 79 + else 80 + GPU_SetVirtualResolution(screen, 400, 400); 81 + } 82 + else if(event.key.keysym.sym == SDLK_w) 83 + { 84 + camera.y -= 100; 85 + } 86 + else if(event.key.keysym.sym == SDLK_s) 87 + { 88 + camera.y += 100; 89 + } 90 + else if(event.key.keysym.sym == SDLK_a) 91 + { 92 + camera.x -= 100; 93 + } 94 + else if(event.key.keysym.sym == SDLK_d) 95 + { 96 + camera.x += 100; 97 + } 98 + else if(event.key.keysym.sym == SDLK_o) 99 + { 100 + GPU_MatrixMode(GPU_PROJECTION); 101 + GPU_LoadIdentity(); 102 + 103 + camera.x = 0; 104 + camera.y = 0; 105 + camera.z = 0.0f; 106 + GPU_Ortho(0, target->w, target->h, 0, target->camera.z_near, target->camera.z_far); 107 + 108 + GPU_MatrixMode(GPU_MODELVIEW); 109 + } 110 + else if(event.key.keysym.sym == SDLK_p) 111 + { 112 + GPU_MatrixMode(GPU_PROJECTION); 113 + GPU_LoadIdentity(); 114 + 115 + camera.x = target->w/2; 116 + camera.y = target->h/2; 117 + camera.z = 1000.0f; 118 + GPU_Frustum(-400, 400, 300, -300, 1000.0f, 10000.0f); 119 + 120 + GPU_MatrixMode(GPU_MODELVIEW); 121 + } 122 + } 123 + } 124 + 125 + if(keystates[KEY_UP]) 126 + { 127 + camera.y -= 200*dt; 128 + } 129 + else if(keystates[KEY_DOWN]) 130 + { 131 + camera.y += 200*dt; 132 + } 133 + if(keystates[KEY_LEFT]) 134 + { 135 + camera.x -= 200*dt; 136 + } 137 + else if(keystates[KEY_RIGHT]) 138 + { 139 + camera.x += 200*dt; 140 + } 141 + if(keystates[KEY_z]) 142 + { 143 + camera.z -= 200*dt; 144 + } 145 + else if(keystates[KEY_x]) 146 + { 147 + camera.z += 200*dt; 148 + } 149 + if(keystates[KEY_MINUS]) 150 + { 151 + camera.zoom_x -= 1.0f*dt; 152 + camera.zoom_y -= 1.0f*dt; 153 + } 154 + else if(keystates[KEY_EQUALS]) 155 + { 156 + camera.zoom_x += 1.0f*dt; 157 + camera.zoom_y += 1.0f*dt; 158 + } 159 + if(keystates[KEY_COMMA]) 160 + { 161 + camera.angle -= 100*dt; 162 + } 163 + else if(keystates[KEY_PERIOD]) 164 + { 165 + camera.angle += 100*dt; 166 + } 167 + 168 + GPU_ClearRGBA(screen, 0, 0, 0, 255); 169 + 170 + // No camera view 171 + GPU_SetCamera(screen, NULL); 172 + 173 + GPU_Circle(target, 0, 0, 25, GPU_MakeColor(255, 255, 255, 255)); 174 + GPU_Circle(target, target->w, 0, 25, GPU_MakeColor(255, 0, 0, 255)); 175 + GPU_Circle(target, target->w, target->h, 25, GPU_MakeColor(0, 255, 0, 255)); 176 + GPU_Circle(target, 0, target->h, 25, GPU_MakeColor(0, 0, 255, 255)); 177 + 178 + GPU_Rectangle(target, target->w/2 - 50, target->h/2 - 50, target->w/2 + 50, target->h/2 + 50, GPU_MakeColor(255, 255, 255, 255)); 179 + 180 + // Camera's view 181 + GPU_SetCamera(target, &camera); 182 + 183 + GPU_Line(target, 0, target->h/2, target->w, target->h/2, GPU_MakeColor(255, 255, 255, 255)); 184 + 185 + GPU_CircleFilled(target, 0, 0, 15, GPU_MakeColor(255, 255, 255, 255)); 186 + GPU_CircleFilled(target, target->w, 0, 15, GPU_MakeColor(255, 0, 0, 255)); 187 + GPU_CircleFilled(target, target->w, target->h, 15, GPU_MakeColor(0, 255, 0, 255)); 188 + GPU_CircleFilled(target, 0, target->h, 15, GPU_MakeColor(0, 0, 255, 255)); 189 + 190 + GPU_RectangleFilled(target, target->w/2 - 20, target->h/2 - 20, target->w/2 + 20, target->h/2 + 20, GPU_MakeColor(255, 0, 0, 255)); 191 + 192 + GPU_Flip(screen); 193 + 194 + frameCount++; 195 + if(frameCount%500 == 0) 196 + printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); 197 + } 198 + 199 + printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); 200 + 201 + GPU_FreeImage(img); 202 + } 203 + 204 + GPU_Quit(); 205 + 206 + return 0; 207 + } 208 + 209 +
+12 -10
tests/camera/main.c
··· 17 17 if(worldX) 18 18 { 19 19 //if(camera.angle == 0.0f) 20 - *worldX = (screenX - screen->w/2) / camera.zoom + camera.x + screen->w/2; 20 + *worldX = (screenX - screen->w/2) / camera.zoom_x + camera.x + screen->w/2; 21 21 //else 22 - //*worldX = (screenX - screen->w/2) / camera.zoom * cos(-camera.angle*PI/180) - (screenY - screen->h/2) / camera.zoom * sin(-camera.angle*PI/180) + camera.x + screen->w/2; 22 + //*worldX = (screenX - screen->w/2) / camera.zoom_x * cos(-camera.angle*PI/180) - (screenY - screen->h/2) / camera.zoom * sin(-camera.angle*PI/180) + camera.x + screen->w/2; 23 23 } 24 24 if(worldY) 25 25 { 26 26 //if(camera.angle == 0.0f) 27 - *worldY = (screenY - screen->h/2) / camera.zoom + camera.y + screen->h/2; 27 + *worldY = (screenY - screen->h/2) / camera.zoom_y + camera.y + screen->h/2; 28 28 //else 29 - //*worldY = (screenX - screen->w/2) / camera.zoom * sin(-camera.angle*PI/180) + (screenY - screen->h/2) / camera.zoom * cos(-camera.angle*PI/180) + camera.y + screen->h/2; 29 + //*worldY = (screenX - screen->w/2) / camera.zoom_y * sin(-camera.angle*PI/180) + (screenY - screen->h/2) / camera.zoom * cos(-camera.angle*PI/180) + camera.y + screen->h/2; 30 30 } 31 31 } 32 32 ··· 40 40 if(screenX) 41 41 { 42 42 //if(camera.angle == 0.0f) 43 - *screenX = (worldX - camera.x - screen->w/2)*camera.zoom + screen->w/2; 43 + *screenX = (worldX - camera.x - screen->w/2)*camera.zoom_x + screen->w/2; 44 44 //else 45 - //*screenX = (worldX - camera.x - screen->w/2)*camera.zoom * cos(-camera.angle*PI/180) + screen->w/2; 45 + //*screenX = (worldX - camera.x - screen->w/2)*camera.zoom_x * cos(-camera.angle*PI/180) + screen->w/2; 46 46 } 47 47 if(screenY) 48 48 { 49 49 //if(camera.angle == 0.0f) 50 - *screenY = (worldY - camera.y - screen->h/2)*camera.zoom + screen->h/2; 50 + *screenY = (worldY - camera.y - screen->h/2)*camera.zoom_y + screen->h/2; 51 51 //else 52 - //*screenY = (worldY - camera.y - screen->h/2)*camera.zoom * sin(-camera.angle*PI/180) + screen->h/2; 52 + //*screenY = (worldY - camera.y - screen->h/2)*camera.zoom_y * sin(-camera.angle*PI/180) + screen->h/2; 53 53 } 54 54 } 55 55 ··· 197 197 } 198 198 if(keystates[KEY_MINUS]) 199 199 { 200 - camera.zoom -= 1.0f*dt; 200 + camera.zoom_x -= 1.0f*dt; 201 + camera.zoom_y -= 1.0f*dt; 201 202 } 202 203 else if(keystates[KEY_EQUALS]) 203 204 { 204 - camera.zoom += 1.0f*dt; 205 + camera.zoom_x += 1.0f*dt; 206 + camera.zoom_y += 1.0f*dt; 205 207 } 206 208 if(keystates[KEY_COMMA]) 207 209 {
+4 -2
tests/copy/main.c
··· 100 100 } 101 101 if(keystates[KEY_MINUS]) 102 102 { 103 - camera.zoom -= 1.0f*dt; 103 + camera.zoom_x -= 1.0f*dt; 104 + camera.zoom_y -= 1.0f*dt; 104 105 } 105 106 else if(keystates[KEY_EQUALS]) 106 107 { 107 - camera.zoom += 1.0f*dt; 108 + camera.zoom_x += 1.0f*dt; 109 + camera.zoom_y += 1.0f*dt; 108 110 } 109 111 110 112
+4 -2
tests/pixel-perfect/main.c
··· 156 156 157 157 if(keystates[KEY_MINUS]) 158 158 { 159 - camera.zoom -= 1.0f*dt; 159 + camera.zoom_x -= 1.0f*dt; 160 + camera.zoom_y -= 1.0f*dt; 160 161 } 161 162 else if(keystates[KEY_EQUALS]) 162 163 { 163 - camera.zoom += 1.0f*dt; 164 + camera.zoom_x += 1.0f*dt; 165 + camera.zoom_y += 1.0f*dt; 164 166 } 165 167 166 168 GPU_SetCamera(screen, &camera);
+10 -12
tests/transform-matrix/main.c
··· 97 97 { 98 98 use_camera = 1; 99 99 GPU_EnableCamera(screen, use_camera); 100 + GPU_ResetProjection(); 100 101 } 101 102 102 103 } ··· 104 105 105 106 GPU_Clear(screen); 106 107 107 - 108 - GPU_MatrixMode(GPU_PROJECTION); 109 - GPU_LoadIdentity(); 108 + GPU_MatrixMode(GPU_PROJECTION); 110 109 111 110 if (!use_camera) 112 111 { 112 + GPU_LoadIdentity(); 113 113 // Apply projection matrix 114 114 GPU_MatrixIdentity(matrix); 115 115 ··· 150 150 } 151 151 152 152 153 + 153 154 // Apply model matrix 154 155 GPU_MatrixIdentity(matrix); 155 156 156 157 GPU_MatrixTranslate(matrix, x, y, z); 157 158 158 - if (!use_camera) 159 - { 160 - // Rotate 161 - if(rotate_stuff) 162 - { 163 - float a = SDL_GetTicks() / 10.0f; 164 - GPU_MatrixRotate(matrix, a, 0.57, 0.57, 0.57); 165 - } 166 - } 159 + // Rotate 160 + if(rotate_stuff) 161 + { 162 + float a = SDL_GetTicks() / 10.0f; 163 + GPU_MatrixRotate(matrix, a, 0.57, 0.57, 0.57); 164 + } 167 165 168 166 GPU_MultMatrix(matrix); 169 167
+19 -21
tools/compare-images-src/main.c
··· 18 18 if(worldX) 19 19 { 20 20 //if(camera.angle == 0.0f) 21 - *worldX = (screenX - screen->w/2) / camera.zoom + camera.x + screen->w/2; 21 + *worldX = (screenX - screen->w/2) / camera.zoom_x + camera.x + screen->w/2; 22 22 //else 23 - //*worldX = (screenX - screen->w/2) / camera.zoom * cos(-camera.angle*PI/180) - (screenY - screen->h/2) / camera.zoom * sin(-camera.angle*PI/180) + camera.x + screen->w/2; 23 + //*worldX = (screenX - screen->w/2) / camera.zoom_x * cos(-camera.angle*PI/180) - (screenY - screen->h/2) / camera.zoom * sin(-camera.angle*PI/180) + camera.x + screen->w/2; 24 24 } 25 25 if(worldY) 26 26 { 27 27 //if(camera.angle == 0.0f) 28 - *worldY = (screenY - screen->h/2) / camera.zoom + camera.y + screen->h/2; 28 + *worldY = (screenY - screen->h/2) / camera.zoom_y + camera.y + screen->h/2; 29 29 //else 30 - //*worldY = (screenX - screen->w/2) / camera.zoom * sin(-camera.angle*PI/180) + (screenY - screen->h/2) / camera.zoom * cos(-camera.angle*PI/180) + camera.y + screen->h/2; 30 + //*worldY = (screenX - screen->w/2) / camera.zoom_y * sin(-camera.angle*PI/180) + (screenY - screen->h/2) / camera.zoom * cos(-camera.angle*PI/180) + camera.y + screen->h/2; 31 31 } 32 32 } 33 33 ··· 41 41 if(screenX) 42 42 { 43 43 //if(camera.angle == 0.0f) 44 - *screenX = (worldX - camera.x - screen->w/2)*camera.zoom + screen->w/2; 44 + *screenX = (worldX - camera.x - screen->w/2)*camera.zoom_x + screen->w/2; 45 45 //else 46 - //*screenX = (worldX - camera.x - screen->w/2)*camera.zoom * cos(-camera.angle*PI/180) + screen->w/2; 46 + //*screenX = (worldX - camera.x - screen->w/2)*camera.zoom_x * cos(-camera.angle*PI/180) + screen->w/2; 47 47 } 48 48 if(screenY) 49 49 { 50 50 //if(camera.angle == 0.0f) 51 - *screenY = (worldY - camera.y - screen->h/2)*camera.zoom + screen->h/2; 51 + *screenY = (worldY - camera.y - screen->h/2)*camera.zoom_y + screen->h/2; 52 52 //else 53 - //*screenY = (worldY - camera.y - screen->h/2)*camera.zoom * sin(-camera.angle*PI/180) + screen->h/2; 53 + //*screenY = (worldY - camera.y - screen->h/2)*camera.zoom_y * sin(-camera.angle*PI/180) + screen->h/2; 54 54 } 55 55 } 56 56 ··· 122 122 done = 1; 123 123 else if (event.key.keysym.sym == SDLK_r) 124 124 { 125 - camera.x = 0.0f; 126 - camera.y = 0.0f; 127 - camera.z = -10.0f; 128 - camera.zoom = 1.0f; 129 - camera.angle = 0.0f; 125 + camera = GPU_GetDefaultCamera(); 130 126 } 131 127 } 132 128 else if (event.type == SDL_MOUSEBUTTONDOWN) ··· 154 150 { 155 151 camera.x += 200 * dt; 156 152 } 157 - if (keystates[KEY_MINUS]) 158 - { 159 - camera.zoom -= 1.0f*dt; 160 - } 161 - else if (keystates[KEY_EQUALS]) 162 - { 163 - camera.zoom += 1.0f*dt; 164 - } 153 + if(keystates[KEY_MINUS]) 154 + { 155 + camera.zoom_x -= 1.0f*dt; 156 + camera.zoom_y -= 1.0f*dt; 157 + } 158 + else if(keystates[KEY_EQUALS]) 159 + { 160 + camera.zoom_x += 1.0f*dt; 161 + camera.zoom_y += 1.0f*dt; 162 + } 165 163 166 164 GPU_ClearRGBA(screen, 255, 255, 255, 255); 167 165
+10 -8
tools/thumb-viewer-src/main.c
··· 68 68 { 69 69 camera.x += 200 * dt; 70 70 } 71 - if (keystates[KEY_MINUS]) 72 - { 73 - camera.zoom -= 1.0f*dt; 74 - } 75 - else if (keystates[KEY_EQUALS]) 76 - { 77 - camera.zoom += 1.0f*dt; 78 - } 71 + if(keystates[KEY_MINUS]) 72 + { 73 + camera.zoom_x -= 1.0f*dt; 74 + camera.zoom_y -= 1.0f*dt; 75 + } 76 + else if(keystates[KEY_EQUALS]) 77 + { 78 + camera.zoom_x += 1.0f*dt; 79 + camera.zoom_y += 1.0f*dt; 80 + } 79 81 80 82 GPU_ClearRGBA(screen, 255, 255, 255, 255); 81 83