22#if defined(WIN32) || defined(__APPLE__)
49 printf(
"timer1, time=%d\n", (
int)time);
53 GLfloat inner_radius, GLfloat outer_radius, GLfloat width, GLint teeth, GLfloat tooth_depth)
59 const double pi = 3.14159264;
62 r1 = (
float)(outer_radius - tooth_depth / 2.0);
63 r2 = (
float)(outer_radius + tooth_depth / 2.0);
65 da = (
float)(2.0 * pi / teeth / 4.0);
67 glShadeModel(GL_FLAT);
68 glNormal3f(0.0, 0.0, 1.0);
71 glBegin(GL_QUAD_STRIP);
72 for (
i = 0;
i <= teeth;
i++) {
74 glVertex3f((
float)(r0 *
cos(
angle)), (
float)(r0 *
sin(
angle)), (
float)(width * 0.5));
75 glVertex3f((
float)(r1 *
cos(
angle)), (
float)(r1 *
sin(
angle)), (
float)(width * 0.5));
76 glVertex3f((
float)(r0 *
cos(
angle)), (
float)(r0 *
sin(
angle)), (
float)(width * 0.5));
77 glVertex3f((
float)(r1 *
cos(
angle + 3 * da)),
79 (
float)(width * 0.5));
85 da = (
float)(2.0 * pi / teeth / 4.0);
86 for (
i = 0;
i < teeth;
i++) {
88 glVertex3f((
float)(r1 *
cos(
angle)), (
float)(r1 *
sin(
angle)), (
float)(width * 0.5));
89 glVertex3f((
float)(r2 *
cos(
angle + da)), (
float)(r2 *
sin(
angle + da)), (
float)(width * 0.5));
90 glVertex3f((
float)(r2 *
cos(
angle + 2 * da)),
92 (
float)(width * 0.5));
93 glVertex3f((
float)(r1 *
cos(
angle + 3 * da)),
95 (
float)(width * 0.5));
99 glNormal3f(0.0, 0.0, -1.0);
102 glBegin(GL_QUAD_STRIP);
103 for (
i = 0;
i <= teeth;
i++) {
105 glVertex3f((
float)(r1 *
cos(
angle)), (
float)(r1 *
sin(
angle)), (
float)(-width * 0.5));
106 glVertex3f((
float)(r0 *
cos(
angle)), (
float)(r0 *
sin(
angle)), (
float)(-width * 0.5));
107 glVertex3f((
float)(r1 *
cos(
angle + 3 * da)),
109 (
float)(-width * 0.5));
110 glVertex3f((
float)(r0 *
cos(
angle)), (
float)(r0 *
sin(
angle)), (
float)(-width * 0.5));
116 da = (
float)(2.0 * pi / teeth / 4.0);
117 for (
i = 0;
i < teeth;
i++) {
119 glVertex3f((
float)(r1 *
cos(
angle + 3 * da)),
121 (
float)(-width * 0.5));
122 glVertex3f((
float)(r2 *
cos(
angle + 2 * da)),
124 (
float)(-width * 0.5));
126 (
float)(r2 *
cos(
angle + da)), (
float)(r2 *
sin(
angle + da)), (
float)(-width * 0.5));
127 glVertex3f((
float)(r1 *
cos(
angle)), (
float)(r1 *
sin(
angle)), (
float)(-width * 0.5));
132 glBegin(GL_QUAD_STRIP);
133 for (
i = 0;
i < teeth;
i++) {
135 glVertex3f((
float)(r1 *
cos(
angle)), (
float)(r1 *
sin(
angle)), (
float)(width * 0.5));
136 glVertex3f((
float)(r1 *
cos(
angle)), (
float)(r1 *
sin(
angle)), (
float)(-width * 0.5));
142 glNormal3f(
v, -u, 0.0);
143 glVertex3f((
float)(r2 *
cos(
angle + da)), (
float)(r2 *
sin(
angle + da)), (
float)(width * 0.5));
145 (
float)(r2 *
cos(
angle + da)), (
float)(r2 *
sin(
angle + da)), (
float)(-width * 0.5));
147 glVertex3f((
float)(r2 *
cos(
angle + 2 * da)),
149 (
float)(width * 0.5));
150 glVertex3f((
float)(r2 *
cos(
angle + 2 * da)),
152 (
float)(-width * 0.5));
155 glNormal3f(
v, -u, 0.0);
156 glVertex3f((
float)(r1 *
cos(
angle + 3 * da)),
158 (
float)(width * 0.5));
159 glVertex3f((
float)(r1 *
cos(
angle + 3 * da)),
161 (
float)(-width * 0.5));
164 glVertex3f((
float)(r1 *
cos(0.0)), (
float)(r1 *
sin(0.0)), (
float)(width * 0.5));
165 glVertex3f((
float)(r1 *
cos(0.0)), (
float)(r1 *
sin(0.0)), (
float)(-width * 0.5));
168 glShadeModel(GL_SMOOTH);
171 glBegin(GL_QUAD_STRIP);
172 for (
i = 0;
i <= teeth;
i++) {
175 glVertex3f((
float)(r0 *
cos(
angle)), (
float)(r0 *
sin(
angle)), (
float)(-width * 0.5));
176 glVertex3f((
float)(r0 *
cos(
angle)), (
float)(r0 *
sin(
angle)), (
float)(width * 0.5));
183 static GLfloat
pos[4] = {5.0f, 5.0f, 10.0f, 1.0f};
184 static GLfloat ared[4] = {0.8f, 0.1f, 0.0f, 1.0f};
185 static GLfloat agreen[4] = {0.0f, 0.8f, 0.2f, 1.0f};
186 static GLfloat ablue[4] = {0.2f, 0.2f, 1.0f, 1.0f};
188 glLightfv(GL_LIGHT0, GL_POSITION,
pos);
189 glEnable(GL_CULL_FACE);
190 glEnable(GL_LIGHTING);
192 glEnable(GL_DEPTH_TEST);
196 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ared);
197 gearGL(1.0f, 4.0f, 1.0f, 20, 0.7f);
200 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, agreen);
201 gearGL(0.5f, 2.0f, 2.0f, 10, 0.7f);
204 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ablue);
205 gearGL(1.3f, 2.0f, 0.5f, 10, 0.7f);
210 glEnable(GL_NORMALIZE);
215 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
224 glTranslatef(-3.0, -2.0, 0.0);
225 glRotatef(
fAngle, 0.0, 0.0, 1.0);
230 glTranslatef(3.1f, -2.0f, 0.0f);
231 glRotatef((
float)(-2.0 *
fAngle - 9.0), 0.0, 0.0, 1.0);
236 glTranslatef(-3.1f, 2.2f, -1.8f);
237 glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
238 glRotatef((
float)(2.0 *
fAngle - 2.0), 0.0, 0.0, 1.0);
247 GHOST_RectangleHandle hRect = NULL;
258 glMatrixMode(GL_PROJECTION);
260 glFrustum(-
w,
w, -h, h, 5.0, 60.0);
262 glMatrixMode(GL_MODELVIEW);
264 glTranslatef(0.0, 0.0, -40.0);
266 glClearColor(.2f, 0.0f, 0.0f, 0.0f);
267 glClear(GL_COLOR_BUFFER_BIT);
285 case GHOST_kEventCursorButton:
292 if (wheelData->
value > 0) {
306 switch (keyData->
key) {
336 char *ntitle = malloc(strlen(title) + 2);
338 sprintf(ntitle,
"%s-", title);
394 char *title1 =
"gears - main window";
395 char *title2 =
"gears - secondary window";
413 GHOST_kDrawingContextTypeOpenGL,
416 printf(
"could not create main window\n");
430 GHOST_kDrawingContextTypeOpenGL,
433 printf(
"could not create secondary window\n");
468 GHOST_WindowHandle hWindow = NULL;
void BLI_kdtree_nd_ free(KDTree *tree)
static void gearsTimerProc(GHOST_TimerTaskHandle task, uint64_t time)
static GHOST_SystemHandle shSystem
static GHOST_WindowHandle sMainWindow
static void gearGL(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, GLint teeth, GLfloat tooth_depth)
static void setViewPortGL(GHOST_WindowHandle hWindow)
static GHOST_TimerTaskHandle sTestTimer
static void testTimerProc(GHOST_TimerTaskHandle task, uint64_t time)
bool processEvent(GHOST_EventHandle hEvent, GHOST_TUserDataPtr user_data)
static GHOST_TimerTaskHandle sGearsTimer
static int sExitRequested
static void drawGearGL(int id)
static GHOST_TStandardCursor sCursor
static GHOST_WindowHandle sSecondaryWindow
GHOST C-API function and type declarations.
int32_t GHOST_GetWidthRectangle(GHOST_RectangleHandle rectanglehandle)
GHOST_TSuccess GHOST_SwapWindowBufferRelease(GHOST_WindowHandle windowhandle)
GHOST_EventConsumerHandle GHOST_CreateEventConsumer(GHOST_EventCallbackProcPtr eventCallback, GHOST_TUserDataPtr user_data)
GHOST_SystemHandle GHOST_CreateSystem(void)
GHOST_TSuccess GHOST_AddEventConsumer(GHOST_SystemHandle systemhandle, GHOST_EventConsumerHandle consumerhandle)
GHOST_TSuccess GHOST_SwapWindowBufferAcquire(GHOST_WindowHandle windowhandle)
void GHOST_DisposeRectangle(GHOST_RectangleHandle rectanglehandle)
bool GHOST_ProcessEvents(GHOST_SystemHandle systemhandle, bool waitForEvent)
void GHOST_SetTitle(GHOST_WindowHandle windowhandle, const char *title)
GHOST_TSuccess GHOST_SetCursorShape(GHOST_WindowHandle windowhandle, GHOST_TStandardCursor cursorshape)
GHOST_TUserDataPtr GHOST_GetTimerTaskUserData(GHOST_TimerTaskHandle timertaskhandle)
GHOST_TSuccess GHOST_InvalidateWindow(GHOST_WindowHandle windowhandle)
GHOST_TSuccess GHOST_DisposeWindow(GHOST_SystemHandle systemhandle, GHOST_WindowHandle windowhandle)
GHOST_TSuccess GHOST_RemoveTimer(GHOST_SystemHandle systemhandle, GHOST_TimerTaskHandle timertaskhandle)
int32_t GHOST_GetHeightRectangle(GHOST_RectangleHandle rectanglehandle)
GHOST_TEventDataPtr GHOST_GetEventData(GHOST_EventHandle eventhandle)
bool GHOST_GetCursorVisibility(GHOST_WindowHandle windowhandle)
GHOST_TSuccess GHOST_SetCursorVisibility(GHOST_WindowHandle windowhandle, bool visible)
GHOST_TSuccess GHOST_ActivateWindowDrawingContext(GHOST_WindowHandle windowhandle)
bool GHOST_ValidWindow(GHOST_SystemHandle systemhandle, GHOST_WindowHandle windowhandle)
GHOST_TEventType GHOST_GetEventType(GHOST_EventHandle eventhandle)
GHOST_WindowHandle GHOST_GetEventWindow(GHOST_EventHandle eventhandle)
char * GHOST_GetTitle(GHOST_WindowHandle windowhandle)
GHOST_WindowHandle GHOST_CreateWindow(GHOST_SystemHandle systemhandle, GHOST_WindowHandle parent_windowhandle, const char *title, int32_t left, int32_t top, uint32_t width, uint32_t height, GHOST_TWindowState state, bool is_dialog, GHOST_GPUSettings gpu_settings)
void GHOST_DispatchEvents(GHOST_SystemHandle systemhandle)
GHOST_TimerTaskHandle GHOST_InstallTimer(GHOST_SystemHandle systemhandle, uint64_t delay, uint64_t interval, GHOST_TimerProcPtr timer_proc, GHOST_TUserDataPtr user_data)
GHOST_RectangleHandle GHOST_GetClientBounds(GHOST_WindowHandle windowhandle)
GHOST_TSuccess GHOST_DisposeSystem(GHOST_SystemHandle systemhandle)
@ GHOST_kWindowStateNormal
void * GHOST_TUserDataPtr
#define GHOST_kStandardCursorNumCursors
@ GHOST_kEventWindowClose
@ GHOST_kEventWindowActivate
@ GHOST_kEventWindowUpdate
@ GHOST_kEventWindowDeactivate
#define GHOST_kStandardCursorFirstCursor
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
ATTR_WARN_UNUSED_RESULT const BMVert * v
unsigned long long int uint64_t
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.