Example #1
0
/*************************************************************************
	Handler for mouse button down events
*************************************************************************/
void FrameWindow::onMouseButtonDown(MouseEventArgs& e)
{
	// default processing (this is now essential as it controls event firing).
	Window::onMouseButtonDown(e);

	if (e.button == LeftButton)
	{
		if (isSizingEnabled())
		{
			// get position of mouse as co-ordinates local to this window.
			Point localPos(CoordConverter::screenToWindow(*this, e.position));

			// if the mouse is on the sizing border
			if (getSizingBorderAtPoint(localPos) != SizingNone)
			{
				// ensure all inputs come to us for now
				if (captureInput())
				{
					// setup the 'dragging' state variables
					d_beingSized = true;
					d_dragPoint = localPos;
					e.handled = true;
				}

			}

		}

	}

}
Example #2
0
 bool eventFilter(QObject *watched, QEvent *event) {
     if (event->type() == QEvent::MouseButtonDblClick ||
             event->type() == QEvent::MouseButtonPress ||
             event->type() == QEvent::MouseButtonRelease) {
         auto ev = static_cast<QMouseEvent*>(event);
         if (ev->button() == Qt::RightButton) {
             auto buttons = ev->buttons();
             if (buttons & Qt::RightButton) {
                 buttons ^= Qt::RightButton;
                 buttons |= Qt::LeftButton;
             }
             QMouseEvent lev{ev->type(),
                             ev->localPos(),
                             ev->windowPos(),
                             ev->screenPos(),
                             Qt::LeftButton,
                             buttons,
                             ev->modifiers(),
                             ev->source()};
             Q_ASSERT(! (lev.buttons() & Qt::RightButton));
             QCoreApplication::sendEvent(watched, &lev);
             return true;
         }
     }
     return QObject::eventFilter(watched, event);
 }
