void Constraint::ApplyFrames() { if (!constraint_) return; if (node_) cachedWorldScale_ = node_->GetWorldScale(); Vector3 ownBodyScaledPosition = position_ * cachedWorldScale_; Vector3 otherBodyScaledPosition = otherBody_ ? otherPosition_ * otherBody_->GetNode()->GetWorldScale() : otherPosition_; switch (constraint_->getConstraintType()) { case POINT2POINT_CONSTRAINT_TYPE: { btPoint2PointConstraint* pointConstraint = static_cast<btPoint2PointConstraint*>(constraint_); pointConstraint->setPivotA(ToBtVector3(ownBodyScaledPosition)); pointConstraint->setPivotB(ToBtVector3(otherBodyScaledPosition)); } break; case HINGE_CONSTRAINT_TYPE: { btHingeConstraint* hingeConstraint = static_cast<btHingeConstraint*>(constraint_); btTransform ownFrame(ToBtQuaternion(rotation_), ToBtVector3(ownBodyScaledPosition)); btTransform otherFrame(ToBtQuaternion(otherRotation_), ToBtVector3(otherBodyScaledPosition)); hingeConstraint->setFrames(ownFrame, otherFrame); } break; case SLIDER_CONSTRAINT_TYPE: { btSliderConstraint* sliderConstraint = static_cast<btSliderConstraint*>(constraint_); btTransform ownFrame(ToBtQuaternion(rotation_), ToBtVector3(ownBodyScaledPosition)); btTransform otherFrame(ToBtQuaternion(otherRotation_), ToBtVector3(otherBodyScaledPosition)); sliderConstraint->setFrames(ownFrame, otherFrame); } break; case CONETWIST_CONSTRAINT_TYPE: { btConeTwistConstraint* coneTwistConstraint = static_cast<btConeTwistConstraint*>(constraint_); btTransform ownFrame(ToBtQuaternion(rotation_), ToBtVector3(ownBodyScaledPosition)); btTransform otherFrame(ToBtQuaternion(otherRotation_), ToBtVector3(otherBodyScaledPosition)); coneTwistConstraint->setFrames(ownFrame, otherFrame); } break; default: break; } }
void Constraint::CreateConstraint() { PROFILE(CreateConstraint); cachedWorldScale_ = node_->GetWorldScale(); ReleaseConstraint(); ownBody_ = GetComponent<RigidBody>(); btRigidBody* ownBody = ownBody_ ? ownBody_->GetBody() : 0; btRigidBody* otherBody = otherBody_ ? otherBody_->GetBody() : 0; // If no physics world available now mark for retry later if (!physicsWorld_ || !ownBody) { retryCreation_ = true; return; } if (!otherBody) otherBody = &btTypedConstraint::getFixedBody(); Vector3 ownBodyScaledPosition = position_ * cachedWorldScale_ - ownBody_->GetCenterOfMass(); Vector3 otherBodyScaledPosition = otherBody_ ? otherPosition_ * otherBody_->GetNode()->GetWorldScale() - otherBody_->GetCenterOfMass() : otherPosition_; switch (constraintType_) { case CONSTRAINT_POINT: { constraint_ = new btPoint2PointConstraint(*ownBody, *otherBody, ToBtVector3(ownBodyScaledPosition), ToBtVector3(otherBodyScaledPosition)); } break; case CONSTRAINT_HINGE: { btTransform ownFrame(ToBtQuaternion(rotation_), ToBtVector3(ownBodyScaledPosition)); btTransform otherFrame(ToBtQuaternion(otherRotation_), ToBtVector3(otherBodyScaledPosition)); constraint_ = new btHingeConstraint(*ownBody, *otherBody, ownFrame, otherFrame); } break; case CONSTRAINT_SLIDER: { btTransform ownFrame(ToBtQuaternion(rotation_), ToBtVector3(ownBodyScaledPosition)); btTransform otherFrame(ToBtQuaternion(otherRotation_), ToBtVector3(otherBodyScaledPosition)); constraint_ = new btSliderConstraint(*ownBody, *otherBody, ownFrame, otherFrame, false); } break; case CONSTRAINT_CONETWIST: { btTransform ownFrame(ToBtQuaternion(rotation_), ToBtVector3(ownBodyScaledPosition)); btTransform otherFrame(ToBtQuaternion(otherRotation_), ToBtVector3(otherBodyScaledPosition)); constraint_ = new btConeTwistConstraint(*ownBody, *otherBody, ownFrame, otherFrame); } break; default: break; } if (constraint_) { constraint_->setUserConstraintPtr(this); constraint_->setEnabled(IsEnabledEffective()); ownBody_->AddConstraint(this); if (otherBody_) otherBody_->AddConstraint(this); ApplyLimits(); physicsWorld_->GetWorld()->addConstraint(constraint_, disableCollision_); } recreateConstraint_ = false; framesDirty_ = false; retryCreation_ = false; }
void tst_QVideoFrame::assign() { QFETCH(QAbstractVideoBuffer::HandleType, handleType); QFETCH(QSize, size); QFETCH(QVideoFrame::PixelFormat, pixelFormat); QFETCH(QVideoFrame::FieldType, fieldType); QFETCH(qint64, startTime); QFETCH(qint64, endTime); QPointer<QtTestVideoBuffer> buffer = new QtTestVideoBuffer(handleType); QVideoFrame frame; { QVideoFrame otherFrame(buffer, size, pixelFormat); otherFrame.setFieldType(fieldType); otherFrame.setStartTime(startTime); otherFrame.setEndTime(endTime); frame = otherFrame; QVERIFY(!buffer.isNull()); QVERIFY(otherFrame.isValid()); QCOMPARE(otherFrame.handleType(), handleType); QCOMPARE(otherFrame.pixelFormat(), pixelFormat); QCOMPARE(otherFrame.size(), size); QCOMPARE(otherFrame.width(), size.width()); QCOMPARE(otherFrame.height(), size.height()); QCOMPARE(otherFrame.fieldType(), fieldType); QCOMPARE(otherFrame.startTime(), startTime); QCOMPARE(otherFrame.endTime(), endTime); otherFrame.setStartTime(-1); QVERIFY(!buffer.isNull()); QVERIFY(otherFrame.isValid()); QCOMPARE(otherFrame.handleType(), handleType); QCOMPARE(otherFrame.pixelFormat(), pixelFormat); QCOMPARE(otherFrame.size(), size); QCOMPARE(otherFrame.width(), size.width()); QCOMPARE(otherFrame.height(), size.height()); QCOMPARE(otherFrame.fieldType(), fieldType); QCOMPARE(otherFrame.startTime(), qint64(-1)); QCOMPARE(otherFrame.endTime(), endTime); } QVERIFY(!buffer.isNull()); QVERIFY(frame.isValid()); QCOMPARE(frame.handleType(), handleType); QCOMPARE(frame.pixelFormat(), pixelFormat); QCOMPARE(frame.size(), size); QCOMPARE(frame.width(), size.width()); QCOMPARE(frame.height(), size.height()); QCOMPARE(frame.fieldType(), fieldType); QCOMPARE(frame.startTime(), qint64(-1)); QCOMPARE(frame.endTime(), endTime); frame = QVideoFrame(); QVERIFY(buffer.isNull()); QVERIFY(!frame.isValid()); QCOMPARE(frame.handleType(), QAbstractVideoBuffer::NoHandle); QCOMPARE(frame.pixelFormat(), QVideoFrame::Format_Invalid); QCOMPARE(frame.size(), QSize()); QCOMPARE(frame.width(), -1); QCOMPARE(frame.height(), -1); QCOMPARE(frame.fieldType(), QVideoFrame::ProgressiveFrame); QCOMPARE(frame.startTime(), qint64(-1)); QCOMPARE(frame.endTime(), qint64(-1)); }
void tst_QVideoFrame::copy() { QFETCH(QAbstractVideoBuffer::HandleType, handleType); QFETCH(QSize, size); QFETCH(QVideoFrame::PixelFormat, pixelFormat); QFETCH(QVideoFrame::FieldType, fieldType); QFETCH(qint64, startTime); QFETCH(qint64, endTime); QPointer<QtTestVideoBuffer> buffer = new QtTestVideoBuffer(handleType); { QVideoFrame frame(buffer, size, pixelFormat); frame.setFieldType(QVideoFrame::FieldType(fieldType)); frame.setStartTime(startTime); frame.setEndTime(endTime); QVERIFY(frame.isValid()); QCOMPARE(frame.handleType(), handleType); QCOMPARE(frame.pixelFormat(), pixelFormat); QCOMPARE(frame.size(), size); QCOMPARE(frame.width(), size.width()); QCOMPARE(frame.height(), size.height()); QCOMPARE(frame.fieldType(), fieldType); QCOMPARE(frame.startTime(), startTime); QCOMPARE(frame.endTime(), endTime); { QVideoFrame otherFrame(frame); QVERIFY(!buffer.isNull()); QVERIFY(otherFrame.isValid()); QCOMPARE(otherFrame.handleType(), handleType); QCOMPARE(otherFrame.pixelFormat(), pixelFormat); QCOMPARE(otherFrame.size(), size); QCOMPARE(otherFrame.width(), size.width()); QCOMPARE(otherFrame.height(), size.height()); QCOMPARE(otherFrame.fieldType(), fieldType); QCOMPARE(otherFrame.startTime(), startTime); QCOMPARE(otherFrame.endTime(), endTime); otherFrame.setEndTime(-1); QVERIFY(!buffer.isNull()); QVERIFY(otherFrame.isValid()); QCOMPARE(otherFrame.handleType(), handleType); QCOMPARE(otherFrame.pixelFormat(), pixelFormat); QCOMPARE(otherFrame.size(), size); QCOMPARE(otherFrame.width(), size.width()); QCOMPARE(otherFrame.height(), size.height()); QCOMPARE(otherFrame.fieldType(), fieldType); QCOMPARE(otherFrame.startTime(), startTime); QCOMPARE(otherFrame.endTime(), qint64(-1)); } QVERIFY(!buffer.isNull()); QVERIFY(frame.isValid()); QCOMPARE(frame.handleType(), handleType); QCOMPARE(frame.pixelFormat(), pixelFormat); QCOMPARE(frame.size(), size); QCOMPARE(frame.width(), size.width()); QCOMPARE(frame.height(), size.height()); QCOMPARE(frame.fieldType(), fieldType); QCOMPARE(frame.startTime(), startTime); QCOMPARE(frame.endTime(), qint64(-1)); // Explicitly shared. } QVERIFY(buffer.isNull()); }