graphics.cpp

来自「机器人的行为控制模拟程序。用于机器人的环境识别。A robot action d」· C++ 代码 · 共 34 行

CPP
34
字号
#include <windows.h>
#include <math.h>

#include "world.h"

/* End of draw arrow */
/* Crazy GDI code to draw a vector graphics arrow */
void draw_arrow(HDC dc, double x, double y, double dir, double size)
{
    double arrow_base_x = x - size * cos(dir);
    double arrow_base_y = y - size * sin(dir);
    
    MoveToEx(dc, get_screen_x(arrow_base_x), get_screen_y(arrow_base_y), NULL);
    
    double arrow_tip_x = x + size * cos(dir);
    double arrow_tip_y = y + size * sin(dir);
        
    LineTo(dc, get_screen_x(arrow_tip_x), get_screen_y(arrow_tip_y));    

    double arrow_left_x = x + 0.75 * size * cos(dir - M_PI / 4.0);
    double arrow_left_y = y + 0.75 * size * sin(dir - M_PI / 4.0);

    MoveToEx(dc, get_screen_x(arrow_left_x), get_screen_y(arrow_left_y), NULL);

    LineTo(dc, get_screen_x(arrow_tip_x), get_screen_y(arrow_tip_y));    

    double arrow_right_x = x + 0.75 * size * cos(dir + M_PI / 4.0);
    double arrow_right_y = y + 0.75 * size * sin(dir + M_PI / 4.0);

    LineTo(dc, get_screen_x(arrow_right_x), get_screen_y(arrow_right_y));    
}
/* End of draw arrow */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?