原点を中心とした点(-1,-1)を時計周りに回転させるプログラムで、回転の大きさがどんどん小さくなっていってしまって、最終的に原点とくっついてしまいます。
X = xcosΘ + ysinΘ
Y = x*-sinΘ + y*cosΘ
の計算を行ったのですが、どのようにすればいいのでしょうか?
教えていただければ幸いです。<(_ _)>
c++
1struct Rect { 2 float color[3] = { 0.f }; 3 float matrix[4][2] = { 0.f }; 4 5 Rect(int _x, int _y, int _wight, int _height); 6 7 void rect_Color(float _red,float _green,float _blue); 8 void rect_Rotate(float _x,float _y); 9 10 void const rect_Draw(); 11}; 12
c++
1#include <math.h> 2 3#include "glut.h" 4 5#include "rect.h" 6 7Rect::Rect(int _x, int _y, int _width, int _height) { 8 this->matrix[0][0] = _x; 9 this->matrix[0][1] = _y; 10 11 this->matrix[1][0] = this->matrix[0][0] + _width; 12 this->matrix[1][1] = _y; 13 14 this->matrix[2][0] = _x; 15 this->matrix[2][1] = this->matrix[0][1] + _height; 16 17 this->matrix[3][0] = this->matrix[0][0] + _width; 18 this->matrix[3][1] = this->matrix[0][1] + _height; 19} 20 21void Rect::rect_Color(float _red, float _green, float _blue) { 22 this->color[0] = _red; 23 this->color[1] = _green; 24 this->color[2] = _blue; 25} 26 27void Rect::rect_Rotate(float _x, float _y) { 28 this->matrix[0][0] = this->matrix[0][0] * cos(_x) + this->matrix[0][1] * sin(_x); 29 this->matrix[0][1] = -this->matrix[0][0] * sin(_x) + this->matrix[0][1] * cos(_x); 30} 31 32void const Rect::rect_Draw() { 33 glPushMatrix(); 34 35 glColor3f(0x00,0x00,0xff); 36 glPointSize(3); 37 glBegin(GL_POINTS); 38 { 39 glVertex3f(this->matrix[0][0], this->matrix[0][1], 0); 40 glVertex3f(0, 0, 0); 41 } 42 glEnd(); 43 44 glPopMatrix(); 45}
opengl
1#include <stdio.h> 2#include <stdlib.h> 3 4#include "glm/glm.hpp" 5#include "glut.h" 6 7#include "rect.h" 8#include "font.h" 9 10using namespace glm; 11vec2 windowSize = { 1000,600 }; 12 13Rect rect1=Rect(-1, -1,2, 2); 14 15void display(void) { 16 glClearColor(0xff, 0xff, 0xff, 0); 17 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 18 19 glMatrixMode(GL_PROJECTION); 20 glLoadIdentity(); 21 glMatrixMode(GL_MODELVIEW); 22 glLoadIdentity(); 23 24 gluPerspective(30.0, (double)windowSize.x / windowSize.y, 1.0, 4000.0); 25 26 gluLookAt(0.0, 2, 50, 0.0, 0, 0.0, 0.0, 1.0, 0.0); 27 28 rect1.rect_Color(0xff, 0x00, 0xff); 29 rect1.rect_Rotate(0.1, 0); 30 rect1.rect_Draw(); 31 32 glutSwapBuffers(); 33} 34 35void idle(void) { 36 glutPostRedisplay(); 37} 38 39void reshape(int width, int height) { 40 printf("reshape: width:%d height:%d\n", width, height); 41 glViewport(0,0,width,height); 42 windowSize = vec2(width, height); 43} 44 45int main(int argc, char* argv[]) { 46 glutInit( 47 &argc, 48 argv); 49 glutInitDisplayMode(GL_DOUBLE); 50 glutInitWindowPosition(100,100); 51 glutInitWindowSize(windowSize.x,windowSize.y); 52 glutCreateWindow("Window"); 53 54 glutDisplayFunc(display); 55 glutIdleFunc(idle); 56 glutReshapeFunc(reshape); 57 58 glutMainLoop(); 59 60 return 0; 61}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/05/08 05:34