Example #3
0
// |----------------------------------------------------------------------------|
// |							     Logic()									|
// |----------------------------------------------------------------------------|
bool Player::Logic() {
	DebugLog ("Player: Logic() called.", DB_LOGIC, 10);

	// If crashed, don't process
	if (m_crashed) return true;

    // Get time for this frame
    float time = TimerManager::GetRef()->GetTime() / 1000;

	// TODO: Get player input (Update direction, speed), set camera based on this
	// For now, keep using mouselookcamera and get it from the camera
    Camera* camera = GraphicsManager::GetRef()->GetCamera();
	Coord cameraOrientation = camera->GetOrientation();

	SetOrientation(Coord(
		0.0f+cameraOrientation.y*3.14/180,
		-1*(3.14f/6.0f)+cameraOrientation.x*3.14/180,
		0.0f+cameraOrientation.z*3.14/180));

	// Ship just stays with the camera
	Coord localPos(
		10.0f*sin(3.14/2-cameraOrientation.x*3.14/180-1*(3.14f/16.0f))*sin(cameraOrientation.y*3.14/180),
		-10.0f*cos(3.14/2-cameraOrientation.x*3.14/180-1*(3.14f/16.0f)),
		10.0f*sin(3.14/2-cameraOrientation.x*3.14/180-1*(3.14f/16.0f))*cos(cameraOrientation.y*3.14/180) );
	Coord unbounded = localPos + camera->GetPosition();
	m_linearVelocity = unbounded - m_position;
	SetPosition(unbounded);
	localPos = Coord(
		9.3f*sin(3.14/2-cameraOrientation.x*3.14/180-1.25*(3.14f/16.0f))*sin(cameraOrientation.y*3.14/180-0.6*(3.14f/32.0f)),
		-9.3f*cos(3.14/2-cameraOrientation.x*3.14/180-1.25*(3.14f/16.0f)),
		9.3f*sin(3.14/2-cameraOrientation.x*3.14/180-1.25*(3.14f/16.0f))*cos(cameraOrientation.y*3.14/180-0.6*(3.14f/32.0f)) );
    m_leftThruster->SetPosition(localPos+camera->GetPosition());
	localPos = Coord(
		9.3f*sin(3.14/2-cameraOrientation.x*3.14/180-1.25*(3.14f/16.0f))*sin(cameraOrientation.y*3.14/180+0.6*(3.14f/32.0f)),
		-9.3f*cos(3.14/2-cameraOrientation.x*3.14/180-1.25*(3.14f/16.0f)),
		9.3f*sin(3.14/2-cameraOrientation.x*3.14/180-1.25*(3.14f/16.0f))*cos(cameraOrientation.y*3.14/180+0.6*(3.14f/32.0f)) );
    m_rightThruster->SetPosition(localPos+camera->GetPosition());
	
	// Alternate controlling method:
	//Coord unbounded(camera->GetPosition()+Coord(0.0f,-2.0f,10.0f));
	// If the position gets too far from the camera direction vector, move it to that point.
	// Need bounding points to left, right, up, and down.
	// Need to keep ship a certain distance from camera...

	// TODO: Update velocity of thrusters to shoot backwards
	Coord thrusterVel = Coord(
		sin(3.14/2-camera->GetOrientation().x*3.14/180+1.25*(3.14f/16.0f))*sin(camera->GetOrientation().y*3.14/180),
		-1*cos(3.14/2-camera->GetOrientation().x*3.14/180+1.25*(3.14f/16.0f)),
		sin(3.14/2-camera->GetOrientation().x*3.14/180+1.25*(3.14f/16.0f))*cos(camera->GetOrientation().y*3.14/180) );
	thrusterVel *= -2.0f;
    m_leftThruster->SetParticleVelocity(thrusterVel);
    m_rightThruster->SetParticleVelocity(thrusterVel);

	// Call logic functions for child objects
	m_ship->Logic();
	m_leftThruster->Logic();
	m_rightThruster->Logic();

	return true;
}
unsigned int Forest::onCollideJumper(unsigned int id, Matrix4f* matrix, void* data)
{
    Forest* __this = reinterpret_cast<Forest*>( data );

    // determine obb of instance
    NxBox instanceOBB = calculateOBB( 
        __this->_canopyBatch->getBatchScheme()->lodGeometry[0], 
        *matrix,
        __this->_desc.collScale
    );
    __this->_debugBoxes.push_back( instanceOBB );

    // collide obbs
    if( NxBoxBoxIntersect( instanceOBB, __this->_jumperOBB ) )
    {
        Jumper* jumper = dynamic_cast<Jumper*>( __this->_currentJumper );
        // add impulse to jumper body
        NxVec3 linearVelocity = __this->_currentJumperActor->getLinearVelocity();
        NxVec3 impulse = linearVelocity * getCore()->getRandToolkit()->getUniform( __this->_desc.minImpulseFactor, __this->_desc.maxImpulseFactor ) * -1;
        NxVec3 localPos(
            __this->_jumperOBB.extents.x * getCore()->getRandToolkit()->getUniform( -1, 1 ),
            __this->_jumperOBB.extents.y * getCore()->getRandToolkit()->getUniform( -1, 1 ),
            __this->_jumperOBB.extents.z * getCore()->getRandToolkit()->getUniform( -1, 1 )
        );
        __this->_currentJumperActor->addForceAtLocalPos( impulse, localPos, NX_IMPULSE );
        // damage jumper
        jumper->damage( __this->_desc.damageFactor * impulse.magnitude(), 0.0f, linearVelocity.magnitude() );
        // play rustle sound
        __this->playRustleSound( __this->_currentJumperCollision->getFrame()->getPos() );
    }

    return id;
}
Example #5
0
/*************************************************************************
	Handler for when mouse button is pressed
*************************************************************************/
void Listbox::onMouseButtonDown(MouseEventArgs& e)
{
	// base class processing
	Window::onMouseButtonDown(e);

	if (e.button == LeftButton)
	{
		bool modified = false;

		// clear old selections if no control key is pressed or if multi-select is off
		if (!(e.sysKeys & Control) || !d_multiselect)
		{
			modified = clearAllSelections_impl();
		}

		Point localPos(screenToWindow(e.position));

		if (getMetricsMode() == Relative)
		{
			localPos = relativeToAbsolute(localPos);
		}

		ListboxItem* item = getItemAtPoint(localPos);

		if (item != NULL)
		{
			modified = true;

			// select range or item, depending upon keys and last selected item
			if (((e.sysKeys & Shift) && (d_lastSelected != NULL)) && d_multiselect)
			{
				selectRange(getItemIndex(item), getItemIndex(d_lastSelected));
			}
			else
			{
				item->setSelected(item->isSelected() ^ true);
			}

			// update last selected item
			d_lastSelected = item->isSelected() ? item : NULL;
		}

		// fire event if needed
		if (modified)
		{
			WindowEventArgs args(this);
			onSelectionChanged(args);
		}
		
		e.handled = true;
	}

}
Example #6
0
void NzGeneratePlane(const NzVector2ui& subdivision, const NzVector2f& size, const NzMatrix4f& matrix, const NzRectf& textureCoords, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb, unsigned int indexOffset)
{
	// Pour plus de facilité, on va construire notre plan en considérant que la normale est de 0,1,0
	// Et appliquer ensuite une matrice "finissant le travail"

	// Le nombre de faces appartenant à un axe est équivalent à 2 exposant la subdivision (1,2,4,8,16,32,...)
	unsigned int horizontalFaceCount = (1 << subdivision.x);
	unsigned int verticalFaceCount = (1 << subdivision.y);

	// Et le nombre de sommets est ce nombre ajouté de 1 (2,3,5,9,17,33,...)
	unsigned int horizontalVertexCount = horizontalFaceCount + 1;
	unsigned int verticalVertexCount = verticalFaceCount + 1;

	NzVector3f normal(NzVector3f::UnitY());
	normal = matrix.Transform(normal, 0.f);
	normal.Normalize();

	NzVector3f tangent(1.f, 1.f, 0.f);
	tangent = matrix.Transform(tangent, 0.f);
	tangent.Normalize();

	float halfSizeX = size.x / 2.f;
	float halfSizeY = size.y / 2.f;

	float invHorizontalVertexCount = 1.f/(horizontalVertexCount-1);
	float invVerticalVertexCount = 1.f/(verticalVertexCount-1);
	for (unsigned int x = 0; x < horizontalVertexCount; ++x)
	{
		for (unsigned int y = 0; y < verticalVertexCount; ++y)
		{
			NzVector3f localPos((2.f*x*invHorizontalVertexCount - 1.f) * halfSizeX, 0.f, (2.f*y*invVerticalVertexCount - 1.f) * halfSizeY);
			vertices->position = matrix * localPos;
			vertices->uv.Set(textureCoords.x + x*invHorizontalVertexCount*textureCoords.width, textureCoords.y + y*invVerticalVertexCount*textureCoords.height);
			vertices->normal = normal;
			vertices->tangent = tangent;
			vertices++;

			if (x != horizontalVertexCount-1 && y != verticalVertexCount-1)
			{
				*indices++ = (x+0)*verticalVertexCount + y + 0 + indexOffset;
				*indices++ = (x+0)*verticalVertexCount + y + 1 + indexOffset;
				*indices++ = (x+1)*verticalVertexCount + y + 0 + indexOffset;

				*indices++ = (x+1)*verticalVertexCount + y + 0 + indexOffset;
				*indices++ = (x+0)*verticalVertexCount + y + 1 + indexOffset;
				*indices++ = (x+1)*verticalVertexCount + y + 1 + indexOffset;
			}
		}
	}

	if (aabb)
		aabb->Set(matrix.Transform(NzVector3f(-halfSizeX, 0.f, -halfSizeY), 0.f), matrix.Transform(NzVector3f(halfSizeX, 0.f, halfSizeY), 0.f));
}
/*************************************************************************
	Handler for mouse movement events
*************************************************************************/
void ComboDropList::onMouseMove(MouseEventArgs& e)
{
	Listbox::onMouseMove(e);

	// if mouse is within our area (but not our children)
	if (isHit(e.position))
	{
		if (!getChildAtPosition(e.position))
		{
			// handle auto-arm
			if (d_autoArm)
			{
				d_armed = true;
			}

			if (d_armed)
			{
				//
				// Convert mouse position to absolute window pixels
				//
				Point localPos(CoordConverter::screenToWindow(*this, e.position));

				// check for an item under the mouse
				ListboxItem* selItem = getItemAtPoint(localPos);

				// if an item is under mouse, select it
				if (selItem)
				{
					setItemSelectState(selItem, true);
				}
				else
				{
					clearAllSelections();
				}

			}
		}

		e.handled = true;
	}
	// not within the list area
	else
	{
		// if left mouse button is down, clear any selection
		if (e.sysKeys & LeftMouse)
		{
			clearAllSelections();
		}

	}

}
Example #8
0
void ImageNode::getElementsByPos(const glm::vec2& pos, vector<NodePtr>& pElements)
{
    if (reactsToMouseEvents()) {
        OffscreenCanvasPtr pCanvas = m_pGPUImage->getCanvas();
        if (pCanvas && pCanvas->getHandleEvents()) {
            glm::vec2 nodeSize(getSize());
            glm::vec2 canvasSize(pCanvas->getSize());
            glm::vec2 localPos(pos.x*(canvasSize.x/nodeSize.x), 
                    pos.y*(canvasSize.y/nodeSize.y));
            pCanvas->getRootNode()->getElementsByPos(localPos, pElements);
        }
        RasterNode::getElementsByPos(pos, pElements);
    }
}
Example #9
0
	void SimpleLightSource::valueChanged(Value *value) {
		LightSource::valueChanged(value);
		if(value == 0) {
			return;
		}
		if(value == mCenterBrightness) {
			updateLightCone();
		}
		else if(value == mRadius) {
			CylinderGeom *geom = dynamic_cast<CylinderGeom*>
				(mBodyCollisionObject->getGeometry());
			if(geom != 0) {
				geom->setRadius(mRadius->get());
			}
		}
		else if(value == mHideLightCone) {
			updateLightCone();
		}
		else if(value == mLightColor) {
			updateLightCone();
		}
		else if(mReferenceObject != 0 
			&& (value == mReferenceObject->getPositionValue() 
			|| value == mReferenceObject->getQuaternionOrientationValue()))
		{
			// TODO change this? see Test line 247
			//
			Quaternion localPos(
					0.0,
					mLocalPosition->getX(),
					mLocalPosition->getY(),
					mLocalPosition->getZ()
				);
			Quaternion bodyOrientationInverse =	mReferenceObject->
				getQuaternionOrientationValue()->get().getInverse();

			Quaternion rotatedLocalPosQuat = mReferenceObject->
				getQuaternionOrientationValue()->get() * localPos *
				bodyOrientationInverse;

			Vector3D rotatedLocalPos(
					rotatedLocalPosQuat.getX(),
					rotatedLocalPosQuat.getY(),
					rotatedLocalPosQuat.getZ()
				);
			mPositionValue->set(mReferenceObject->
					getPositionValue()->get() + rotatedLocalPos);
		}
	}
