質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
C

C言語は、1972年にAT&Tベル研究所の、デニス・リッチーが主体となって作成したプログラミング言語です。 B言語の後継言語として開発されたことからC言語と命名。そのため、表記法などはB言語やALGOLに近いとされています。 Cの拡張版であるC++言語とともに、現在世界中でもっとも普及されているプログラミング言語です。

OpenGL

OpenGLは、プラットフォームから独立した、デスクトップやワークステーション、モバイルサービスで使用可能な映像処理用のAPIです。

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

Q&A

解決済

1回答

1380閲覧

回転の大きさが小さくなっていってしまい、最終的に原点とくっついてしまいます。

hikarhikar

総合スコア18

C

C言語は、1972年にAT&Tベル研究所の、デニス・リッチーが主体となって作成したプログラミング言語です。 B言語の後継言語として開発されたことからC言語と命名。そのため、表記法などはB言語やALGOLに近いとされています。 Cの拡張版であるC++言語とともに、現在世界中でもっとも普及されているプログラミング言語です。

OpenGL

OpenGLは、プラットフォームから独立した、デスクトップやワークステーション、モバイルサービスで使用可能な映像処理用のAPIです。

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

0グッド

0クリップ

投稿2020/05/07 17:17

原点を中心とした点(-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}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

C++

1void Rect::rect_Rotate(float _x, float _y) { 2 this->matrix[0][0] = this->matrix[0][0] * cos(_x) + this->matrix[0][1] * sin(_x); // (1) 3 this->matrix[0][1] = -this->matrix[0][0] * sin(_x) + this->matrix[0][1] * cos(_x); // (2) 4}

コレ↑ 怪しい。(1)で書き換わった matrix[0][0] を (2)で使ってる.

C++

1 float X = this->matrix[0][0] * cos(_x) + this->matrix[0][1] * sin(_x); 2 float Y = -this->matrix[0][0] * sin(_x) + this->matrix[0][1] * cos(_x); 3 this->matrix[0][0] = X; 4 this->matrix[0][1] = Y;

だとどうなります?

投稿2020/05/07 22:10

episteme

総合スコア16614

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

hikarhikar

2020/05/08 05:34

epistemeさんご返答ありがとうございます。 epistemeさんに教えていただいた通りに修正してみたら、時計回りに正常に機能しました。 本当にありがとうございました。(*´▽`*)
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問