Tree @HEAD (Download .tar.gz)
- ..
- achievements.cpp
- achievements.hpp
- animation_creator.cpp
- animation_creator.hpp
- animation_preview_widget.cpp
- animation_preview_widget.hpp
- animation_widget.cpp
- animation_widget.hpp
- Appirater.h
- Appirater.m
- array_callable.hpp
- asserts.cpp
- asserts.hpp
- background.cpp
- background.hpp
- background_task_pool.cpp
- background_task_pool.hpp
- base64.cpp
- base64.hpp
- blur.cpp
- blur.hpp
- border_widget.cpp
- border_widget.hpp
- button.cpp
- button.hpp
- character_editor_dialog.cpp
- character_editor_dialog.hpp
- checkbox.cpp
- checkbox.hpp
- checksum.cpp
- checksum.hpp
- clipboard.cpp
- clipboard.hpp
- CMakeLists.txt
- code_editor_dialog.cpp
- code_editor_dialog.hpp
- code_editor_widget.cpp
- code_editor_widget.hpp
- collision_utils.cpp
- collision_utils.hpp
- color_chart.cpp
- color_chart.hpp
- color_utils.cpp
- color_utils.hpp
- colorshift_hash_table.cpp
- colorshift_hash_table.hpp
- compat.hpp
- compress.cpp
- compress.hpp
- concurrent_cache.hpp
- controls.cpp
- controls.hpp
- controls_dialog.cpp
- controls_dialog.hpp
- current_generator.cpp
- current_generator.hpp
- custom_object.cpp
- custom_object.hpp
- custom_object_callable.cpp
- custom_object_callable.hpp
- custom_object_dialog.cpp
- custom_object_dialog.hpp
- custom_object_functions.cpp
- custom_object_functions.hpp
- custom_object_type.cpp
- custom_object_type.hpp
- debug_console.cpp
- debug_console.hpp
- decimal.cpp
- decimal.hpp
- dialog.cpp
- dialog.hpp
- difficulty.cpp
- difficulty.hpp
- drag_widget.cpp
- drag_widget.hpp
- draw_number.cpp
- draw_number.hpp
- draw_scene.cpp
- draw_scene.hpp
- draw_tile.cpp
- draw_tile.hpp
- dropdown_widget.cpp
- dropdown_widget.hpp
- editor.cpp
- editor.hpp
- editor_dialogs.cpp
- editor_dialogs.hpp
- editor_formula_functions.cpp
- editor_formula_functions.hpp
- editor_layers_dialog.cpp
- editor_layers_dialog.hpp
- editor_level_properties_dialog.cpp
- editor_level_properties_dialog.hpp
- editor_module_properties_dialog.cpp
- editor_module_properties_dialog.hpp
- editor_stats_dialog.cpp
- editor_stats_dialog.hpp
- editor_variable_info.cpp
- editor_variable_info.hpp
- eglport-tegra.c
- eglport.c
- eglport.h
- entity.cpp
- entity.hpp
- entity_fwd.hpp
- external_text_editor.cpp
- external_text_editor.hpp
- file_chooser_dialog.cpp
- file_chooser_dialog.hpp
- filesystem-android.cpp
- filesystem.cpp
- filesystem.hpp
- font.cpp
- font.hpp
- foreach.hpp
- formatter.hpp
- formula.cpp
- formula.hpp
- formula_callable.hpp
- formula_callable_definition.cpp
- formula_callable_definition.hpp
- formula_callable_definition_fwd.hpp
- formula_callable_utils.hpp
- formula_constants.cpp
- formula_constants.hpp
- formula_function.cpp
- formula_function.hpp
- formula_function_registry.cpp
- formula_function_registry.hpp
- formula_fwd.hpp
- formula_profiler.cpp
- formula_profiler.hpp
- formula_test.cpp
- formula_tokenizer.cpp
- formula_tokenizer.hpp
- formula_variable_storage.cpp
- formula_variable_storage.hpp
- frame.cpp
- frame.hpp
- framed_gui_element.cpp
- framed_gui_element.hpp
- frogatto-resouces.rc
- functional.hpp
- game_registry.cpp
- game_registry.hpp
- geometry.cpp
- geometry.hpp
- gles2.cpp
- gles2.hpp
- globals.cpp
- globals.h
- graphical_font.cpp
- graphical_font.hpp
- graphical_font_label.cpp
- graphical_font_label.hpp
- graphics.hpp
- grid_widget.cpp
- grid_widget.hpp
- grid_widget_fwd.hpp
- group_property_editor_dialog.cpp
- group_property_editor_dialog.hpp
- gui_formula_functions.cpp
- gui_formula_functions.hpp
- gui_section.cpp
- gui_section.hpp
- hex_map.cpp
- hex_map.hpp
- hex_object.cpp
- hex_object.hpp
- hex_object_fwd.hpp
- hex_tile.cpp
- hex_tile.hpp
- hex_tileset_editor_dialog.cpp
- hex_tileset_editor_dialog.hpp
- hi_res_timer.hpp
- http_client.cpp
- http_client.hpp
- http_server.cpp
- http_server.hpp
- i18n.cpp
- i18n.hpp
- image_widget.cpp
- image_widget.hpp
- image_widget_fwd.hpp
- IMG_savepng.cpp
- IMG_savepng.h
- input.cpp
- input.hpp
- iphone_controls.cpp
- iphone_controls.hpp
- iphone_device_info.h
- iphone_device_info.m
- iphone_sound.h
- iphone_sound.m
- joystick.cpp
- joystick.hpp
- json_parser.cpp
- json_parser.hpp
- json_tokenizer.cpp
- json_tokenizer.hpp
- key.cpp
- key.hpp
- key_button.cpp
- key_button.hpp
- label.cpp
- label.hpp
- level.cpp
- level.hpp
- level_logic.cpp
- level_logic.hpp
- level_object.cpp
- level_object.hpp
- level_runner.cpp
- level_runner.hpp
- level_solid_map.cpp
- level_solid_map.hpp
- LICENSE
- light.cpp
- light.hpp
- load_level.cpp
- load_level.hpp
- load_level_nothread.cpp
- loading_screen.cpp
- loading_screen.hpp
- main.cpp
- map_utils.hpp
- md5.cpp
- md5.hpp
- message_dialog.cpp
- message_dialog.hpp
- module.cpp
- module.hpp
- module_web_server.cpp
- module_web_server.hpp
- movement_script.cpp
- movement_script.hpp
- multi_tile_pattern.cpp
- multi_tile_pattern.hpp
- multiplayer.cpp
- multiplayer.hpp
- object_events.cpp
- object_events.hpp
- of_bridge.h
- of_bridge.mm
- options_dialog.cpp
- options_dialog.hpp
- particle_system.cpp
- particle_system.hpp
- pathfinding.cpp
- pathfinding.hpp
- pause_game_dialog.cpp
- pause_game_dialog.hpp
- playable_custom_object.cpp
- playable_custom_object.hpp
- player_info.cpp
- player_info.hpp
- point_map.hpp
- poly_line_widget.hpp
- preferences.cpp
- preferences.hpp
- preprocessor.cpp
- preprocessor.hpp
- preview_tileset_widget.cpp
- preview_tileset_widget.hpp
- progress_bar.cpp
- progress_bar.hpp
- property_editor_dialog.cpp
- property_editor_dialog.hpp
- random.cpp
- random.hpp
- raster.cpp
- raster.hpp
- raster_distortion.cpp
- raster_distortion.hpp
- rectangle_rotator.cpp
- rectangle_rotator.hpp
- reference_counted_object.hpp
- regex_utils.hpp
- SampleOFDelegate.h
- SampleOFDelegate.mm
- SConscript
- scoped_resource.hpp
- scrollable_widget.cpp
- scrollable_widget.hpp
- scrollbar_widget.cpp
- scrollbar_widget.hpp
- SDLMain.h
- SDLMain.m
- segment_editor_dialog.cpp
- segment_editor_dialog.hpp
- server.cpp
- settings_dialog.cpp
- settings_dialog.hpp
- shaders.cpp
- shaders.hpp
- simple_wml.cpp
- simple_wml.hpp
- slider.cpp
- slider.hpp
- solid_map.cpp
- solid_map.hpp
- solid_map_fwd.hpp
- sound.cpp
- sound.hpp
- speech_dialog.cpp
- speech_dialog.hpp
- stats.cpp
- stats.hpp
- stats_server.cpp
- stats_server.hpp
- stats_server_main.cpp
- stats_web_server.cpp
- stats_web_server.hpp
- string_utils.cpp
- string_utils.hpp
- surface.cpp
- surface.hpp
- surface_cache.cpp
- surface_cache.hpp
- surface_formula.cpp
- surface_formula.hpp
- surface_palette.cpp
- surface_palette.hpp
- surface_scaling.cpp
- surface_scaling_generated.hpp
- sys.cpp
- sys.hpp
- tbs_ai_player.cpp
- tbs_ai_player.hpp
- tbs_bot.cpp
- tbs_bot.hpp
- tbs_client.cpp
- tbs_client.hpp
- tbs_functions.cpp
- tbs_functions.hpp
- tbs_game.cpp
- tbs_game.hpp
- tbs_server.cpp
- tbs_server.hpp
- tbs_web_server.cpp
- tbs_web_server.hpp
- text_editor_widget.cpp
- text_editor_widget.hpp
- texture.cpp
- texture.hpp
- texture_frame_buffer.cpp
- texture_frame_buffer.hpp
- thread.cpp
- thread.hpp
- tile_map.cpp
- tile_map.hpp
- tileset_editor_dialog.cpp
- tileset_editor_dialog.hpp
- tooltip.cpp
- tooltip.hpp
- translate.cpp
- translate.hpp
- tree_view_widget.cpp
- tree_view_widget.hpp
- unit_test.cpp
- unit_test.hpp
- uri.hpp
- userevents.h
- utility_object_compiler.cpp
- utility_query.cpp
- utility_query.hpp
- utility_render_level.cpp
- utils.cpp
- utils.hpp
- variant.cpp
- variant.hpp
- variant_callable.cpp
- variant_callable.hpp
- variant_utils.cpp
- variant_utils.hpp
- vecmath.hpp
- vector_text.cpp
- vector_text.hpp
- water.cpp
- water.hpp
- water_particle_system.cpp
- water_particle_system.hpp
- weather_particle_system.cpp
- weather_particle_system.hpp
- widget.cpp
- widget.hpp
- widget_factory.cpp
- widget_factory.hpp
- win_profile_timer.hpp
- wm.cpp
- wm.hpp
- wml_formula_callable.cpp
- wml_formula_callable.hpp
rectangle_rotator.cpp @HEAD — raw · history · blame
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | #include "graphics.hpp" #include "rectangle_rotator.hpp" #include <math.h> #ifndef M_PI #define M_PI 3.14159265358979323846 #endif #include "unit_test.hpp" void rotate_rect(GLshort center_x, GLshort center_y, float rotation, GLshort* rect_vertexes){ point p; float rotate_radians = (rotation * M_PI)/180; //rect r(rect_vertexes[0],rect_vertexes[1],rect_vertexes[4]-rect_vertexes[0],rect_vertexes[5]-rect_vertexes[1]); p = rotate_point_around_origin_with_offset( rect_vertexes[0], rect_vertexes[1], rotate_radians, center_x, center_y ); rect_vertexes[0] = p.x; rect_vertexes[1] = p.y; p = rotate_point_around_origin_with_offset( rect_vertexes[2], rect_vertexes[3], rotate_radians, center_x, center_y ); rect_vertexes[2] = p.x; rect_vertexes[3] = p.y; p = rotate_point_around_origin_with_offset( rect_vertexes[4], rect_vertexes[5], rotate_radians, center_x, center_y ); rect_vertexes[4] = p.x; rect_vertexes[5] = p.y; p = rotate_point_around_origin_with_offset( rect_vertexes[6], rect_vertexes[7], rotate_radians, center_x, center_y ); rect_vertexes[6] = p.x; rect_vertexes[7] = p.y; } void rotate_rect(const rect& r, GLfloat angle, GLshort* output){ point offset; offset.x = r.x() + r.w()/2; offset.y = r.y() + r.h()/2; point p; p = rotate_point_around_origin_with_offset( r.x(), r.y(), angle, offset.x, offset.y ); output[0] = p.x; output[1] = p.y; p = rotate_point_around_origin_with_offset( r.x2(), r.y(), angle, offset.x, offset.y ); output[2] = p.x; output[3] = p.y; p = rotate_point_around_origin_with_offset( r.x2(), r.y2(), angle, offset.x, offset.y ); output[4] = p.x; output[5] = p.y; p = rotate_point_around_origin_with_offset( r.x(), r.y2(), angle, offset.x, offset.y ); output[6] = p.x; output[7] = p.y; } point rotate_point_around_origin_with_offset(int x1, int y1, float alpha, int u1, int v1){ point beta = rotate_point_around_origin(x1 - u1, y1 - v1, alpha); beta.x += u1; beta.y += v1; return beta; } point rotate_point_around_origin(int x1, int y1, float alpha){ point beta; /* //we actually don't need the initial theta and radius. This is why: x2 = R * (cos(theta) * cos(alpha) + sin(theta) * sin(alpha)) y2 = R * (sin(theta) * cos(alpha) + cos(theta) * sin(alpha)); but R * (cos(theta)) = x1 R * (sin(theta)) = x2 this collapses the above to: */ beta.x = x1 * cos(alpha) - y1 * sin(alpha); beta.y = y1 * cos(alpha) + x1 * sin(alpha); return beta; } /*UNIT_TEST(rotate_test) { std::cerr << "rotating_a_point \n"; std::cerr << rotate_point_around_origin( 1000, 1000, (M_PI/2)).to_string() << "\n"; //Should be -1000,1000 std::cerr << rotate_point_around_origin_with_offset( 11000, 1000, (M_PI/2), 10000,0).to_string() << "\n"; //Should be 9000,1000 GLshort myOutputData[8]; rect r(10, 10, 20, 30); rotate_rect(r, (M_PI*2), myOutputData); std::cerr << "Outputting point list \n"; for(int i=0;i<8;++i){ std::cerr << myOutputData[i] << " "; if(i%2){ std::cerr << "\n";} } }*/ BENCHMARK(rect_rotation) { rect r(10, 10, 20, 30); GLshort output[8]; BENCHMARK_LOOP { rotate_rect(r, 75, output); } } |