handcanvas.java
来自「3D手机游戏开发实例源代码」· Java 代码 · 共 771 行 · 第 1/3 页
JAVA
771 行
} // end of updateModelTrans()
// -----------------key operation methods ---------------------
public void keyRepeated(int keyCode)
{
int gameAction = getGameAction(keyCode);
if (hasRepeatEvents())
performAction( gameAction );
}
protected void keyPressed(int keyCode)
{
int gameAction = getGameAction(keyCode);
// System.out.println("Can repeat: " + hasRepeatEvents());
// if this MIDP doesn't support repeated keys
// then initialise our key repeater
if (!hasRepeatEvents())
keyRepeater.startRepeat( gameAction );
} // end of keyPressed()
protected void keyReleased(int keyCode)
{
int gameAction = getGameAction(keyCode);
// if this MIDP doesn't support repeated keys
// then stop our key repeater
if (!hasRepeatEvents())
keyRepeater.stopRepeat( gameAction );
}
public void performAction(int gameAction)
// called by KeyRepeat object or the keyRepeated() method
{
if (gameAction == UP) {
moveModel(0,MODEL_MOVE,0); // y up
}
else if (gameAction == DOWN) {
moveModel(0,-MODEL_MOVE,0); // y down
}
else if (gameAction == LEFT) {
moveModel(-MODEL_MOVE,0,0); // x left
}
else if (gameAction == RIGHT) {
moveModel(MODEL_MOVE,0,0); // x right
}
else if (gameAction == GAME_A) {
// System.out.println("fwd");
moveModel(0,0,MODEL_MOVE); // z fwd
}
else if (gameAction == GAME_B) {
// System.out.println("back");
moveModel(0,0,-MODEL_MOVE); // z back
}
else if (gameAction == GAME_C) {
// System.out.println("rot left");
rotYModel(-MODEL_ROT); // rotate left
}
else if (gameAction == GAME_D) {
// System.out.println("rot right");
rotYModel(MODEL_ROT); // rotate right
}
} // end of keyPressed()
private void moveModel(float x, float y, float z)
// update the model's translation values
{ xTrans += x; yTrans += y; zTrans += z;
repaint();
}
private void rotYModel(float degrees)
// update the model's y-axis rotation value
{ totalDegrees += degrees;
repaint();
} // end of rotYModel()
// ----------------- data-specific methods added here -------
/*
The following methods can be pasted in from the ObjView application
output stored in examObj.txt:
private short[] getVerts() {...}
private byte[] getNormals() {...}
private short[] getTexCoords() (...}
private short[] getColourCoords() (...}
private int[] getStripLengths() {...}
private Material setMatColours() {...}
*/
// Methods for model in hand.obj
private short[] getVerts()
// return an array holding Verts [2205 values / 3 = 735 points]
{
short[] vals = {
42,114,-5, 47,101,4, 52,114,-2, 47,101,4,
61,111,-1, 47,101,4, 57,99,4, 50,83,9,
57,99,4, 62,96,-2, 61,111,-1, 89,69,25,
87,72,30, 97,68,28, 96,71,35, 101,62,33,
83,69,38, 90,67,42, 87,72,30, 90,67,42,
96,71,35, 95,63,46, 96,71,35, 100,66,39,
101,62,33, 100,66,39, 101,56,38, 100,66,39,
100,58,43, 95,63,46, 100,58,43, 97,59,47,
92,51,49, 97,59,47, 87,55,49, 95,63,46,
87,55,49, 90,67,42, 82,58,46, 83,69,38,
77,61,42, 83,69,38, 77,69,34, 87,72,30,
79,70,28, 87,72,30, 82,69,24, 89,69,25,
82,69,24, 85,62,26, 82,69,24, 78,63,26,
79,70,28, 74,64,30, 77,69,34, 73,64,36,
77,61,42, 69,56,37, 77,61,42, 70,52,42,
82,58,46, 70,52,42, 74,48,46, 70,52,42,
64,43,40, 70,52,42, 64,46,35, 69,56,37,
70,57,32, 73,64,36, 70,57,32, 74,64,30,
70,57,32, 78,63,26, 74,55,28, 85,62,26,
79,51,27, 85,62,26, 91,58,29, 89,69,25,
91,58,29, 97,68,28, 91,58,29, 101,62,33,
95,53,34, 101,56,38, 95,49,40, 100,58,43,
94,49,45, 92,51,49, 87,40,46, 92,51,49,
84,42,49, 87,55,49, 79,45,49, 82,58,46,
79,45,49, 74,48,46, 71,37,46, 74,48,46,
67,40,43, 64,43,40, 67,40,43, 59,36,38,
67,40,43, 61,33,42, 67,40,43, 65,31,44,
71,37,46, 69,29,44, 71,37,46, 76,35,46,
79,45,49, 76,35,46, 84,42,49, 79,33,43,
87,40,46, 88,40,41, 94,49,45, 88,40,41,
95,49,40, 87,42,35, 95,53,34, 84,46,30,
91,58,29, 84,46,30, 79,51,27, 75,41,26,
79,51,27, 70,45,26, 74,55,28, 70,45,26,
70,57,32, 66,47,30, 64,46,35, 59,38,33,
64,43,40, 59,38,33, 59,36,38, 53,31,34,
59,36,38, 53,29,39, 61,33,42, 55,27,43,
65,31,44, 59,24,46, 65,31,44, 64,22,45,
69,29,44, 69,20,42, 69,29,44, 74,27,40,
76,35,46, 74,27,40, 79,33,43, 81,32,38,
88,40,41, 81,34,33, 87,42,35, 78,37,29,
84,46,30, 78,37,29, 75,41,26, 71,33,24,
75,41,26, 66,36,23, 70,45,26, 66,36,23,
66,47,30, 62,38,27, 59,38,33, 56,31,27,
53,31,34, 51,31,26, 44,26,35, 41,39,27,
30,29,29, 41,39,27, 31,51,20, 41,55,19,
31,51,20, 35,68,14, 27,65,9, 32,83,4,
27,65,9, 26,64,-1, 21,54,1, 26,64,-1,
29,61,-8, 34,79,-12, 29,61,-8, 39,61,-8,
36,45,-4, 45,51,2, 46,35,11, 47,41,19,
51,31,26, 47,41,19, 41,39,27, 47,41,19,
41,55,19, 47,41,19, 46,55,11, 45,51,2,
49,67,6, 45,51,2, 47,64,-3, 39,61,-8,
43,77,-12, 34,79,-12, 39,97,-16, 34,79,-12,
30,81,-5, 26,64,-1, 30,81,-5, 32,83,4,
37,102,-1, 32,83,4, 41,84,10, 35,68,14,
44,69,14, 41,55,19, 44,69,14, 46,55,11,
44,69,14, 49,67,6, 54,80,3, 49,67,6,
52,78,-6, 47,64,-3, 52,78,-6, 43,77,-12,
49,95,-16, 39,97,-16, 43,110,-17, 39,97,-16,
34,100,-9, 30,81,-5, 34,100,-9, 37,102,-1,
42,114,-5, 37,102,-1, 47,101,4, 41,84,10,
50,83,9, 44,69,14, 50,83,9, 54,80,3,
62,96,-2, 52,78,-6, 59,94,-10, 49,95,-16,
59,94,-10, 63,107,-13, 62,96,-2, 64,111,-7,
61,111,-1, 64,111,-7, 54,117,-11, 63,107,-13,
54,110,-17, 49,95,-16, 54,110,-17, 43,110,-17,
54,117,-11, 43,110,-17, 42,114,-12, 34,100,-9,
42,114,-12, 42,114,-5, 54,117,-11, 52,114,-2,
61,111,-1, 53,31,34, 44,26,35, 53,29,39,
45,20,42, 55,27,43, 49,17,46, 59,24,46,
53,14,48, 59,24,46, 58,12,48, 64,22,45,
64,9,44, 69,20,42, 68,8,38, 69,20,42,
73,19,36, 74,27,40, 77,26,35, 81,32,38,
77,26,35, 81,34,33, 77,27,31, 81,34,33,
75,29,27, 78,37,29, 75,29,27, 71,33,24,
66,25,23, 66,36,23, 61,28,23, 62,38,27,
61,28,23, 56,31,27, 52,23,19, 51,31,26,
52,23,19, 46,35,11, 37,24,4, 36,45,-4,
23,44,-6, 29,61,-8, 23,44,-6, 21,54,1,
17,64,-11, 18,67,-3, 15,86,-17, 18,67,-3,
18,89,-9, 14,91,-1, 14,112,-7, 3,111,-3,
13,124,-11, 3,111,-3, 3,126,-10, -7,122,-10,
3,126,-10, 3,127,-19, 13,124,-11, 15,125,-19,
13,124,-11, 18,110,-15, 14,112,-7, 18,110,-15,
18,89,-9, 15,107,-22, 15,86,-17, 15,107,-22,
5,106,-24, 14,121,-24, 4,121,-25, 14,121,-24,
3,127,-19, 14,121,-24, 15,125,-19, 14,121,-24,
18,110,-15, 15,107,-22, -21,90,15, -27,101,22,
-22,91,24, -29,90,31, -22,91,24, -17,76,25,
-21,90,15, -16,75,16, -21,90,15, -26,88,11,
-21,90,15, -28,101,16, -27,101,22, -38,102,22,
-27,101,22, -34,101,28, -29,90,31, -34,101,28,
-42,97,32, -38,102,22, -42,97,32, -46,97,28,
-44,85,30, -46,97,28, -47,94,22, -38,102,22,
-40,97,16, -28,101,16, -30,98,11, -26,88,11,
-30,98,11, -36,85,14, -40,97,16, -36,85,14,
-47,94,22, -44,84,22, -44,85,30, -37,70,29,
-44,85,30, -38,87,34, -42,97,32, -38,87,34,
-29,90,31, -38,87,34, -31,72,34, -37,70,29,
-29,52,28, -37,70,29, -37,68,21, -44,84,22,
-37,68,21, -36,85,14, -30,69,13, -26,88,11,
-21,72,11, -16,75,16, -21,72,11, -10,59,14,
-14,55,8, -5,51,10, -4,39,2, -5,51,10,
-1,62,-7, -4,65,2, -7,86,-6, -4,89,2,
-7,86,-6, -10,107,-12, -7,86,-6, -3,84,-15,
-1,62,-7, 8,61,-12, -1,62,-7, 10,36,-6,
-4,39,2, 10,36,-6, 12,5,1, 24,13,0,
26,-12,7, 40,6,11, 45,-5,17, 58,14,22,
63,10,26, 71,22,27, 63,10,26, 74,20,31,
63,10,26, 68,8,31, 57,-10,30, 60,-8,37,
52,-22,36, 60,-8,37, 47,-22,41, 56,-7,44,
47,-22,41, 50,-4,48, 41,-20,46, 44,-2,49,
35,-20,47, 44,-2,49, 31,-17,46, 40,0,47,
31,-17,46, 35,2,43, 25,-18,43, 35,2,43,
20,-11,39, 31,10,38, 20,-11,39, 19,17,29,
10,12,31, 19,17,29, 8,43,21, 20,49,15,
6,68,12, 15,69,7, 6,68,12, 5,91,4,
-4,89,2, -7,109,-5, -10,107,-12, -7,109,-5,
-7,122,-10, -7,109,-5, 3,111,-3, 5,91,4,
14,91,-1, 15,69,7, 18,67,-3, 15,69,7,
21,54,1, 20,49,15, 27,65,9, 20,49,15,
31,51,20, 20,49,15, 30,29,29, 19,17,29,
30,29,29, 31,10,38, 44,26,35, 31,10,38,
45,20,42, 35,2,43, 49,17,46, 40,0,47,
53,14,48, 44,-2,49, 53,14,48, 50,-4,48,
58,12,48, 56,-7,44, 64,9,44, 56,-7,44,
68,8,38, 60,-8,37, 68,8,38, 68,8,31,
73,19,36, 74,20,31, 77,26,35, 74,20,31,
77,27,31, 71,22,27, 75,29,27, 71,22,27,
66,25,23, 58,14,22, 61,28,23, 58,14,22,
52,23,19, 40,6,11, 37,24,4, 24,13,0,
23,44,-6, 10,36,-6, 23,44,-6, 8,61,-12,
17,64,-11, 8,61,-12, 6,84,-19, -3,84,-15,
-6,105,-20, -10,107,-12, -6,119,-23, -10,107,-12,
-8,122,-17, -7,122,-10, -8,122,-17, 3,127,-19,
-6,119,-23, 4,121,-25, -6,119,-23, 5,106,-24,
-6,105,-20, 5,106,-24, 6,84,-19, 15,86,-17,
17,64,-11, 12,-123,45, 12,-47,17, 14,-127,44,
16,-49,17, 17,-128,43, 20,-49,19, 20,-128,44,
20,-49,22, 21,-127,47, 20,-49,22, 20,-125,49,
18,-46,26, 17,-121,49, 15,-43,27, 17,-121,49,
12,-44,27, 15,-122,49, 10,-47,26, 12,-123,45,
10,-46,20, 12,-47,17, 5,-31,14, 12,-47,17,
19,-38,13, 16,-49,17, 19,-38,13, 20,-49,19,
33,-35,20, 20,-49,22, 30,-40,30, 18,-46,26,
24,-35,40, 15,-43,27, 15,-31,40, 12,-44,27,
6,-22,39, 12,-44,27, 0,-32,37, 10,-47,26,
-2,-35,33, 10,-47,26, -1,-38,24, 10,-46,20,
-1,-38,24, 5,-31,14, -1,-38,24, -8,-27,28,
-2,-35,33, -5,-25,37, 0,-32,37, -3,-17,40,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?