Example #10
0
	bool GUIWidget::inBounds(const Vector2I& position) const
	{
		Viewport* target = getTarget();
		if (target == nullptr)
			return false;

		// Technically GUI widget bounds can be larger than the viewport, so make sure we clip to viewport first
		if(!target->getArea().contains(position))
			return false;

		Vector3 vecPos((float)position.x, (float)position.y, 0.0f);
		vecPos = mTransform.inverse().multiplyAffine(vecPos);

		Vector2I localPos(Math::roundToInt(vecPos.x), Math::roundToInt(vecPos.y));
		return mBounds.contains(localPos);
	}
Example #11
0
bool ApResourceUnit::_AddImagePanelToRightBottom(const MkHashStr& name, const MkPathName& imgPath, const MkHashStr& ssName, float localDepth)
{
	if (m_SceneNode == NULL)
		return true;

	if (!_AddImagePanel(name, imgPath, ssName, localDepth))
		return false;

	MkPanel& panel = *m_SceneNode->GetPanel(name);
	const MkFloat2& indexSize = panel.GetPanelSize();
	MkFloat2 localPos(ApStaticDefinition::Instance().GetResourceTileSize().x - indexSize.x, 0.f); // right bottom
	localPos += MkFloat2(-5.f, 5.f); // offset
	localPos -= ApStaticDefinition::Instance().GetResourceTileSize() * 0.5f; // pivot to center
	panel.SetLocalPosition(localPos);
	return true;
}
Example #12
0
/**
 * Called when a parameter Value changed.
 * @param value the value that changed.
 */
