-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path3DENG.cpp
More file actions
440 lines (385 loc) · 11.2 KB
/
3DENG.cpp
File metadata and controls
440 lines (385 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
/*****************************************************************/
/* */
/* CASIO fx-9860G SDK Library */
/* */
/* File name : [ProjectName].c */
/* */
/* Copyright (c) 2006 CASIO COMPUTER CO., LTD. */
/* */
/*****************************************************************/
extern "C"{
#include "string.h"
#define __KEYBIOS_H__
#include "fxlib.h"
#define KEY_CHAR_0 71
#define KEY_CHAR_1 72
#define KEY_CHAR_2 62
#define KEY_CHAR_3 52
#define KEY_CHAR_4 73
#define KEY_CHAR_5 63
#define KEY_CHAR_6 53
#define KEY_CHAR_7 74
#define KEY_CHAR_8 64
#define KEY_CHAR_9 54
#define KEY_CHAR_DP 61
#define KEY_CHAR_EXP 51
#define KEY_CHAR_PMINUS 41
#define KEY_CHAR_PLUS 42
#define KEY_CHAR_MINUS 32
#define KEY_CHAR_MULT 43
#define KEY_CHAR_DIV 33
#define KEY_CHAR_FRAC 75
#define KEY_CHAR_LPAR 55
#define KEY_CHAR_RPAR 45
#define KEY_CHAR_COMMA 35
#define KEY_CHAR_STORE 25
#define KEY_CHAR_LOG 66
#define KEY_CHAR_LN 56
#define KEY_CHAR_SIN 46
#define KEY_CHAR_COS 36
#define KEY_CHAR_TAN 26
#define KEY_CHAR_SQUARE 67
#define KEY_CHAR_POW 57
#define KEY_CTRL_EXE 31
#define KEY_CTRL_DEL 44
#define KEY_CTRL_AC 32
#define KEY_CTRL_FD 65
#define KEY_CTRL_EXIT 47
#define KEY_CTRL_SHIFT 78
#define KEY_CTRL_ALPHA 77
#define KEY_CTRL_OPTN 68
#define KEY_CTRL_VARS 58
#define KEY_CTRL_UP 28
#define KEY_CTRL_DOWN 37
#define KEY_CTRL_LEFT 38
#define KEY_CTRL_RIGHT 27
#define KEY_CTRL_F1 79
#define KEY_CTRL_F2 69
#define KEY_CTRL_F3 59
#define KEY_CTRL_F4 49
#define KEY_CTRL_F5 39
#define KEY_CTRL_F6 29
#define KEY_CTRL_MENU 48
#ifndef OS2Change
#define OS2Change
#ifndef OS2Change_GetOS2
#define OS2Change_GetOS2
typedef int(*sc_i2cp2sip)(char*, char*, short int*, short int*);
const unsigned int sc0015[] = { 0xD201D002, 0x422B0009, 0x80010070, 0x0015 };
#define GlibGetOSVersionInfo (*(sc_i2cp2sip)sc0015)
int OSVersionAsInt(void)
{
unsigned char mainversion;
unsigned char minorversion;
unsigned short release;
unsigned short build;
GlibGetOSVersionInfo( (char *)&mainversion, (char *)&minorversion, (short *)&release, (short *)&build );
return ( ( mainversion << 24 ) & 0xFF000000 ) | ( ( minorversion << 16 ) & 0x00FF0000 ) | ( release & 0x0000FFFF );
}
#define isOS2 (OSVersionAsInt() >= 0x02020000)
#define OS2(x,y) ((OSVersionAsInt() >= 0x02020000)?y:x)
#endif
#ifndef OS2Change_Keyboard
#define OS2Change_Keyboard
void delay(void)
{
char i;
for (i=0; i<5; i++){};
}
unsigned char CheckKeyRow(unsigned char code)
{
unsigned char result=0;
short*PORTB_CTRL=(short*)0xA4000102;
short*PORTM_CTRL=(short*)0xA4000118;
char*PORTB=(char*)0xA4000122;
char*PORTM=(char*)0xA4000138;
char*PORTA=(char*)0xA4000120;
short smask;
char cmask;
unsigned char column, row;
column = code>>4;
row = code &0x0F;
smask = 0x0003 << (( row %8)*2);
cmask = ~( 1 << ( row %8) );
if(row <8)
{
*PORTB_CTRL = 0xAAAA ^ smask;
*PORTM_CTRL = (*PORTM_CTRL & 0xFF00 ) | 0x00AA;
delay();
*PORTB = cmask;
*PORTM = (*PORTM & 0xF0 ) | 0x0F;
}
else
{
*PORTB_CTRL = 0xAAAA;
*PORTM_CTRL = ((*PORTM_CTRL & 0xFF00 ) | 0x00AA) ^ smask;
delay();
*PORTB = 0xFF;
*PORTM = (*PORTM & 0xF0 ) | cmask;
}
delay();
result = (~(*PORTA))>>column & 1;
delay();
*PORTB_CTRL = 0xAAAA;
*PORTM_CTRL = (*PORTM_CTRL & 0xFF00 ) | 0x00AA;
delay();
*PORTB_CTRL = 0x5555;
*PORTM_CTRL = (*PORTM_CTRL & 0xFF00 ) | 0x0055;
delay();
return result;
}
unsigned char KeyDown(unsigned char keycode)
{
unsigned short key[8];
const unsigned short* keyboardregister = (unsigned short*)0xA44B0000;
if(isOS2)
{
unsigned char row = keycode%10;
memcpy(key, keyboardregister, sizeof(unsigned short) << 3);
return (0 != (key[row >> 1] & 1 << keycode / 10 - 1 + ((row & 1) << 3)));
}
else
{
return CheckKeyRow((keycode % 10) + ((keycode / 10 - 1) << 4));
}
}
unsigned char GetKeyMod(unsigned int *key)
{
unsigned char x, ret;
ret = GetKey(key);
for(x = 0; x < 80; x++)
{
if(KeyDown(x))
{
*key = x;
break;
}
}
return ret;
}
#define IsKeyDown(x) KeyDown(x)
#define IsKeyUp(x) !KeyDown(x)
#define GetKey(x) GetKeyMod(x)
#endif
#endif
}
extern "C"{
#include "fxlib.h"
#include "stdio.h"
#include "stdlib.h"
#include "timer.h"
}
#include "engine.h"
//****************************************************************************
// AddIn_main (Sample program main function)
//
// param : isAppli : 1 = This application is launched by MAIN MENU.
// : 0 = This application is launched by a strip in eACT application.
//
// OptionNum : Strip number (0~3)
// (This parameter is only used when isAppli parameter is 0.)
//
// retval : 1 = No error / 0 = Error
//
//****************************************************************************
unsigned int key1, key2, unused;
Mesh* mesh;
Mesh* meshes[1];
bool rotating = false;
int rotation_counter = 0;
#define LEFT 0
#define RIGHT 1
#define UP 2
#define DOWN 3
extern "C"{
void rotate(int direction, double rotation){
switch(direction){
case LEFT:
mesh->rotation.z-=rotation;
break;
case RIGHT:
mesh->rotation.z+=rotation;
break;
case UP:
break;
case DOWN:
break;
}
}
void rotate_left(){
rotating = true;
mesh->rotation.z -= 0.08;
if(rotation_counter >= 20){
KillTimer(ID_USER_TIMER1);
rotating = false;
rotation_counter = 0;
mesh->rotation.z = 0.0;
}
rotation_counter++;
}
void rotate_right(){
rotating = true;
mesh->rotation.z += 0.08;
if(rotation_counter >= 20){
KillTimer(ID_USER_TIMER1);
rotating = false;
rotation_counter = 0;
mesh->rotation.z = 0.0;
}
rotation_counter++;
}
void rotate_down(){
rotating = true;
mesh->rotation.x += 0.08;
if(rotation_counter >= 20){
KillTimer(ID_USER_TIMER1);
rotating = false;
rotation_counter = 0;
mesh->rotation.x = 0.0;
}
rotation_counter++;
}
void rotate_up(){
rotating = true;
mesh->rotation.x -= 0.08;
if(rotation_counter >= 20){
KillTimer(ID_USER_TIMER1);
rotating = false;
rotation_counter = 0;
mesh->rotation.x = 0.0;
}
rotation_counter++;
}
bool handle_keys(){
if(IsKeyDown(KEY_CTRL_MENU) || IsKeyDown(KEY_CTRL_EXIT)){
return false;
}
/*if(IsKeyDown(KEY_CTRL_LEFT)){
if(!rotating){
SetTimer(ID_USER_TIMER1, 1, rotate_left);
rotation_counter = 0;
}
}
if(IsKeyDown(KEY_CTRL_RIGHT)){
if(!rotating){
SetTimer(ID_USER_TIMER1, 1, rotate_right);
rotation_counter = 0;
}
}
if(IsKeyDown(KEY_CTRL_UP)){
if(!rotating){
SetTimer(ID_USER_TIMER1, 1, rotate_up);
rotation_counter = 0;
}
}
if(IsKeyDown(KEY_CTRL_DOWN)){
if(!rotating){
SetTimer(ID_USER_TIMER1, 1, rotate_down);
rotation_counter = 0;
}
}*/
return true;
}
void draw_text(unsigned char* text, int x, int y){
locate(x,y);
Print(text);
}
int itoa(int value, char *sp, int radix)
{
char tmp[16];// be careful with the length of the buffer
char *tp = tmp;
int i;
unsigned v;
int sign = (radix == 10 && value < 0);
if (sign)
v = -value;
else
v = (unsigned)value;
while (v || tp == tmp)
{
i = v % radix;
v /= radix; // v/=radix uses less CPU clocks than v=v/radix does
if (i < 10)
*tp++ = i+'0';
else
*tp++ = i + 'a' - 10;
}
int len = tp - tmp;
if (sign)
{
*sp++ = '-';
len++;
}
while (tp > tmp)
*sp++ = *--tp;
return len;
}
}
void main(){
Engine eng = Engine();
Camera cam = Camera();
mesh = new Mesh(8, 12, 0);
mesh->vertices[0] = Vector3(-1, 1, 1);
mesh->vertices[1] = Vector3(1, 1, 1);
mesh->vertices[2] = Vector3(-1,-1,1);
mesh->vertices[3] = Vector3(1,-1,1);
mesh->vertices[4] = Vector3(-1, 1, -1);
mesh->vertices[5] = Vector3(1,1,-1);
mesh->vertices[6] = Vector3(1,-1,-1);
mesh->vertices[7] = Vector3(-1,-1,-1);
mesh->faces[0] = Face(0, 1, 2);
mesh->faces[1] = Face(1, 2, 3);
mesh->faces[2] = Face(1, 3, 6);
mesh->faces[3] = Face(1, 5, 6);
mesh->faces[4] = Face(0, 1, 4);
mesh->faces[5] = Face(1, 4, 5);
mesh->faces[6] = Face(2, 3, 7);
mesh->faces[7] = Face(3, 6, 7);
mesh->faces[8] = Face(0, 2, 7);
mesh->faces[9] = Face(0, 4, 7);
mesh->faces[10]= Face(4, 5, 6);
mesh->faces[11]= Face(4, 6, 7);
meshes[0] = mesh;
cam.position = Vector3(0,0,10);
cam.target = Vector3(0,0,0);
mesh->position = Vector3(0,0,0);
while(handle_keys()){
eng.clear();
mesh->rotation.x += 0.02;
mesh->rotation.y += 0.02;
eng.render(cam, meshes);
eng.present();
}
}
extern "C"{
int AddIn_main(int isAppli, unsigned short OptionNum)
{
main();
return 1;
}
}
//****************************************************************************
//************** ****************
//************** Notice! ****************
//************** ****************
//************** Please do not change the following source. ****************
//************** ****************
//****************************************************************************
#pragma section _BR_Size
unsigned long BR_Size;
#pragma section
#pragma section _TOP
//****************************************************************************
// InitializeSystem
//
// param : isAppli : 1 = Application / 0 = eActivity
// OptionNum : Option Number (only eActivity)
//
// retval : 1 = No error / 0 = Error
//
//****************************************************************************
int InitializeSystem(int isAppli, unsigned short OptionNum)
{
return INIT_ADDIN_APPLICATION(isAppli, OptionNum);
}
#pragma section