SpectatorCamera::SpectatorCamera() { mPos = vi_set(0.0f, 0.0f, 0.0f, 1.0f); mOrient = vi_set(0.0f, 0.0f, 0.0f, 1.0f); mVelocity = vi_set_zero(); mAccumPitch = 0.0f; rotationSpeed = DEFAULT_ROTATION_SPEED; }
void SpectatorCamera::updatePosition(float dx, float dy, float dz, float dt) { // Continuously update the camera's velocity vector even if the camera // hasn't moved during this call. When the camera is no longer being moved // the camera is decelerating back to its stationary state. // Updates the camera's velocity based on the supplied movement direction // and the elapsed time (since this method was last called). The movement // direction is in the range [-1,1]. v128 dir, delta, vp, mv, dv, a, mask; dir = vi_set(dx, dy, -dz, 0.0f); vp = mVelocity; mv = vi_load_v3(&maxVelocity); a = vi_load_v3(&acceleration); mask = vi_cmp_eq(dir, vi_set_zero()); // choose direction for deacceleration if corresponding delta==0 dir = vi_select(dir, vi_neg(vi_sign(vp)), mask); // calculate new velocity v = dir * a * dt + pv dv = vi_mul(vi_set(dt, dt, dt, 0.0f), a); mVelocity = vi_mad(dir, dv, vp); mask = vi_and(mask, vi_cmp_lt(vi_abs(vp), dv)); // in order to stop movement when deaccelerating // make zero all coefficients accordingly to mask mVelocity = vi_andnot(mVelocity, mask); // and clip result to [-maxVelocity, maxVelocity] // in order to not exceed maximum velocity mVelocity = vi_clamp(mVelocity, vi_neg(mv), mv); // integrate distance using trapezoid rule(midpoint integration) float dt_div_2 = 0.5f * dt; delta = vi_mul(vi_set(dt_div_2, dt_div_2, dt_div_2, 0.0f), vi_add(vp, mVelocity)); mPos = vi_add( ml::rotate_vec3_quat( ml::conjugate_quat(mOrient), vi_swizzle<0, 3, 2, 3>(delta) ), mPos ); mPos.m128_f32[1] += delta.m128_f32[1]; }
void SpectatorCamera::rotateSmoothly(float heading, float pitch) { v128 r; heading *= -rotationSpeed; pitch *= -rotationSpeed; mAccumPitch += pitch; if (mAccumPitch > FLT_PI_OVER_2) { pitch = FLT_PI_OVER_2 - (mAccumPitch - pitch); mAccumPitch = FLT_PI_OVER_2; } if (mAccumPitch < -FLT_PI_OVER_2) { pitch = -FLT_PI_OVER_2 - (mAccumPitch - pitch); mAccumPitch = -FLT_PI_OVER_2; } // Rotate camera first around y axis, then around x axis. // Note the order the quaternions are multiplied. That is important! r = ml::axis_angle_to_quat(vi_set(0.0f, 1.0f, 0.0f, 0.0f), heading); mOrient = ml::mul_quat(mOrient, r); r = ml::axis_angle_to_quat(vi_set_x(1.0f), pitch); mOrient = ml::mul_quat(r, mOrient); }
void render() { cpu_timer_start(&cpuTimer); gfx::gpu_timer_start(&gpuTimer); glClearColor(0.3f, 0.3f, 0.32f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); gfx::set2DStates(); gfx::setUIMatrices(); v128 mv[4] = { vi_set( mScale, 0.0f, 0.0f, 0.0f), vi_set( 0.0f, mScale, 0.0f, 0.0f), vi_set( 0.0f, 0.0f, 1.0f, 0.0f), vi_set(mOffsetX, mOffsetY, 0.0f, 1.0f), }; gfx::setModelViewMatrix(mv); if (ui::checkBoxIsChecked(mAAEnabled)) { for (size_t i=mPaths.size(); i!=0; i--) vg::drawPath(mPaths[i-1], mPaints[i-1], true, true); } else { glDisable(GL_MULTISAMPLE); for (size_t i=mPaths.size(); i!=0; i--) vg::drawPath(mPaths[i-1], mPaints[i-1], true, false); glEnable(GL_MULTISAMPLE); } cpu_timer_stop(&cpuTimer); gfx::gpu_timer_stop(&gpuTimer); ml::make_identity_mat4(mv); gfx::setModelViewMatrix(mv); ui::displayStats( 10.0f, 10.0f, 300.0f, 100.0f, cpu_timer_measured(&cpuTimer) / 1000.0f, gfx::gpu_timer_measured(&gpuTimer) / 1000.0f ); vg::drawString(vg::defaultFont, 46.0f, 96.0f, 0xFFFFFFFF, "Enable AA", 9); }
void ShaderEditOverlay::renderFullscreen() { //update logic if (timerAbsoluteTime()>mNextTick) { mShaderEditor.Tick(); mDebugOutputView.Tick(); mNextTick = timerAbsoluteTime()+TICK_INTERVAL; } BraceMatch(mShaderEditor); glEnable(GL_SCISSOR_TEST); float w1=mWidth-80.0f, h1=mHeight-80.0f; v128 mv[4]; ml::make_identity_mat4(mv); { PROFILER_CPU_TIMESLICE("mSelectionList.Paint"); mv[3] = vi_set(30.0f, 30.0f, 0.0f, 1.0f); gfx::setModelViewMatrix(mv); mSelectionList.Paint(); } { PROFILER_CPU_TIMESLICE("mShaderEditor.Paint"); mv[3] = vi_set(w1*0.3f+50.0f, 30.0f, 0.0f, 1.0f); gfx::setModelViewMatrix(mv); mShaderEditor.Paint(); } { PROFILER_CPU_TIMESLICE("mDebugOutputView.Paint"); mv[3] = vi_set(w1*0.3f+50.0f, h1*0.7f+50.0f, 0.0f, 1.0f); gfx::setModelViewMatrix(mv); mDebugOutputView.Paint(); } glDisable(GL_SCISSOR_TEST); }
void SpectatorCamera::lookAt(v128 eye, v128 dir) { mPos = eye; v128 xaxis, yaxis, zaxis; zaxis = ml::normalize(dir); xaxis = vi_cross3(vi_set(0.0f, 1.0f, 0.0f, 0.0f), zaxis); xaxis = ml::normalize(xaxis); yaxis = vi_cross3(zaxis, xaxis); yaxis = ml::normalize(yaxis); v128 m[3] = {xaxis, yaxis, zaxis}; // Extract the pitch angle from the view matrix. mAccumPitch = ml::asin(m[2].m128_f32[1]); mOrient = ml::conjugate_quat(ml::mat4x3_to_quat(m)); }
void render() { ui::processZoomAndPan(zoom, offsetX, offsetY, doMove); gfx::set2DStates(); gfx::setUIMatrices(); v128 mv[4] = { vi_set( zoom, 0.0f, 0.0f, 0.0f), vi_set( 0.0f, zoom, 0.0f, 0.0f), vi_set( 0.0f, 0.0f, 1.0f, 0.0f), vi_set(offsetX, offsetY, 0.0f, 1.0f), }; gfx::setModelViewMatrix(mv); vg::drawPath(testPath, 0xFFFFFFFF, false); vg::drawPath(testPathOff, 0xFF0000FF, true); float p[] = { controlPts[0].x/controlPts[0].z, controlPts[0].y/controlPts[0].z, controlPts[1].x/controlPts[1].z, controlPts[1].y/controlPts[1].z, controlPts[2].x/controlPts[2].z, controlPts[2].y/controlPts[2].z, controlPts[3].x/controlPts[3].z, controlPts[3].y/controlPts[3].z, }; gfx::draw2DLineStrip(p, ARRAY_SIZE(p)/ 2, 0xFF0000FF); /* return; float vp[4]; glGetFloatv(GL_VIEWPORT, vp); glPushMatrix(); if (bool alphaAA = false) { glDisable(GL_STENCIL_TEST); glMatrixMode(GL_MODELVIEW); glTranslatef(offsetX, offsetY, 0); glScalef(zoom, zoom, 1); glPushMatrix(); glTranslatef(-40, -40, 0); glScalef(80, 80, 1); clearAlpha(); glPopMatrix(); rasterizeEvenOddAA(rcubic); rasterizeEvenOddAA(rtri); glUseProgram(0); glPushMatrix(); glTranslatef(-40, -40, 0); glScalef(80, 80, 1); drawAlphaQuad(); glPopMatrix(); glColor3f(1, 0, 0); glBegin(GL_LINE_STRIP); glVertex2f(controlPts[0].x/controlPts[0].z, controlPts[0].y/controlPts[0].z); glVertex2f(controlPts[1].x/controlPts[1].z, controlPts[1].y/controlPts[1].z); glVertex2f(controlPts[2].x/controlPts[2].z, controlPts[2].y/controlPts[2].z); glVertex2f(controlPts[3].x/controlPts[3].z, controlPts[3].y/controlPts[3].z); glEnd(); } else if (bool multisample = true) { //glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glEnable(GL_STENCIL_TEST); glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); glMatrixMode(GL_MODELVIEW); glTranslatef(offsetX, offsetY, 0); glScalef(zoom, zoom, 1); glPushMatrix(); glTranslatef(-40, -40, 0); glScalef(80, 80, 1); clearStencil(); glPopMatrix(); glPushMatrix(); //glScalef(-1, 1, 1); drawRCubicA2C(rcubic); rasterizeEvenOdd(rtri); glPopMatrix(); glUseProgram(0); glPushMatrix(); glTranslatef(-40, -40, 0); glScalef(80, 80, 1); drawQuad(); glPopMatrix(); glDisable(GL_STENCIL_TEST); glColor3f(1, 0, 0); glBegin(GL_LINE_STRIP); glVertex2f(controlPts[0].x/controlPts[0].z, controlPts[0].y/controlPts[0].z); glVertex2f(controlPts[1].x/controlPts[1].z, controlPts[1].y/controlPts[1].z); glVertex2f(controlPts[2].x/controlPts[2].z, controlPts[2].y/controlPts[2].z); glVertex2f(controlPts[3].x/controlPts[3].z, controlPts[3].y/controlPts[3].z); glEnd(); glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); //glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); //glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); //glBlitFramebuffer( // 0, 0, 800, 600, // 0, 0, 800, 600, // //if enable depth and stencil resolve - label stops to render. // GL_COLOR_BUFFER_BIT, // GL_NEAREST); //glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); } else { glEnable(GL_STENCIL_TEST); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glTranslatef(offsetX, offsetY, 0); glScalef(zoom, zoom, 1); glPushMatrix(); glTranslatef(-40, -40, 0); glScalef(80, 80, 1); clearStencil(); glPopMatrix(); //rasterizeEvenOdd(mRationalCubic); //rasterizeEvenOdd(mRasterCubic); //rasterizeEvenOdd(rcubic); //rasterizeEvenOdd(rtri); glPushMatrix(); //glScalef(-1, 1, 1); //drawRCubicAA(rcubic); drawRCubicDTAA(rcubic); //drawCubicAA(mRasterCubic); glPopMatrix(); //rasterizeEvenOdd(mTri); glUseProgram(0); glPushMatrix(); glTranslatef(-40, -40, 0); glScalef(80, 80, 1); drawQuad(); glPopMatrix(); glDisable(GL_STENCIL_TEST); glColor3f(1, 0, 0); glBegin(GL_LINE_STRIP); glVertex2f(controlPts[0].x/controlPts[0].z, controlPts[0].y/controlPts[0].z); glVertex2f(controlPts[1].x/controlPts[1].z, controlPts[1].y/controlPts[1].z); glVertex2f(controlPts[2].x/controlPts[2].z, controlPts[2].y/controlPts[2].z); glVertex2f(controlPts[3].x/controlPts[3].z, controlPts[3].y/controlPts[3].z); glEnd(); } glPopMatrix(); char zoomStr[256]; _snprintf(zoomStr, 256, "Zoom level %f", zoom); vg::drawString(vg::defaultFont, 300, 10, 0xFFFFFFFF, zoomStr, strlen(zoomStr)); */ }