/* Public domain */ /* * This program demonstrates the use of the SG_View widget to * display a scene. */ #include #include #include #include #include #include AG_Timeout rotTimer; SG_Ball *center; static Uint32 Rotate(void *obj, Uint32 t, void *arg) { SG_Camera *cam = arg; SG_Orbitvd(cam, M_VecZero3(), M_VecJ3(), 1.0); return (t); } static void CreateWindow(void) { AG_Window *win; SG_View *sv; AG_HBox *hb; SG_Ball *s1, *s2; SG_Light *lt; SG *sg; int i; M_Real angle = 60.0; /* Create a new scene graph. */ sg = SG_New(NULL, "MyScene", 0); /* Display the object tree using the Agar-DEV VFS browser. */ DEV_Browser(sg); /* Create a bunch of spheres. */ s1 = center = SG_BallNew(sg->root, "Sphere A"); for (i = 0; i < 60; i++) { s2 = SG_BallNew(s1, "Sphere B"); s1 = s2; SG_Rotatev(s1, angle, M_VecJ3()); SG_Translate(s1, 2.0, 0.4, 0.0); angle -= 0.4; } /* Create a new light source. */ lt = SG_LightNew(sg->root, "MyLight"); SG_Translate(lt, 5.0, 3.0, 2.0); lt->ambient = M_ColorRGB(0.0, 1.0, 0.0); /* Set ambient color */ lt->diffuse = lt->ambient; /* Set diffuse color */ lt->Kc = 0.5; /* Set constant attenuation */ lt->Kl = 0.05; /* Set linear attenuation */ /* Create a window containing a SG_View widget. */ win = AG_WindowNew(0); AG_WindowSetCaptionS(win, "Scene"); sv = SG_ViewNew(win, sg, SG_VIEW_EXPAND); /* Move the default camera. */ SG_Translate(sv->cam, 0.0, 15.0, 30.0); AG_WindowSetGeometryAlignedPct(win, AG_WINDOW_MC, 60, 40); AG_WindowShow(win); AG_SetTimeout(&rotTimer, Rotate, sv->cam, 0); AG_ScheduleTimeout(sv, &rotTimer, 10); } int main(int argc, char *argv[]) { if (AG_InitCore("sgview-demo", 0) == -1) { fprintf(stderr, "%s\n", AG_GetError()); return (1); } if (AG_InitGraphics("") == -1) { fprintf(stderr, "%s\n", AG_GetError()); return (-1); } SG_InitSubsystem(); DEV_InitSubsystem(0); /* Set some useful hotkeys */ AG_BindGlobalKey(AG_KEY_ESCAPE, AG_KEYMOD_ANY, AG_Quit); AG_BindGlobalKey(AG_KEY_F8, AG_KEYMOD_ANY, AG_ViewCapture); CreateWindow(); AG_EventLoop(); return (0); }