void WavefrontBody::valueChanged(Value *value) {
	SimBody::valueChanged(value);

	if(value == 0) {
		return;
	} 
	else if(mReferenceObject != 0 
		&& (value == mReferenceObject->getPositionValue() 
			|| value == mReferenceObject->getQuaternionOrientationValue()))
	{
		Quaternion localPos(0.0, 
						mLocalPosition->getX(), 
						mLocalPosition->getY(), 
						mLocalPosition->getZ());
		Quaternion bodyOrientationInverse = 
			mReferenceObject->getQuaternionOrientationValue()->get().getInverse();
		Quaternion rotatedLocalPosQuat = mReferenceObject->getQuaternionOrientationValue()->get() 
			* localPos * bodyOrientationInverse;
		Vector3D rotatedLocalPos(rotatedLocalPosQuat.getX(), 
								rotatedLocalPosQuat.getY(), 
								rotatedLocalPosQuat.getZ());
		mPositionValue->set(mReferenceObject->getPositionValue()->get() + rotatedLocalPos);
	}
	else if(mReferenceObject != 0 && value == mReferenceObject->getOrientationValue()) {
		Vector3D orientation = mReferenceObject->getOrientationValue()->get() + mLocalOrientation->get();
		while(orientation.getX() > 180.0) {
			orientation.setX(orientation.getX() - 360.0);
		}
		while(orientation.getX() < -180.0) {
			orientation.setX(orientation.getX() + 360.0);
		}
		while(orientation.getY() > 180.0) {
			orientation.setY(orientation.getY() - 360.0);
		}
		while(orientation.getY() < -180.0) {
			orientation.setY(orientation.getY() + 360.0);
		}
		while(orientation.getZ() > 180.0) {
			orientation.setZ(orientation.getZ() - 360.0);
		}
		while(orientation.getZ() < -180.0) {
			orientation.setZ(orientation.getZ() + 360.0);
		}
		getOrientationValue()->set(orientation);
	}
}
    void btWorldFactory::createRuins(QVariantList &shapesList, double areaX, double areaZ, btVector3 pos, btVector3 boxMin, btVector3 boxMax, int nbBoxes, double density) {

        // Ruin Floor
        for(int i=0;i<nbBoxes;++i){

            btVector3 size(Tools::random((double)boxMin.x(), (double)boxMax.x()),
                           Tools::random((double)boxMin.y(), (double)boxMax.y()),
                           Tools::random((double)boxMin.z(), (double)boxMax.z()));

            btVector3 localPos(Tools::random((double)-areaX/2.0, (double)areaX/2.0),
                           size.y()/2.0,
                           Tools::random(-areaZ/2.0, areaZ/2.0));

            btVector3 euler(Tools::random(-SIMD_PI, SIMD_PI),
                            Tools::random(-SIMD_PI, SIMD_PI),
                            Tools::random(-SIMD_PI, SIMD_PI));

            createBox(shapesList,size,pos + localPos, euler, density);
        }
    }
