jvcleave / ofxImGui

Use ImGui in openFrameworks
299 stars 123 forks source link

How to make the animation of images ratating looks smooth? #88

Closed haorenhl007 closed 5 years ago

haorenhl007 commented 5 years ago

I want to rotate an needl image, but it not looks smooth。How can I to improve it?The refresh of the gui is about 30fps。 the code is as follow: `#include static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x + rhs.x, lhs.y + rhs.y); } static inline ImVec2 ImRotate(const ImVec2& v, float cos_a, float sin_a) { return ImVec2(v.x cos_a - v.y sin_a, v.x sin_a + v.y cos_a); } void ImageRotated(ImTextureID tex_id, ImVec2 center, ImVec2 size, float angle) { ImDrawList* draw_list = ImGui::GetWindowDrawList();

float cos_a = cosf(angle);
float sin_a = sinf(angle);
ImVec2 pos[4] =
{
    center + ImRotate(ImVec2(-size.x * 0.5f, -size.y * 0.5f), cos_a, sin_a),
    center + ImRotate(ImVec2(+size.x * 0.5f, -size.y * 0.5f), cos_a, sin_a),
    center + ImRotate(ImVec2(+size.x * 0.5f, +size.y * 0.5f), cos_a, sin_a),
    center + ImRotate(ImVec2(-size.x * 0.5f, +size.y * 0.5f), cos_a, sin_a)
};
ImVec2 uvs[4] = 
{ 
    ImVec2(0.0f, 0.0f), 
    ImVec2(1.0f, 0.0f), 
    ImVec2(1.0f, 1.0f), 
    ImVec2(0.0f, 1.0f) 
};

draw_list->AddImageQuad(tex_id, pos[0], pos[1], pos[2], pos[3], uvs[0], uvs[1], uvs[2], uvs[3], IM_COL32_WHITE);

}`

It looks like as follow: image_rotate