void FirstPersonCamera::use() { // Obtain the reference point determined by the angles float eyeX, eyeY, eyeZ; getEyePosition(eyeX, eyeY, eyeZ); float centerX = eyeX + cos(degreesToRadians(xzAngle))*cos(degreesToRadians(yAngle)); float centerY = eyeY + sin(degreesToRadians(yAngle)); float centerZ = eyeZ + sin(degreesToRadians(xzAngle))*cos(degreesToRadians(yAngle)); setReferencePoint(centerX, centerY, centerZ); // Use the camera Camera::use(); }
/* Rotating */ void FreeCamera::rotate(float angle) { float eyeX, eyeY, eyeZ; float centerX, centerY, centerZ; getEyePosition(eyeX, eyeY, eyeZ); getReferencePoint(centerX, centerY, centerZ); float distance = distance2D(eyeX, eyeZ, centerX, centerZ); centerX += distance*(cos(degreesToRadians(xzAngle + angle)) - cos(degreesToRadians(xzAngle))); centerZ += distance*(sin(degreesToRadians(xzAngle + angle)) - sin(degreesToRadians(xzAngle))); xzAngle += angle; setReferencePoint(centerX, centerY, centerZ); }
void KDoubleNumInput::setRange(double lower, double upper, double step, bool slider) { if( m_slider ) { // don't update the slider to avoid an endless recursion QSpinBox * spin = d->spin; disconnect(spin, SIGNAL(valueChanged(int)), m_slider, SLOT(setValue(int)) ); } d->spin->setRange( lower, upper, step, d->spin->precision() ); if(slider) { // upcast to base type to get the min/maxValue in int form: QSpinBox * spin = d->spin; int slmax = spin->maxValue(); int slmin = spin->minValue(); int slvalue = spin->value(); int slstep = spin->lineStep(); if (m_slider) { m_slider->setRange(slmin, slmax); m_slider->setLineStep(slstep); m_slider->setValue(slvalue); } else { m_slider = new QSlider(slmin, slmax, slstep, slvalue, QSlider::Horizontal, this); m_slider->setTickmarks(QSlider::Below); // feedback line: when one moves, the other moves, too: connect(m_slider, SIGNAL(valueChanged(int)), SLOT(sliderMoved(int)) ); } connect(spin, SIGNAL(valueChanged(int)), m_slider, SLOT(setValue(int)) ); // calculate ( slmax - slmin ) / 10 without overflowing ints: int major = calcDiffByTen( slmax, slmin ); if ( !major ) major = slstep; // ### needed? m_slider->setTickInterval(major); } else { delete m_slider; m_slider = 0; } setReferencePoint( referencePoint() ); layout(true); updateLegacyMembers(); }
/* Panning */ void FreeCamera::pan(float panX, float panZ) { float eyeX, eyeY, eyeZ; float centerX, centerY, centerZ; getEyePosition(eyeX, eyeY, eyeZ); getReferencePoint(centerX, centerY, centerZ); float deltaX = panX*cos(degreesToRadians(xzAngle)) + panZ*cos(degreesToRadians(xzAngle + 90.0f)); float deltaZ = panX*sin(degreesToRadians(xzAngle)) + panZ*sin(degreesToRadians(xzAngle + 90.0f)); eyeX += deltaX; centerX += deltaX; eyeZ += deltaZ; centerZ += deltaZ; setEyePosition(eyeX, eyeY, eyeZ); setReferencePoint(centerX, centerY, centerZ); }
void KIntNumInput::setRange(int lower, int upper, int step, bool slider) { upper = kMax(upper, lower); lower = kMin(upper, lower); m_spin->setMinValue(lower); m_spin->setMaxValue(upper); m_spin->setLineStep(step); step = m_spin->lineStep(); // maybe QRangeControl didn't like out lineStep? if(slider) { if (m_slider) m_slider->setRange(lower, upper); else { m_slider = new QSlider(lower, upper, step, m_spin->value(), QSlider::Horizontal, this); m_slider->setTickmarks(QSlider::Below); connect(m_slider, SIGNAL(valueChanged(int)), m_spin, SLOT(setValue(int))); } // calculate (upper-lower)/10 without overflowing int's: int major = calcDiffByTen( upper, lower ); if ( major==0 ) major = step; // #### workaround Qt bug in 2.1-beta4 m_slider->setSteps(step, major); m_slider->setTickInterval(major); } else { delete m_slider; m_slider = 0; } // check that reference point is still inside valid range: setReferencePoint( referencePoint() ); layout(true); }