-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3DCUBE.c
186 lines (157 loc) · 7.06 KB
/
3DCUBE.c
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
/*****************************************************************/
/* */
/* CASIO fx-9860G SDK Library */
/* */
/* File name : [ProjectName].c */
/* */
/* Copyright (c) 2006 CASIO COMPUTER CO., LTD. */
/* */
/*****************************************************************/
#include "fxlib.h"
#include <stdio.h>
#include <math.h>
#include <mathf.h>
void DrawCube(int x, int y, int heigth, int rotatez, int radius, float stretchx, float stretchy, int debug){
int iteration = 0;
float rad = 0;
float radone = 0;
float radtwo = 0;
if(debug==1){
while(iteration<360){
Bdisp_SetPoint_VRAM(stretchx*(radius*sin(iteration))+x, stretchy*(radius*cos(iteration))+y, 1);
Bdisp_SetPoint_VRAM(stretchx*(radius*sin(iteration))+x, stretchy*(radius*cos(iteration))+y+heigth, 1);
iteration = iteration + 1;
}
}
//draw vertical lines of cube
iteration = 0;
while(iteration<361){
rad = ((iteration+rotatez)/180.0)*3.141592;
Bdisp_DrawLineVRAM(stretchx*(radius*sin(rad))+x, stretchy*(radius*cos(rad))+y, stretchx*(radius*sin(rad))+x, stretchy*(radius*cos(rad))+y+heigth);
iteration = iteration +90;
}
//conect vertical lines
iteration = 0;
while(iteration<361){
radone = ((iteration+rotatez)/180.0)*3.141592;
radtwo = (((iteration+90)+rotatez)/180.0)*3.141592;
Bdisp_DrawLineVRAM(stretchx*(radius*sin(radone))+x, stretchy*(radius*cos(radone))+y+heigth, stretchx*(radius*sin(radtwo))+x, stretchy*(radius*cos(radtwo))+y+heigth);
Bdisp_DrawLineVRAM(stretchx*(radius*sin(radone))+x, stretchy*(radius*cos(radone))+y, stretchx*(radius*sin(radtwo))+x, stretchy*(radius*cos(radtwo))+y);
iteration = iteration +90;
}
// Bdisp_SetPoint_VRAM(stretchx*(radius*sin(rad))+x, stretchy*(radius*cos(rad))+y+10, 1);
}
void DrawPyramid(int x, int y, int heigth, int rotatez, int radius, float stretchx, float stretchy, int nr_sides,int debug){
int iteration = 0;
float rad = 0;
float radone = 0;
float radtwo = 0;
if(debug==1){
while(iteration<360){
Bdisp_SetPoint_VRAM(stretchx*(radius*sin(iteration))+x, stretchy*(radius*cos(iteration))+y, 1);
iteration = iteration + 1;
}
}
//draw vertical lines of pyramid
iteration = 0;
while(iteration<361){
rad = ((iteration+rotatez)/180.0)*3.141592;
Bdisp_DrawLineVRAM(x, y-heigth, stretchx*(radius*sin(rad))+x, stretchy*(radius*cos(rad))+y);
iteration = iteration + (360/nr_sides);
}
//conect vertical lines
iteration = 0;
while(iteration<361){
radone = ((iteration+rotatez)/180.0)*3.141592;
radtwo = (((iteration+(360/nr_sides))+rotatez)/180.0)*3.141592;
Bdisp_DrawLineVRAM(stretchx*(radius*sin(radone))+x, stretchy*(radius*cos(radone))+y, stretchx*(radius*sin(radtwo))+x, stretchy*(radius*cos(radtwo))+y);
iteration = iteration + (360/nr_sides);
}
}
void DrawPrism(int x, int y, int heigth, int rotatez, int radius, float stretchx, float stretchy, int nr_sides,int debug){
int iteration = 0;
float rad = 0;
float radone = 0;
float radtwo = 0;
if(debug==1){
while(iteration<360){
Bdisp_SetPoint_VRAM(stretchx*(radius*sin(iteration))+x, stretchy*(radius*cos(iteration))+y, 1);
iteration = iteration + 1;
}
}
//draw vertical lines of pyramid
iteration = 0;
while(iteration<361){
rad = ((iteration+rotatez)/180.0)*3.141592;
Bdisp_DrawLineVRAM(stretchx*(radius*sin(rad))+x, stretchy*(radius*cos(rad))+y, stretchx*(radius*sin(rad))+x, stretchy*(radius*cos(rad))+y-heigth);
iteration = iteration + (360/nr_sides);
}
//conect vertical lines
iteration = 0;
while(iteration<361){
radone = ((iteration+rotatez)/180.0)*3.141592;
radtwo = (((iteration+(360/nr_sides))+rotatez)/180.0)*3.141592;
Bdisp_DrawLineVRAM(stretchx*(radius*sin(radone))+x, stretchy*(radius*cos(radone))+y-heigth, stretchx*(radius*sin(radtwo))+x, stretchy*(radius*cos(radtwo))+y-heigth);
Bdisp_DrawLineVRAM(stretchx*(radius*sin(radone))+x, stretchy*(radius*cos(radone))+y, stretchx*(radius*sin(radtwo))+x, stretchy*(radius*cos(radtwo))+y);
iteration = iteration + (360/nr_sides);
}
}
//****************************************************************************
// 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
//
//****************************************************************************
int AddIn_main(int isAppli, unsigned short OptionNum)
{
unsigned int key;
int rotatez = 20;
float stretchx = 1;
float stretchy = 0.3;
int sidelength = 20;
Bdisp_AllClr_DDVRAM();
while(1){
GetKey(&key);
Bdisp_AllClr_DDVRAM();
if(key==KEY_CTRL_RIGHT){
rotatez = rotatez + 10;
}else if(key==KEY_CTRL_LEFT){
rotatez = rotatez - 10;
}
DrawCube(25,10,sidelength,rotatez,sidelength,stretchx,stretchy,0);
DrawPyramid(60,55,30,rotatez,sidelength,stretchx,stretchy,4,0);
DrawPrism(100,35,25,rotatez,sidelength,stretchx,stretchy,7,0);
}
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