質問編集履歴

2

文章を修正

2022/08/11 03:29

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- 一次変換を使ってブロックの回転を実装させたい。
1
+ 一次変換を使ってブロックの回転させるコードわからない動作のコードの意味が知りたい。
test CHANGED
@@ -1,9 +1,8 @@
1
- 提示コードのif文の内部のコードですが参考サイトの一次変換を使ってテトリスのブロックの回転を行いたいのですが(取えず決め打ちの値)うく回転できません。コメント部のように原点戻すとうこともためましたができません。これはどうやるのでしょうか?
1
+ 提示コードのif文の内部のコードですが参考サイトの一次変換を使ってテトリスのブロックの回転を行いたいのですが`* (x - 1)`,`* (y- 1)`の意味がわかりません。これは昔自分で書いたードなのですが詳細な説明をコメントしてないためわかりません。
2
-
2
+ 算数の質問ですがなぜ行っているんでしょうか?
3
3
  参考サイト:http://www.geisya.or.jp/~mwm48961/kou2/linear_image3.html
4
4
 
5
5
  ```cpp
6
-
7
6
  /*#################################################
8
7
  # 回転
9
8
  ###################################################*/
@@ -11,26 +10,37 @@
11
10
  {
12
11
  if(isRotate == true)
13
12
  {
13
+ isRotate = false;
14
+ rotateRadian += 1;
15
+ if(rotateRadian > 3)
16
+ {
17
+ rotateRadian = 0;
18
+ }
19
+
14
20
  //std::cout<<"あああ"<<std::endl;
15
21
 
16
22
  for(int y = 0; y < 4; y++)
17
23
  {
18
24
  for(int x = 0; x < 4; x++)
19
25
  {
26
+ piece[y][x]= 0;
27
+ }
28
+ }
29
+
30
+ for(int y = 0; y < 4; y++)
31
+ {
32
+ for(int x = 0; x < 4; x++)
33
+ {
20
34
  if(piecePattern[(int)nowPiece][y][x] == (byte)1)
21
- {
35
+ {
22
- float xx = (cos((PI / 2.0) * rotateRadian)) * ((float)x - 1.5) + (-sin((PI / 2.0) * rotateRadian)) * ((float)y - 1.5);
36
+ float xx = (cos(PI / 2 * rotateRadian) * (x - 1)) + (-sin(PI / 2 * rotateRadian) * (y - 1) );
23
- float yy = (sin((PI / 2.0) * rotateRadian)) * ((float)x - 1.5) + ( cos((PI / 2.0) * rotateRadian)) * ((float)y - 1.5);
37
+ float yy = (sin(PI / 2 * rotateRadian) * (x - 1)) + ( cos(PI / 2 * rotateRadian) * (y - 1) );
24
-
25
- //int xx = (float)x * cos( (PI / 2) * rotateRadian) * (x - 1.5) + (-(float)y * sin((PI / 2) * rotateRadian)) * (y - 1.5);
26
- //int yy = (float)x * sin((PI / 2) * rotateRadian) * (x - 1.5) + (float)y * cos((PI / 2) * rotateRadian) * (y - 1.5);
27
38
 
28
39
  std::cout<<xx <<std::endl;
29
40
  std::cout<<yy <<std::endl;
30
41
 
31
- piece[(int)(yy + 1.5)][(int)(xx + 1.5)]= 1;
42
+ piece[(int)std::round(yy + 1)][(int)std::round(xx + 1)] = 1;
32
- // piece[y + yy][ x + xx]= 1;
43
+
33
- //piece[y + yy - 1][ x + xx - 1]= 1;
34
44
  }
35
45
  }
36
46
  }

1

文章を修正

2022/08/11 03:22

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -19,14 +19,18 @@
19
19
  {
20
20
  if(piecePattern[(int)nowPiece][y][x] == (byte)1)
21
21
  {
22
+ float xx = (cos((PI / 2.0) * rotateRadian)) * ((float)x - 1.5) + (-sin((PI / 2.0) * rotateRadian)) * ((float)y - 1.5);
23
+ float yy = (sin((PI / 2.0) * rotateRadian)) * ((float)x - 1.5) + ( cos((PI / 2.0) * rotateRadian)) * ((float)y - 1.5);
22
24
 
23
- int xx = (float)x * cos(PI) + (-(float)y * sin(PI));
25
+ //int xx = (float)x * cos( (PI / 2) * rotateRadian) * (x - 1.5) + (-(float)y * sin((PI / 2) * rotateRadian)) * (y - 1.5);
24
- int yy = (float)x * sin(PI) + (float)y * cos(PI);
26
+ //int yy = (float)x * sin((PI / 2) * rotateRadian) * (x - 1.5) + (float)y * cos((PI / 2) * rotateRadian) * (y - 1.5);
25
27
 
28
+ std::cout<<xx <<std::endl;
29
+ std::cout<<yy <<std::endl;
30
+
26
- piece[yy][xx]= 1;
31
+ piece[(int)(yy + 1.5)][(int)(xx + 1.5)]= 1;
27
- //piece[y + yy][ x + xx]= 1;
32
+ // piece[y + yy][ x + xx]= 1;
28
- //piece[y + yy - 1][ x + xx - 1]= 1;
33
+ //piece[y + yy - 1][ x + xx - 1]= 1;
29
-
30
34
  }
31
35
  }
32
36
  }