void PezUpdate(unsigned int elapsedMicroseconds) { const float RadiansPerMicrosecond = 0.0000005f; static float Theta = 0; Theta += elapsedMicroseconds * RadiansPerMicrosecond; Vector3 offset = V3MakeFromElems(0, 0, 0); Matrix4 model = M4MakeRotationZ(Theta); model = M4Mul(M4MakeTranslation(offset), model); model = M4Mul(model, M4MakeTranslation(V3Neg(offset))); Point3 eyePosition = P3MakeFromElems(0, 10, 0); Point3 targetPosition = P3MakeFromElems(0, 0, 0); Vector3 upVector = V3MakeFromElems(0, 0, 1); Matrix4 view = M4MakeLookAt(eyePosition, targetPosition, upVector); ModelviewMatrix = M4Mul(view, model); }
void PezUpdate(float seconds) { // Create the model-view matrix: Point3 eye = P3MakeFromElems(EyeVector[0] * EyeScale, EyeVector[1] * EyeScale, EyeVector[2] * EyeScale); Point3 target = P3MakeFromElems(TargetVector[0] * TargetScale, TargetVector[1] * TargetScale, TargetVector[2] * TargetScale); Vector3 up = V3MakeFromElems(0, 1, 0); Scene.ViewMatrix = M4MakeLookAt(eye, target, up); PezConfig cfg = PezGetConfig(); const float h = 5.0f; const float w = h * cfg.Width / cfg.Height; const float hither = 5; const float yon = 200; Scene.Projection = M4MakeFrustum(-w, w, -h, h, hither, yon); }
void draw() { int mesh = 0, multi = 0, meshcolor = 0; switch (state) { case STATE_GRAY_SOURCE: parg_shader_bind(P_GRAY); parg_texture_bind(graytex, 0); parg_uniform1f(U_ZSCALE, 1); break; case STATE_COLOR_IH: mesh = 1; parg_shader_bind(P_GRAYMESH); parg_uniform1f(U_ZSCALE, 0.3); break; case STATE_COLOR_DHSCSI: mesh = multi = 1; parg_shader_bind(P_GRAYMESH); parg_uniform1f(U_ZSCALE, 0.3); break; case STATE_MULTI_RGBA: case STATE_MULTI_RGB: case STATE_MULTI_DIAGRAM: meshcolor = mesh = multi = 1; parg_shader_bind(P_GRAYMESH); parg_uniform1f(U_ZSCALE, 0.25); break; case STATE_COLOR_DEFAULT: case STATE_GRAY_DEFAULT: case STATE_GRAY_SIMPLIFY: case STATE_GRAY_INVERT: case STATE_GRAY_HEIGHTS: mesh = 1; parg_shader_bind(P_GRAYMESH); parg_uniform1f(U_ZSCALE, 1); break; case STATE_GRAY_MULTI: mesh = multi = 1; parg_shader_bind(P_GRAYMESH); parg_texture_bind(colortex, 0); parg_uniform1f(U_ZSCALE, 0.3); break; case STATE_GRAY_DUAL: mesh = multi = 1; parg_shader_bind(P_GRAYMESH); parg_texture_bind(colortex, 0); parg_uniform1f(U_ZSCALE, 1); break; case STATE_GRAY_DHS: case STATE_GRAY_DHSC: mesh = multi = 1; parg_shader_bind(P_GRAYMESH); parg_texture_bind(colortex, 0); parg_uniform1f(U_ZSCALE, 0.5); break; case STATE_COLOR_SOURCE: parg_texture_bind(colortex, 0); parg_shader_bind(P_COLOR); parg_uniform1f(U_ZSCALE, 1); break; default: break; } if (mesh) { for (int i = 0; i < sizeof(trimesh) / sizeof(trimesh[0]); i++) { parg_mesh_free(trimesh[i]); } memset(trimesh, 0, sizeof(trimesh)); create_mesh(); } Matrix4 model; if (mesh) { model = M4MakeScale(V3MakeFromElems(20, 20, 10)); model = M4Mul(M4MakeTranslation(V3MakeFromElems(-10, -10, 0)), model); } else { model = M4MakeIdentity(); } Matrix4 modelview = M4Mul(view, model); Matrix4 mvp = M4Mul(projection, modelview); parg_uniform_matrix4f(U_MVP, &mvp); parg_draw_clear(); if (mesh) { Vector4 colors[3]; colors[0] = (Vector4){0, 0.6, 0.9, 1}; colors[1] = (Vector4){0, 0.9, 0.6, 1}; colors[2] = (Vector4){0.9, 0.6, 0, 1}; Vector4 black = {0, 0, 0, 1.0}; for (int imesh = 0; imesh < nmeshes; imesh++) { parg_varray_enable(parg_mesh_coord(trimesh[imesh]), A_POSITION, 3, PARG_FLOAT, 0, 0); parg_varray_bind(parg_mesh_index(trimesh[imesh])); if (meshcolor) { unsigned int b = meshcolors[imesh] & 0xff; unsigned int g = (meshcolors[imesh] >> 8) & 0xff; unsigned int r = (meshcolors[imesh] >> 16) & 0xff; unsigned int a = (meshcolors[imesh] >> 24) & 0xff; Vector4 color; color.x = r / 255.0f; color.y = g / 255.0f; color.z = b / 255.0f; color.w = a / 255.0f; parg_uniform4f(U_COLOR, &color); } else { parg_uniform4f(U_COLOR, &colors[imesh]); } parg_draw_triangles_u16(0, parg_mesh_ntriangles(trimesh[imesh])); parg_uniform4f(U_COLOR, &black); parg_draw_wireframe_triangles_u16( 0, parg_mesh_ntriangles(trimesh[imesh])); } } else {
static float Tesselation = 0.0; static float Wireframe = 0.0; static float Tagg = 0.0; static float ColNorm = 0.0; static float DCol = 0.0; // storage std::vector<float> Verts; std::vector<float> Faces; int nv; // Camera information Point3 eyePosition = P3MakeFromElems(0, 0, -10); Point3 targetPosition = P3MakeFromElems(0, 0, 1.0); Vector3 upVector = V3MakeFromElems(0, 1, 0); float camAngleX=0.0f, camAngleY=0.0f; // camera angles // Button information float mouseSensitivy = 0.001f; bool b_r = false; int mouseButton = 0; int mouseX = 0; int mouseY = 0; // selection int selID = 0; void PezRender(GLuint fbo) {