22#if defined(WIN32) || defined(__APPLE__)
50 printf(
"timer1, time=%d\n", (
int)time);
54 GLfloat inner_radius, GLfloat outer_radius, GLfloat width, GLint teeth, GLfloat tooth_depth)
60 const double pi = 3.14159264;
63 r1 = (
float)(outer_radius - tooth_depth / 2.0);
64 r2 = (
float)(outer_radius + tooth_depth / 2.0);
66 da = (
float)(2.0 * pi / teeth / 4.0);
68 glShadeModel(GL_FLAT);
69 glNormal3f(0.0, 0.0, 1.0);
72 glBegin(GL_QUAD_STRIP);
73 for (i = 0; i <= teeth; i++) {
74 angle = (
float)(i * 2.0 * pi / teeth);
75 glVertex3f((
float)(r0 *
cos(angle)), (
float)(r0 * sin(angle)), (
float)(width * 0.5));
76 glVertex3f((
float)(r1 *
cos(angle)), (
float)(r1 * sin(angle)), (
float)(width * 0.5));
77 glVertex3f((
float)(r0 *
cos(angle)), (
float)(r0 * sin(angle)), (
float)(width * 0.5));
78 glVertex3f((
float)(r1 *
cos(angle + 3 * da)),
79 (
float)(r1 * sin(angle + 3 * da)),
80 (
float)(width * 0.5));
86 da = (
float)(2.0 * pi / teeth / 4.0);
87 for (i = 0; i < teeth; i++) {
88 angle = (
float)(i * 2.0 * pi / teeth);
89 glVertex3f((
float)(r1 *
cos(angle)), (
float)(r1 * sin(angle)), (
float)(width * 0.5));
90 glVertex3f((
float)(r2 *
cos(angle + da)), (
float)(r2 * sin(angle + da)), (
float)(width * 0.5));
91 glVertex3f((
float)(r2 *
cos(angle + 2 * da)),
92 (
float)(r2 * sin(angle + 2 * da)),
93 (
float)(width * 0.5));
94 glVertex3f((
float)(r1 *
cos(angle + 3 * da)),
95 (
float)(r1 * sin(angle + 3 * da)),
96 (
float)(width * 0.5));
100 glNormal3f(0.0, 0.0, -1.0);
103 glBegin(GL_QUAD_STRIP);
104 for (i = 0; i <= teeth; i++) {
105 angle = (
float)(i * 2.0 * pi / teeth);
106 glVertex3f((
float)(r1 *
cos(angle)), (
float)(r1 * sin(angle)), (
float)(-width * 0.5));
107 glVertex3f((
float)(r0 *
cos(angle)), (
float)(r0 * sin(angle)), (
float)(-width * 0.5));
108 glVertex3f((
float)(r1 *
cos(angle + 3 * da)),
109 (
float)(r1 * sin(angle + 3 * da)),
110 (
float)(-width * 0.5));
111 glVertex3f((
float)(r0 *
cos(angle)), (
float)(r0 * sin(angle)), (
float)(-width * 0.5));
117 da = (
float)(2.0 * pi / teeth / 4.0);
118 for (i = 0; i < teeth; i++) {
119 angle = (
float)(i * 2.0 * pi / teeth);
120 glVertex3f((
float)(r1 *
cos(angle + 3 * da)),
121 (
float)(r1 * sin(angle + 3 * da)),
122 (
float)(-width * 0.5));
123 glVertex3f((
float)(r2 *
cos(angle + 2 * da)),
124 (
float)(r2 * sin(angle + 2 * da)),
125 (
float)(-width * 0.5));
127 (
float)(r2 *
cos(angle + da)), (
float)(r2 * sin(angle + da)), (
float)(-width * 0.5));
128 glVertex3f((
float)(r1 *
cos(angle)), (
float)(r1 * sin(angle)), (
float)(-width * 0.5));
133 glBegin(GL_QUAD_STRIP);
134 for (i = 0; i < teeth; i++) {
135 angle = (
float)(i * 2.0 * pi / teeth);
136 glVertex3f((
float)(r1 *
cos(angle)), (
float)(r1 * sin(angle)), (
float)(width * 0.5));
137 glVertex3f((
float)(r1 *
cos(angle)), (
float)(r1 * sin(angle)), (
float)(-width * 0.5));
138 u = (
float)(r2 *
cos(angle + da) - r1 *
cos(angle));
139 v = (
float)(r2 * sin(angle + da) - r1 * sin(angle));
143 glNormal3f(
v, -u, 0.0);
144 glVertex3f((
float)(r2 *
cos(angle + da)), (
float)(r2 * sin(angle + da)), (
float)(width * 0.5));
146 (
float)(r2 *
cos(angle + da)), (
float)(r2 * sin(angle + da)), (
float)(-width * 0.5));
147 glNormal3f((
float)(
cos(angle)), (
float)(sin(angle)), 0.0);
148 glVertex3f((
float)(r2 *
cos(angle + 2 * da)),
149 (
float)(r2 * sin(angle + 2 * da)),
150 (
float)(width * 0.5));
151 glVertex3f((
float)(r2 *
cos(angle + 2 * da)),
152 (
float)(r2 * sin(angle + 2 * da)),
153 (
float)(-width * 0.5));
154 u = (
float)(r1 *
cos(angle + 3 * da) - r2 *
cos(angle + 2 * da));
155 v = (
float)(r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da));
156 glNormal3f(
v, -u, 0.0);
157 glVertex3f((
float)(r1 *
cos(angle + 3 * da)),
158 (
float)(r1 * sin(angle + 3 * da)),
159 (
float)(width * 0.5));
160 glVertex3f((
float)(r1 *
cos(angle + 3 * da)),
161 (
float)(r1 * sin(angle + 3 * da)),
162 (
float)(-width * 0.5));
163 glNormal3f((
float)(
cos(angle)), (
float)(sin(angle)), 0.0);
165 glVertex3f((
float)(r1 *
cos(0.0)), (
float)(r1 * sin(0.0)), (
float)(width * 0.5));
166 glVertex3f((
float)(r1 *
cos(0.0)), (
float)(r1 * sin(0.0)), (
float)(-width * 0.5));
169 glShadeModel(GL_SMOOTH);
172 glBegin(GL_QUAD_STRIP);
173 for (i = 0; i <= teeth; i++) {
174 angle = (
float)(i * 2.0 * pi / teeth);
175 glNormal3f((
float)(-
cos(angle)), (
float)(-sin(angle)), 0.0);
176 glVertex3f((
float)(r0 *
cos(angle)), (
float)(r0 * sin(angle)), (
float)(-width * 0.5));
177 glVertex3f((
float)(r0 *
cos(angle)), (
float)(r0 * sin(angle)), (
float)(width * 0.5));
184 static GLfloat
pos[4] = {5.0f, 5.0f, 10.0f, 1.0f};
185 static GLfloat ared[4] = {0.8f, 0.1f, 0.0f, 1.0f};
186 static GLfloat agreen[4] = {0.0f, 0.8f, 0.2f, 1.0f};
187 static GLfloat ablue[4] = {0.2f, 0.2f, 1.0f, 1.0f};
189 glLightfv(GL_LIGHT0, GL_POSITION,
pos);
190 glEnable(GL_CULL_FACE);
191 glEnable(GL_LIGHTING);
193 glEnable(GL_DEPTH_TEST);
197 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ared);
198 gearGL(1.0f, 4.0f, 1.0f, 20, 0.7f);
201 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, agreen);
202 gearGL(0.5f, 2.0f, 2.0f, 10, 0.7f);
205 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ablue);
206 gearGL(1.3f, 2.0f, 0.5f, 10, 0.7f);
211 glEnable(GL_NORMALIZE);
216 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
225 glTranslatef(-3.0, -2.0, 0.0);
226 glRotatef(
fAngle, 0.0, 0.0, 1.0);
231 glTranslatef(3.1f, -2.0f, 0.0f);
232 glRotatef((
float)(-2.0 *
fAngle - 9.0), 0.0, 0.0, 1.0);
237 glTranslatef(-3.1f, 2.2f, -1.8f);
238 glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
239 glRotatef((
float)(2.0 *
fAngle - 2.0), 0.0, 0.0, 1.0);
248 GHOST_RectangleHandle hRect =
NULL;
259 glMatrixMode(GL_PROJECTION);
261 glFrustum(-
w,
w, -h, h, 5.0, 60.0);
263 glMatrixMode(GL_MODELVIEW);
265 glTranslatef(0.0, 0.0, -40.0);
267 glClearColor(.2f, 0.0f, 0.0f, 0.0f);
268 glClear(GL_COLOR_BUFFER_BIT);
287 case GHOST_kEventCursorButton:
294 if (wheelData->
z > 0) {
308 switch (keyData->
key) {
367 char *ntitle = malloc(strlen(title) + 2);
369 sprintf(ntitle,
"%s-", title);
424 char *title1 =
"gears - main window";
425 char *title2 =
"gears - secondary window";
443 GHOST_kDrawingContextTypeOpenGL,
446 printf(
"could not create main window\n");
460 GHOST_kDrawingContextTypeOpenGL,
463 printf(
"could not create secondary window\n");
498 GHOST_WindowHandle hWindow =
NULL;
void BLI_kdtree_nd_ free(KDTree *tree)
static void gearsTimerProc(GHOST_TimerTaskHandle task, uint64_t time)
static GHOST_WindowHandle sFullScreenWindow
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)
static GHOST_TimerTaskHandle sGearsTimer
static int sExitRequested
static void drawGearGL(int id)
static GHOST_TStandardCursor sCursor
static GHOST_WindowHandle sSecondaryWindow
bool processEvent(GHOST_EventHandle hEvent, GHOST_TUserDataPtr userData)
GHOST C-API function and type declarations.
int32_t GHOST_GetWidthRectangle(GHOST_RectangleHandle rectanglehandle)
bool GHOST_GetFullScreen(GHOST_SystemHandle systemhandle)
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)
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_EndFullScreen(GHOST_SystemHandle systemhandle)
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_TSuccess GHOST_SwapWindowBuffers(GHOST_WindowHandle windowhandle)
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)
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 gpuSettings)
bool GHOST_ValidWindow(GHOST_SystemHandle systemhandle, GHOST_WindowHandle windowhandle)
GHOST_TEventType GHOST_GetEventType(GHOST_EventHandle eventhandle)
GHOST_WindowHandle GHOST_BeginFullScreen(GHOST_SystemHandle systemhandle, const GHOST_DisplaySetting *setting, const bool stereoVisual)
GHOST_WindowHandle GHOST_GetEventWindow(GHOST_EventHandle eventhandle)
char * GHOST_GetTitle(GHOST_WindowHandle windowhandle)
void GHOST_DispatchEvents(GHOST_SystemHandle systemhandle)
GHOST_RectangleHandle GHOST_GetClientBounds(GHOST_WindowHandle windowhandle)
GHOST_TimerTaskHandle GHOST_InstallTimer(GHOST_SystemHandle systemhandle, uint64_t delay, uint64_t interval, GHOST_TimerProcPtr timerProc, GHOST_TUserDataPtr user_data)
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
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
draw_view in_light_buf[] float
ccl_device_inline float3 cos(float3 v)
unsigned __int64 uint64_t