Example #14
0
//--------------------------------------------------------------------
// setWorldPosition()
//--------------------------------------------------------------------
void LLJoint::setWorldPosition( const LLVector3& pos )
{
	if (mParent == NULL)
	{
		this->setPosition( pos );
		return;
	}

	LLMatrix4a temp_matrix = getWorldMatrix();
	temp_matrix.setTranslate_affine(pos);

	LLMatrix4a invParentWorldMatrix = mParent->getWorldMatrix();
	invParentWorldMatrix.invert();

	invParentWorldMatrix.mul(temp_matrix);

	LLVector3 localPos(	invParentWorldMatrix.getRow<LLMatrix4a::ROW_TRANS>().getF32ptr() );

	setPosition( localPos );
}
/*************************************************************************
	Handler for when mouse buttons are pushed
*************************************************************************/
void ListHeaderSegment::onMouseButtonDown(MouseEventArgs& e)
{
	// base class processing
	Window::onMouseButtonDown(e);

	if (e.button == LeftButton)
	{
		// ensure all inputs come to us for now
		if (captureInput())
		{
			// get position of mouse as co-ordinates local to this window.
			Point localPos(CoordConverter::screenToWindow(*this, e.position));

			// store drag point for possible sizing or moving operation.
			d_dragPoint = localPos;

			// if the mouse is in the sizing area
			if (d_splitterHover)
			{
				if (isSizingEnabled())
				{
					// setup the 'dragging' state variables
					d_dragSizing = true;
				}

			}
			else
			{
				d_segmentPushed = true;
			}

		}

		++e.handled;
	}

}
Example #16
0
Grid* Grid::createGridFromId(int potencialId, const std::list<Piece*> pieces) {
    Grid *grid = new Grid(pieces);
    
    bool fakeResult = false;
    if (!fakeResult) {
        int id = potencialId;
        for (auto piece : pieces) {
            int localId = id % (GRID_X*GRID_Y);
            GridPos localPos(localId / GRID_X, localId%GRID_Y);
            
            if (grid->pieceInPos(localPos) != NULL) {
                Analytics::reportEvent("Invalid id for grid creation");
                delete grid;
                return NULL;
            }
            grid->setPieceToPos(piece, localPos);
            id = id / (GRID_X*GRID_Y);
        }
    }
    else {
        GridPos fixedPositions[6];
        fixedPositions[0].set(4,2);
        fixedPositions[1].set(0,4);
        fixedPositions[2].set(0,3);
        fixedPositions[3].set(0,2);
        fixedPositions[4].set(0,1);
        fixedPositions[5].set(0,0);
        
        int i=0;
        for (auto piece : pieces) {
            grid->setPieceToPos(piece, fixedPositions[i++]);
        }
    }
    
    return grid;
}
Example #17
0
//--------------------------------------------------------------------
// setWorldPosition()
//--------------------------------------------------------------------
void LLJoint::setWorldPosition( const LLVector3& pos )
{
	if (mParent == NULL)
	{
		this->setPosition( pos );
		return;
	}

	LLMatrix4 temp_matrix = getWorldMatrix();
	temp_matrix.mMatrix[VW][VX] = pos.mV[VX];
	temp_matrix.mMatrix[VW][VY] = pos.mV[VY];
	temp_matrix.mMatrix[VW][VZ] = pos.mV[VZ];

	LLMatrix4 parentWorldMatrix = mParent->getWorldMatrix();
	LLMatrix4 invParentWorldMatrix = parentWorldMatrix.invert();

	temp_matrix *= invParentWorldMatrix;

	LLVector3 localPos(	temp_matrix.mMatrix[VW][VX],
						temp_matrix.mMatrix[VW][VY],
						temp_matrix.mMatrix[VW][VZ] );

	setPosition( localPos );
}
Example #18
0
/*************************************************************************
    Handler for when mouse button is pressed
*************************************************************************/
void Tree::onMouseButtonDown(MouseEventArgs& e)
{
    // base class processing
    // populateGeometryBuffer();
    Window::onMouseButtonDown(e);
    
    if (e.button == LeftButton)
    {
        //bool modified = false;
        
        Vector2f localPos(CoordConverter::screenToWindow(*this, e.position));
        //      Point localPos(screenToWindow(e.position));
        
        TreeItem* item = getItemAtPoint(localPos);
        
        if (item != 0)
        {
            //modified = true;
            TreeEventArgs args(this);
            args.treeItem = item;
            populateGeometryBuffer();
            Rectf buttonLocation = item->getButtonLocation();
            if ((localPos.d_x >= buttonLocation.left()) && (localPos.d_x <= buttonLocation.right()) &&
                (localPos.d_y >= buttonLocation.top()) && (localPos.d_y <= buttonLocation.bottom()))
            {
                item->toggleIsOpen();
                if (item->getIsOpen())
                {
                    TreeItem *lastItemInList = item->getTreeItemFromIndex(item->getItemCount() - 1);
                    ensureItemIsVisible(lastItemInList);
                    ensureItemIsVisible(item);
                    onBranchOpened(args);
                }
                else
                {
                    onBranchClosed(args);
                }
                
                // Update the item screen locations, needed to update the scrollbars.
                //	populateGeometryBuffer();
                
                // Opened or closed a tree branch, so must update scrollbars.
                configureScrollbars();
            }
            else
            {
                // clear old selections if no control key is pressed or if multi-select is off
                if (!(e.sysKeys & Control) || !d_multiselect)
                    clearAllSelections_impl();
                
                // select range or item, depending upon keys and last selected item
#if 0 // TODO: fix this
                if (((e.sysKeys & Shift) && (d_lastSelected != 0)) && d_multiselect)
                    selectRange(getItemIndex(item), getItemIndex(d_lastSelected));
                else
#endif
                    item->setSelected(item->isSelected() ^ true);
                
                // update last selected item
                d_lastSelected = item->isSelected() ? item : 0;
                onSelectionChanged(args);
            }
        }
        else
        {
            // clear old selections if no control key is pressed or if multi-select is off
            if (!(e.sysKeys & Control) || !d_multiselect)
            {
                if (clearAllSelections_impl())
                {
                    // Changes to the selections were actually made
                    TreeEventArgs args(this);
                    args.treeItem = item;
                    onSelectionChanged(args);
                }
            }
        }
        
        
        ++e.handled;
    }
}
Example #19
0
void AccelSensor::updateSensorValues() {

	if(mHostBody == 0) {
		return;
	}
	if(mTimeStepSize->get() == 0.0) {
		Core::log("AccelSensor warning: Time step size was 0.0, prevented division by zero.");
		return;
	}
	Quaternion localPos(0.0, 
						mLocalPosition->getX(), 
						mLocalPosition->getY(), 
						mLocalPosition->getZ());
	Quaternion bodyOrientationInverse = 
		mHostBody->getQuaternionOrientationValue()->get().getInverse();
	Quaternion rotatedLocalPosQuat = mHostBody->getQuaternionOrientationValue()->get() 
		* localPos * bodyOrientationInverse;
	Vector3D rotatedLocalPos(rotatedLocalPosQuat.getX(), 
							 rotatedLocalPosQuat.getY(), 
							 rotatedLocalPosQuat.getZ());
	mPosition = mHostBody->getPositionValue()->get() + rotatedLocalPos;

	mVelocity = (mPosition - mLastPosition) * (1.0 / mTimeStepSize->get());
	mAcceleration = (mVelocity - mLastVelocity) * (1.0 / mTimeStepSize->get());

	mAcceleration.setY(mAcceleration.getY() + mGravitation);

	Quaternion bodyRotation = mHostBody->getQuaternionOrientationValue()->get();
	bodyRotation.normalize();
	Quaternion bodyRotationInverse = bodyRotation.getInverse();
	bodyRotationInverse.normalize();

	//Axis 1
	Quaternion xAxisQuat(0.0, 
						mSensorAxisOne.getX(), 
						mSensorAxisOne.getY(), 
						mSensorAxisOne.getZ());
	Quaternion xAxisRotatedQuat = bodyRotation * xAxisQuat * bodyRotationInverse;

	mRotatedSensorAxisOne.set(xAxisRotatedQuat.getX(), 
							  xAxisRotatedQuat.getY(),
							  xAxisRotatedQuat.getZ());

	//Axis 2
	Quaternion yAxisQuat(0.0, 
						mSensorAxisTwo.getX(), 
						mSensorAxisTwo.getY(),
					 	mSensorAxisTwo.getZ());
	Quaternion yAxisRotatedQuat = bodyRotation * yAxisQuat * bodyRotationInverse;

	mRotatedSensorAxisTwo.set(yAxisRotatedQuat.getX(), 
							  yAxisRotatedQuat.getY(),
							  yAxisRotatedQuat.getZ());

	//Axis 3
	Quaternion zAxisQuat(0.0, 
						mSensorAxisThree.getX(), 
						mSensorAxisThree.getY(),
					 	mSensorAxisThree.getZ());
	Quaternion zAxisRotatedQuat = bodyRotation * zAxisQuat * bodyRotationInverse;

	mRotatedSensorAxisThree.set(zAxisRotatedQuat.getX(), 
							  zAxisRotatedQuat.getY(),
							  zAxisRotatedQuat.getZ());



	double sensorValue1 = mAcceleration.getX() * xAxisRotatedQuat.getX() 
		+ mAcceleration.getY() * xAxisRotatedQuat.getY() 
		+ mAcceleration.getZ() * xAxisRotatedQuat.getZ();
	sensorValue1 = -1 * sensorValue1;

	double sensorValue2 = mAcceleration.getX() * yAxisRotatedQuat.getX() 
		+ mAcceleration.getY() * yAxisRotatedQuat.getY() 
		+ mAcceleration.getZ() * yAxisRotatedQuat.getZ();
	sensorValue2 = -1 * sensorValue2;

	double sensorValue3 = mAcceleration.getX() * zAxisRotatedQuat.getX() 
		+ mAcceleration.getY() * zAxisRotatedQuat.getY() 
		+ mAcceleration.getZ() * zAxisRotatedQuat.getZ();
	sensorValue3 = -1 * sensorValue3;



	// freeze all sensorValues if one of them exceeds the maximum value.
	if(fabs(sensorValue1) > mMaxSensorValue 
		|| (fabs(sensorValue2) > mMaxSensorValue && mNumberOfAxes > 1)
		|| (fabs(sensorValue3) > mMaxSensorValue && mNumberOfAxes > 2)) 
	{
		sensorValue1 = mLastAxisOneMeasurement;
		sensorValue2 = mLastAxisTwoMeasurement;
		sensorValue3 = mLastAxisThreeMeasurement;
	} 
	else {
		mLastAxisOneMeasurement = sensorValue1;
		mLastAxisTwoMeasurement = sensorValue2;
		mLastAxisThreeMeasurement = sensorValue3;
	}

	if(mValueOneHistory.size() >= mLowPassFilterDelay) {
		mValueOneHistory.pop_front();
		mValueTwoHistory.pop_front();
		mValueThreeHistory.pop_front();
	}
	mValueOneHistory.push_back(sensorValue1);
	mValueTwoHistory.push_back(sensorValue2);
	mValueThreeHistory.push_back(sensorValue3);

	// perform low pass filtering
	QList<double> result = calculateFilteredSensorValues(sensorValue1, sensorValue2, sensorValue3);

	sensorValue1 = result.at(0);
	sensorValue2 = result.at(1);
	sensorValue3 = result.at(2);

	// add noise
	sensorValue1 = Math::calculateGaussian(sensorValue1, mGlobalNoiseDeviation);
	sensorValue2 = Math::calculateGaussian(sensorValue2, mGlobalNoiseDeviation);
	sensorValue3 = Math::calculateGaussian(sensorValue3, mGlobalNoiseDeviation);

	mFirstSensorValue->set(sensorValue1);
	mSecondSensorValue->set(sensorValue2);
	mThirdSensorValue->set(sensorValue3);

	mLastVelocity = mVelocity;
	mLastPosition = mPosition;

}
Example #20
0
void AccelSensor::setup() {
	SimObject::setup();

	if(mInitialized == false) {
		mHostBody = Physics::getPhysicsManager()->getSimBody(mReferenceBodyName->get());
		if(mHostBody == 0) {
			Core::log("AccelSensor: Sensor has no valid reference body. Name was ["
					+ mReferenceBodyName->get() + "]! Ignoring", true);
			return;
		}
		createSensor();	
		mFirstSensorValue->set(0.0);
		mSecondSensorValue->set(0.0);
		mThirdSensorValue->set(0.0);

		mTimeStepSize = dynamic_cast<DoubleValue*>(Core::getInstance()->
			getValueManager()->getValue(SimulationConstants::VALUE_TIME_STEP_SIZE));
		DoubleValue *mGravitationValue = dynamic_cast<DoubleValue*>(Core::getInstance()->
			getValueManager()->getValue("/Simulation/Gravitation"));
		if(mTimeStepSize == 0 || mGravitationValue == 0) {
			Core::log("AccelSensor: Required Event or Value could not be found.");
			return;
		}
		mGravitation = mGravitationValue->get();
		mLastAxisOneMeasurement = 0.0;
		mLastAxisTwoMeasurement = 0.0;
		mLastAxisThreeMeasurement = 0.0;
		mInitialized = true;
	}
// 	rotate chosen axis about the localRotation of this sensor
	Quaternion localOrientation = mLocalOrientation->get();
	localOrientation.normalize();
	mLocalOrientation->set(localOrientation);
	Quaternion localOrientationInverse = localOrientation.getInverse();
	localOrientationInverse.normalize();

	Quaternion xAxis(0.0, 
					mSensorAxisOneValue->getX(), 
					mSensorAxisOneValue->getY(), 
					mSensorAxisOneValue->getZ());
	Quaternion xAxisRotated = localOrientation * xAxis * localOrientationInverse;
	mSensorAxisOne.set(xAxisRotated.getX(), xAxisRotated.getY(), xAxisRotated.getZ());
	mRotatedSensorAxisOne.set(xAxisRotated.getX(), 
							  xAxisRotated.getY(), 
							  xAxisRotated.getZ());

	Quaternion yAxis(0.0, 
					mSensorAxisTwoValue->getX(), 
					mSensorAxisTwoValue->getY(), 
					mSensorAxisTwoValue->getZ());
	Quaternion yAxisRotated = localOrientation * yAxis * localOrientationInverse;
	mSensorAxisTwo.set(yAxisRotated.getX(), yAxisRotated.getY(), yAxisRotated.getZ());
	mRotatedSensorAxisTwo.set(yAxisRotated.getX(), 
							  yAxisRotated.getY(), 
							  yAxisRotated.getZ());

	Quaternion zAxis(0.0, 
					mSensorAxisThreeValue->getX(), 
					mSensorAxisThreeValue->getY(), 
					mSensorAxisThreeValue->getZ());
	Quaternion zAxisRotated = localOrientation * zAxis * localOrientationInverse;
	mSensorAxisThree.set(zAxisRotated.getX(), zAxisRotated.getY(), zAxisRotated.getZ());
	mRotatedSensorAxisThree.set(zAxisRotated.getX(), 
							  zAxisRotated.getY(), 
							  zAxisRotated.getZ());

	if(mSensorBody == 0 || mHostBody == 0) {
		Core::log("AccelSensor: The sensor has no valid host or sensor-body.");
		return;
	}	

	mSensorBody->setTextureType("None");
	mSensorBody->setFaceTexture(5, "AccelBoard");
	mSensorGeometry->setLocalOrientation(mLocalOrientation->get());
	mSensorBody->getGeometry()->setLocalPosition(mLocalPosition->get());
	Quaternion localPos(0, 
						mLocalPosition->getX(), 
						mLocalPosition->getY(), 
						mLocalPosition->getZ());
	Quaternion bodyOrientationInverse = mHostBody->getQuaternionOrientationValue()->get().getInverse();
	Quaternion rotatedLocalPosQuat = mHostBody->getQuaternionOrientationValue()->get() 
		* localPos * bodyOrientationInverse;
	Vector3D rotatedLocalPos(rotatedLocalPosQuat.getX(), 
							 rotatedLocalPosQuat.getY(), 
							 rotatedLocalPosQuat.getZ());
	mLastPosition = mHostBody->getPositionValue()->get() + rotatedLocalPos;

	if(mLowPassFilterDelayValue != 0) {
		mLowPassFilterDelay = mLowPassFilterDelayValue->get();
	}
	mValueOneHistory.clear();
	mValueTwoHistory.clear();
	mValueThreeHistory.clear();

	mGlobalNoiseDeviation = mGlobalNoiseDeviationValue->get();

}
void LayoutBox::layout() {
    Layout::layout();
    if (m_eDirection == CCLayoutBoxDirectionHorizontal)
    {
        // Get the maximum height
        float maxHeight = 0;

        for(auto it = _children.cbegin(); it != _children.cend(); ++it) {
            float height = (*it)->getContentSize().height;
            if (height > maxHeight) maxHeight = height;
        }
        
        // Position the nodes
        float width = 0;
        for(auto it = _children.cbegin(); it != _children.cend(); ++it) {
            
            Size childSize = (*it)->getContentSize();
            
            Point offset = (*it)->getAnchorPointInPoints();
            Point localPos(roundf(width), roundf((maxHeight-childSize.height)/2.0f));
            Point position = localPos + offset;
            
            (*it)->setPosition(position);
//            (*it)->setPositionType(CCPositionTypePoints);
            
            width += childSize.width;
            width += m_nSpacing;
        }
        
        // Account for last added increment
        width -= m_nSpacing;
        if (width < 0) width = 0;
        
        this->setContentSize(Size(roundUpToEven(width), roundUpToEven(maxHeight)));
    }
    else
    {
        // Get the maximum height
        float maxWidth = 0;
        
        for(auto it = _children.cbegin(); it != _children.cend(); ++it) {
            float width = (*it)->getContentSize().width;
            if (width > maxWidth) maxWidth = width;
        }
        
        // Position the nodes
        float height = 0;
        for(auto it = _children.cbegin(); it != _children.cend(); ++it) {
            
            Size childSize = (*it)->getContentSize();
            
            Point offset = (*it)->getAnchorPointInPoints();
            Point localPos(roundf((maxWidth-childSize.width)/2.0f), roundf(height));
            Point position = localPos + offset;
            
            (*it)->setPosition(position);
            //            (*it)->setPositionType(CCPositionTypePoints);
            
            height += childSize.height;
            height += m_nSpacing;
        }
        
        // Account for last added increment
        height -= m_nSpacing;
        if (height < 0) height = 0;
        
        
        this->setContentSize(Size(roundUpToEven(maxWidth), roundUpToEven(height)));
    }
}