Example #1
0
void Window::saveWindowState()
{
    // Saving X, Y and Width and Height for resizables in the config
    if (!mWindowName.empty() && mWindowName != "window")
    {
        config.setValue(mWindowName + "WinX", getX());
        config.setValue(mWindowName + "WinY", getY());

        if (mSaveVisible)
            config.setValue(mWindowName + "Visible", isVisible());

        if (mStickyButton)
            config.setValue(mWindowName + "Sticky", isSticky());

        if (mGrip)
        {
            if (getMinWidth() > getWidth())
                setWidth(getMinWidth());
            else if (getMaxWidth() < getWidth())
                setWidth(getMaxWidth());
            if (getMinHeight() > getHeight())
                setHeight(getMinHeight());
            else if (getMaxHeight() < getHeight())
                setHeight(getMaxHeight());

            config.setValue(mWindowName + "WinWidth", getWidth());
            config.setValue(mWindowName + "WinHeight", getHeight());
        }
    }
}
Example #2
0
	void iWidget::updateAlignment(int32 clientWidth, int32 clientHeight)
	{
        int32 width = getMinWidth();
        int32 height = getMinHeight();

		switch (iWidget::getHorizontalAlignment())
		{
		case iHorizontalAlignment::Left:
			_relativeX = 0;
			break;

		case iHorizontalAlignment::Strech:
			_relativeX = 0;
            width = clientWidth;
			break;

		case iHorizontalAlignment::Center:
			_relativeX = (clientWidth - width) / 2;
			break;

		case iHorizontalAlignment::Right:
			_relativeX = clientWidth - width;
			break;

		case iHorizontalAlignment::Absolut:
			con_err("absolut positioning only supported for dialogs");
			break;

		default:;
		};

		switch (iWidget::getVerticalAlignment())
		{
		case iVerticalAlignment::Top:
			_relativeY = 0;
			break;

		case iVerticalAlignment::Strech:
			_relativeY = 0;
            height = clientHeight;
			break;

		case iVerticalAlignment::Center:
			_relativeY = (clientHeight - height) / 2;
			break;

		case iVerticalAlignment::Bottom:
			_relativeY = clientHeight - height;
			break;

		case iVerticalAlignment::Absolut:
			con_err("absolut positioning only supported for dialogs");
			break;

		default:;
		}

        _actualWidth = width;
        _actualHeight = height;
	}
Example #3
0
void Window::setContentSize(int width, int height)
{
    width = width + 2 * getPadding();
    height = height + getPadding() + getTitleBarHeight();

    if (getMinWidth() > width)
        width = getMinWidth();
    else if (getMaxWidth() < width)
        width = getMaxWidth();
    if (getMinHeight() > height)
        height = getMinHeight();
    else if (getMaxHeight() < height)
        height = getMaxHeight();

    setSize(width, height);
}
Example #4
0
void Window::setDefaultSize(int defaultX, int defaultY,
                            int defaultWidth, int defaultHeight)
{
    if (getMinWidth() > defaultWidth)
        defaultWidth = getMinWidth();
    else if (getMaxWidth() < defaultWidth)
        defaultWidth = getMaxWidth();
    if (getMinHeight() > defaultHeight)
        defaultHeight = getMinHeight();
    else if (getMaxHeight() < defaultHeight)
        defaultHeight = getMaxHeight();

    mDefaultX = defaultX;
    mDefaultY = defaultY;
    mDefaultWidth = defaultWidth;
    mDefaultHeight = defaultHeight;
}
Example #5
0
void Popup::setContentSize(int width, int height)
{
    width += 2 * getPadding();
    height += 2 * getPadding();

    if (getMinWidth() > width)
        width = getMinWidth();
    else if (getMaxWidth() < width)
        width = getMaxWidth();
    if (getMinHeight() > height)
        height = getMinHeight();
    else if (getMaxHeight() < height)
        height = getMaxHeight();

    setSize(width, height);
    mRedraw = true;
}
Example #6
0
Box* Tile::getTileBoundingVolume(const G3MRenderContext *rc) {
  if (_tileBoundingVolume == NULL) {
    const Planet* planet = rc->getPlanet();

    const double minHeight = getMinHeight() * _verticalExaggeration;
    const double maxHeight = getMaxHeight() * _verticalExaggeration;

    const Vector3D v0 = planet->toCartesian( _sector._center, maxHeight );
    const Vector3D v1 = planet->toCartesian( _sector.getNE(),     minHeight );
    const Vector3D v2 = planet->toCartesian( _sector.getNW(),     minHeight );
    const Vector3D v3 = planet->toCartesian( _sector.getSE(),     minHeight );
    const Vector3D v4 = planet->toCartesian( _sector.getSW(),     minHeight );

    double lowerX = v0._x;
    if (v1._x < lowerX) { lowerX = v1._x; }
    if (v2._x < lowerX) { lowerX = v2._x; }
    if (v3._x < lowerX) { lowerX = v3._x; }
    if (v4._x < lowerX) { lowerX = v4._x; }

    double upperX = v0._x;
    if (v1._x > upperX) { upperX = v1._x; }
    if (v2._x > upperX) { upperX = v2._x; }
    if (v3._x > upperX) { upperX = v3._x; }
    if (v4._x > upperX) { upperX = v4._x; }


    double lowerY = v0._y;
    if (v1._y < lowerY) { lowerY = v1._y; }
    if (v2._y < lowerY) { lowerY = v2._y; }
    if (v3._y < lowerY) { lowerY = v3._y; }
    if (v4._y < lowerY) { lowerY = v4._y; }

    double upperY = v0._y;
    if (v1._y > upperY) { upperY = v1._y; }
    if (v2._y > upperY) { upperY = v2._y; }
    if (v3._y > upperY) { upperY = v3._y; }
    if (v4._y > upperY) { upperY = v4._y; }


    double lowerZ = v0._z;
    if (v1._z < lowerZ) { lowerZ = v1._z; }
    if (v2._z < lowerZ) { lowerZ = v2._z; }
    if (v3._z < lowerZ) { lowerZ = v3._z; }
    if (v4._z < lowerZ) { lowerZ = v4._z; }

    double upperZ = v0._z;
    if (v1._z > upperZ) { upperZ = v1._z; }
    if (v2._z > upperZ) { upperZ = v2._z; }
    if (v3._z > upperZ) { upperZ = v3._z; }
    if (v4._z > upperZ) { upperZ = v4._z; }


    _tileBoundingVolume = new Box(Vector3D(lowerX, lowerY, lowerZ),
                                  Vector3D(upperX, upperY, upperZ));
  }
  return _tileBoundingVolume;
}
Example #7
0
void Window::loadWindowState()
{
    const std::string &name = mWindowName;
    assert(!name.empty());

    setPosition((int) config.getValue(name + "WinX", mDefaultX),
                (int) config.getValue(name + "WinY", mDefaultY));

    if (mSaveVisible)
        setVisible((bool) config.getValue(name + "Visible", mDefaultVisible));

    if (mStickyButton)
        setSticky((bool) config.getValue(name + "Sticky", isSticky()));

    if (mGrip)
    {
        int width = (int) config.getValue(name + "WinWidth", mDefaultWidth);
        int height = (int) config.getValue(name + "WinHeight", mDefaultHeight);

        if (getMinWidth() > width)
            width = getMinWidth();
        else if (getMaxWidth() < width)
            width = getMaxWidth();
        if (getMinHeight() > height)
            height = getMinHeight();
        else if (getMaxHeight() < height)
            height = getMaxHeight();

        setSize(width, height);
    }
    else
    {
        setSize(mDefaultWidth, mDefaultHeight);
    }

    // Check if the window is off screen...
    checkIfIsOffScreen();
}
Example #8
0
void Window::setDefaultSize(int defaultWidth, int defaultHeight,
                            ImageRect::ImagePosition position,
                            int offsetX, int offsetY)
{
    if (getMinWidth() > defaultWidth)
        defaultWidth = getMinWidth();
    else if (getMaxWidth() < defaultWidth)
        defaultWidth = getMaxWidth();
    if (getMinHeight() > defaultHeight)
        defaultHeight = getMinHeight();
    else if (getMaxHeight() < defaultHeight)
        defaultHeight = getMaxHeight();

    int posX = 0, posY = 0;

    getRelativeOffset(position, posX, posY, defaultWidth, defaultHeight, 0, 0);

    mDefaultWidth = defaultWidth;
    mDefaultHeight = defaultHeight;
    mDefaultPosition = position;
    mDefaultOffsetX = posX - offsetX;
    mDefaultOffsetY = posY - offsetY;
}
bool LLNearbyChatBar::applyRectControl()
{
	bool rect_controlled = LLFloater::applyRectControl();

	if (!mNearbyChat->getVisible())
	{
		reshape(getRect().getWidth(), getMinHeight());
		enableResizeCtrls(true, true, false);
	}
	else
	{
		enableResizeCtrls(true);
		setResizeLimits(getMinWidth(), EXPANDED_MIN_HEIGHT);
	}
	
	return rect_controlled;
}
Example #10
0
void FloaterAO::onClickMore()
{
	LLRect fullSize=gSavedPerAccountSettings.getRect("floater_rect_animation_overrider_full");
	LLRect smallSize=getRect();

	if(fullSize.getHeight()<getMinHeight())
		fullSize.setOriginAndSize(fullSize.mLeft,fullSize.mBottom,fullSize.getWidth(),getRect().getHeight());

	if(fullSize.getWidth()<getMinWidth())
		fullSize.setOriginAndSize(fullSize.mLeft,fullSize.mBottom,getRect().getWidth(),fullSize.getHeight());

	mMore=TRUE;

	mSmallInterfacePanel->setVisible(FALSE);
	mMainInterfacePanel->setVisible(TRUE);
	setCanResize(TRUE);

	gSavedPerAccountSettings.setBOOL("UseFullAOInterface",TRUE);

	reshape(getRect().getWidth(),fullSize.getHeight());
}
Example #11
0
bool Tile::isVisible(const G3MRenderContext *rc,
                     const TileRenderContext* trc,
                     const Planet* planet,
                     const Vector3D& cameraNormalizedPosition,
                     double cameraAngle2HorizonInRadians,
                     const Frustum* cameraFrustumInModelCoordinates) {

////  const BoundingVolume* boundingVolume = getTessellatorMesh(rc, trc)->getBoundingVolume();
//  const BoundingVolume* boundingVolume = getBoundingVolume(rc, trc);
//  if (boundingVolume == NULL) {
//    return false;
//  }
//
//  if (!boundingVolume->touchesFrustum(cameraFrustumInModelCoordinates)) {
//    return false;
//  }
//
//  // test if sector is back oriented with respect to the camera
//  return !_sector.isBackOriented(rc,
//                                 getMinHeight(),
//                                 planet,
//                                 cameraNormalizedPosition,
//                                 cameraAngle2HorizonInRadians);


  // test if sector is back oriented with respect to the camera
  if (_sector.isBackOriented(rc,
                             getMinHeight(),
                             planet,
                             cameraNormalizedPosition,
                             cameraAngle2HorizonInRadians)) {
    return false;
  }

  const BoundingVolume* boundingVolume = getBoundingVolume(rc, trc);

  return ((boundingVolume != NULL)  &&
          boundingVolume->touchesFrustum(cameraFrustumInModelCoordinates));
}
Example #12
0
void Window::loadWindowState()
{
    const std::string &name = mWindowName;
    const std::string skinName = config.getValue(name + "Skin",
                                                 mSkin->getFilePath());
    assert(!name.empty());

    if (mGrip)
    {
        int width = (int) config.getValue(name + "WinWidth", mDefaultWidth);
        int height = (int) config.getValue(name + "WinHeight", mDefaultHeight);

        if (getMinWidth() > width)
            width = getMinWidth();
        else if (getMaxWidth() < width)
            width = getMaxWidth();
        if (getMinHeight() > height)
            height = getMinHeight();
        else if (getMaxHeight() < height)
            height = getMaxHeight();

        setSize(width, height);
    }
    else
    {
        setSize(mDefaultWidth, mDefaultHeight);
    }

    int x = (int) config.getValue(name + "WinX", -1);
    int y = (int) config.getValue(name + "WinY", -1);

    if (x != -1 || y != -1)
    {
        // These two tags are deprecated. Convert them to the new system, then
        // remove them to avoid client coordinate confusion.
        config.removeValue(mWindowName + "WinX");
        config.removeValue(mWindowName + "WinY");
        saveRelativeLocation(x, y);
    }

    int position = (int) config.getValue(name + "Position", -1);
    mOffsetX = (int) config.getValue(name + "OffsetX", mDefaultOffsetX);
    mOffsetY = (int) config.getValue(name + "OffsetY", mDefaultOffsetY);

    if (position != -1)
    {
        mPosition = (ImageRect::ImagePosition) position;
        setLocationRelativeTo(mPosition, mOffsetX, mOffsetY);
    }
    else
    {
        setLocationRelativeTo(mDefaultPosition, mDefaultOffsetX, mDefaultOffsetY);
    }

    if (mSaveVisibility)
    {
        setVisible((bool) config.getValue(name + "Visible", mDefaultVisible));
        mOldVisibility = (bool) config.getValue(name + "Hidden", false);
    }

    if (skinName.compare(mSkin->getFilePath()) != 0)
    {
        mSkin->instances--;
        mSkin = skinLoader->load(skinName, mDefaultSkinPath);
    }
}
Example #13
0
// virtual
void LLFloaterTexturePicker::draw()
{
	S32 floater_header_size = getHeaderHeight();
	if (mOwner)
	{
		// draw cone of context pointing back to texture swatch	
		LLRect owner_rect;
		mOwner->localRectToOtherView(mOwner->getLocalRect(), &owner_rect, this);
		LLRect local_rect = getLocalRect();
		if (gFocusMgr.childHasKeyboardFocus(this) && mOwner->isInVisibleChain() && mContextConeOpacity > 0.001f)
		{
			gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
			LLGLEnable(GL_CULL_FACE);
			gGL.begin(LLRender::QUADS);
			{
				gGL.color4f(0.f, 0.f, 0.f, CONTEXT_CONE_IN_ALPHA * mContextConeOpacity);
				gGL.vertex2i(owner_rect.mLeft, owner_rect.mTop);
				gGL.vertex2i(owner_rect.mRight, owner_rect.mTop);
				gGL.color4f(0.f, 0.f, 0.f, CONTEXT_CONE_OUT_ALPHA * mContextConeOpacity);
				gGL.vertex2i(local_rect.mRight, local_rect.mTop);
				gGL.vertex2i(local_rect.mLeft, local_rect.mTop);

				gGL.color4f(0.f, 0.f, 0.f, CONTEXT_CONE_OUT_ALPHA * mContextConeOpacity);
				gGL.vertex2i(local_rect.mLeft, local_rect.mTop);
				gGL.vertex2i(local_rect.mLeft, local_rect.mBottom);
				gGL.color4f(0.f, 0.f, 0.f, CONTEXT_CONE_IN_ALPHA * mContextConeOpacity);
				gGL.vertex2i(owner_rect.mLeft, owner_rect.mBottom);
				gGL.vertex2i(owner_rect.mLeft, owner_rect.mTop);

				gGL.color4f(0.f, 0.f, 0.f, CONTEXT_CONE_OUT_ALPHA * mContextConeOpacity);
				gGL.vertex2i(local_rect.mRight, local_rect.mBottom);
				gGL.vertex2i(local_rect.mRight, local_rect.mTop);
				gGL.color4f(0.f, 0.f, 0.f, CONTEXT_CONE_IN_ALPHA * mContextConeOpacity);
				gGL.vertex2i(owner_rect.mRight, owner_rect.mTop);
				gGL.vertex2i(owner_rect.mRight, owner_rect.mBottom);


				gGL.color4f(0.f, 0.f, 0.f, CONTEXT_CONE_OUT_ALPHA * mContextConeOpacity);
				gGL.vertex2i(local_rect.mLeft, local_rect.mBottom);
				gGL.vertex2i(local_rect.mRight, local_rect.mBottom);
				gGL.color4f(0.f, 0.f, 0.f, CONTEXT_CONE_IN_ALPHA * mContextConeOpacity);
				gGL.vertex2i(owner_rect.mRight, owner_rect.mBottom);
				gGL.vertex2i(owner_rect.mLeft, owner_rect.mBottom);
			}
			gGL.end();
		}
	}

	if (gFocusMgr.childHasMouseCapture(getDragHandle()))
	{
		mContextConeOpacity = lerp(mContextConeOpacity, gSavedSettings.getF32("PickerContextOpacity"), LLCriticalDamp::getInterpolant(CONTEXT_FADE_TIME));
	}
	else
	{
		mContextConeOpacity = lerp(mContextConeOpacity, 0.f, LLCriticalDamp::getInterpolant(CONTEXT_FADE_TIME));
	}

	updateImageStats();

	// if we're inactive, gray out "apply immediate" checkbox
	getChildView("show_folders_check")->setEnabled(mActive && mCanApplyImmediately && !mNoCopyTextureSelected);
	getChildView("Select")->setEnabled(mActive);
	getChildView("Pipette")->setEnabled(mActive);
	getChild<LLUICtrl>("Pipette")->setValue(LLToolMgr::getInstance()->getCurrentTool() == LLToolPipette::getInstance());

	//BOOL allow_copy = FALSE;
	if( mOwner ) 
	{
		mTexturep = NULL;
		if(mImageAssetID.notNull())
		{
			mTexturep = LLViewerTextureManager::getFetchedTexture(mImageAssetID, MIPMAP_YES);
			mTexturep->setBoostLevel(LLViewerTexture::BOOST_PREVIEW);
		}

		if (mTentativeLabel)
		{
			mTentativeLabel->setVisible( FALSE  );
		}

		getChildView("Default")->setEnabled(mImageAssetID != mOwner->getDefaultImageAssetID());
		getChildView("Blank")->setEnabled(mImageAssetID != mWhiteImageAssetID );
		getChildView("None")->setEnabled(mOwner->getAllowNoTexture() && !mImageAssetID.isNull() );

		LLFloater::draw();

		if( isMinimized() )
		{
			return;
		}

		// Border
		LLRect border( BORDER_PAD, 
					   getRect().getHeight() - floater_header_size - BORDER_PAD, 
					   ((getMinWidth() / 2) - TEXTURE_INVENTORY_PADDING - HPAD) - BORDER_PAD,
					   BORDER_PAD + FOOTER_HEIGHT + (getRect().getHeight() - getMinHeight()));
		gl_rect_2d( border, LLColor4::black, FALSE );


		// Interior
		LLRect interior = border;
		interior.stretch( -1 ); 

		// If the floater is focused, don't apply its alpha to the texture (STORM-677).
		const F32 alpha = getTransparencyType() == TT_ACTIVE ? 1.0f : getCurrentTransparency();
		if( mTexturep )
		{
			if( mTexturep->getComponents() == 4 )
			{
				gl_rect_2d_checkerboard( interior, alpha );
			}

			gl_draw_scaled_image( interior.mLeft, interior.mBottom, interior.getWidth(), interior.getHeight(), mTexturep, UI_VERTEX_COLOR % alpha );

			// Pump the priority
			mTexturep->addTextureStats( (F32)(interior.getWidth() * interior.getHeight()) );
		}
		else if (!mFallbackImage.isNull())
		{
			mFallbackImage->draw(interior, UI_VERTEX_COLOR % alpha);
		}
		else
		{
			gl_rect_2d( interior, LLColor4::grey % alpha, TRUE );

			// Draw X
			gl_draw_x(interior, LLColor4::black );
		}

		// Draw Tentative Label over the image
		if( mOwner->getTentative() && !mViewModel->isDirty() )
		{
			mTentativeLabel->setVisible( TRUE );
			drawChild(mTentativeLabel);
		}

		if (mSelectedItemPinned) return;

		LLFolderView* folder_view = mInventoryPanel->getRootFolder();
		if (!folder_view) return;

		LLInventoryFilter* filter = folder_view->getFilter();
		if (!filter) return;

		bool is_filter_active = folder_view->getCompletedFilterGeneration() < filter->getCurrentGeneration() &&
				filter->isNotDefault();

		// After inventory panel filter is applied we have to update
		// constraint rect for the selected item because of folder view
		// AutoSelectOverride set to TRUE. We force PinningSelectedItem
		// flag to FALSE state and setting filter "dirty" to update
		// scroll container to show selected item (see LLFolderView::doIdle()).
		if (!is_filter_active && !mSelectedItemPinned)
		{
			folder_view->setPinningSelectedItem(mSelectedItemPinned);
			folder_view->dirtyFilter();
			folder_view->arrangeFromRoot();

			mSelectedItemPinned = TRUE;
		}
	}
}
Example #14
0
bool HelloWorld::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
    
    auto visibleSize = Director::getInstance()->getVisibleSize();
    auto origin = Director::getInstance()->getVisibleOrigin();



	camera = Camera::createPerspective(30, (float)visibleSize.width / visibleSize.height, 1.0, 1000);
	camera->setBackgroundBrush(CameraBackgroundBrush::createColorBrush(Color4F(0.0f, 1.0f, 1.0f, 0.5f), 1.0f));
	camera->setPosition3D(Vec3(0.0f, 50.0f, 100.0f));
	camera->lookAt(Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0, 1.0, 0.0));
	camera->setCameraFlag(CameraFlag::USER2);
	this->addChild(camera);

	/**
	//Create Plane
	Physics3DRigidBodyDes rbd_plan;
	rbd_plan.mass = 0.0f;
	rbd_plan.shape = Physics3DShape::createBox(Vec3(500, 5.0f, 500));
	auto physics_rbd_plan = Physics3DRigidBody::create(&rbd_plan);
	physics_rbd_plan->setFriction(20);
	auto component_plan = Physics3DComponent::create(physics_rbd_plan);
	_plan = Sprite3D::create("box.c3t");
	_plan->setTexture("plane.png");
	_plan->setScale(30.0f);
	_plan->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0));
	_plan->setScaleX(500);
	_plan->setScaleY(5);
	_plan->setScaleZ(500);
	_plan->setPositionZ(0);
	_plan->setPositionY(0);
	_plan->setPositionX(0);
	_plan->setGlobalZOrder(-1);
	_plan->addComponent(component_plan);
	component_plan->syncNodeToPhysics();
	component_plan->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::NONE);
	_plan->setCameraMask((unsigned short)CameraFlag::USER2);
	this->addChild(_plan, 1);
	**/
	Terrain::DetailMap r("dirt.jpg");
	Terrain::TerrainData data("heightmap16.jpg", "alphamap.png", r, r, r, r, Size(32, 32), 5.0f, 1.0f);
	auto _terrain = Terrain::create(data, Terrain::CrackFixedType::SKIRT);
	_terrain->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0));
	_terrain->setPositionZ(0);
	_terrain->setPositionY(0);
	_terrain->setPositionX(0);
	_terrain->setLODDistance(64, 128, 192);
	_terrain->setDrawWire(false);
	_terrain->setMaxDetailMapAmount(4);
	_terrain->setSkirtHeightRatio(2);
	_terrain->setCameraMask((unsigned short)CameraFlag::USER2);
	//create terrain
	std::vector<float> heidata = _terrain->getHeightData();
	auto size = _terrain->getTerrainSize();
	Physics3DColliderDes colliderDes;
	colliderDes.shape = Physics3DShape::createHeightfield(size.width, size.height, &heidata[0], 1.0f, _terrain->getMinHeight(), _terrain->getMaxHeight(), true, false, true);
	auto collider = Physics3DCollider::create(&colliderDes);
	auto component = Physics3DComponent::create(collider);
	_terrain->addComponent(component);
	component->syncNodeToPhysics();
	component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::NONE);
	this->addChild(_terrain);

	
	//////////////////////////////////////////////// car
	Physics3DRigidBodyDes rbd_cabine;
	rbd_cabine.disableSleep = true;
	rbd_cabine.mass = 500.0f;
	rbd_cabine.shape = Physics3DShape::createBox(Vec3(4, 2.0f, 8));
	physics_rbd_cabine = Physics3DRigidBody::create(&rbd_cabine);
	auto cabine_component = Physics3DComponent::create(physics_rbd_cabine);
	car_cabine = Sprite3D::create("T-90.c3t");
	car_cabine->setTexture("Main Body 2.png");
	car_cabine->setScale(3);
	//car_cabine->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0));
	car_cabine->setPositionX(0);
	car_cabine->setPositionY(10);
	car_cabine->setPositionZ(0);
	car_cabine->setGlobalZOrder(-1);
	car_cabine->addComponent(cabine_component);
	cabine_component->syncNodeToPhysics();
	cabine_component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
	car_cabine->setCameraMask((unsigned short)CameraFlag::USER2);
	this->addChild(car_cabine, 1);


	Physics3DRigidBodyDes rbd_wheel1;
	rbd_wheel1.disableSleep = true;
	rbd_wheel1.mass = 15.0f;
	//rbd_wheel1.shape = Physics3DShape::createCylinder(3, 1);
	rbd_wheel1.shape = Physics3DShape::createSphere(1.5);
	auto physics_rbd_wheel1 = Physics3DRigidBody::create(&rbd_wheel1);
	auto wheel1_component = Physics3DComponent::create(physics_rbd_wheel1);
	wheel1 = Sprite3D::create();
	//wheel1->setTexture("Gun.png");
	//wheel1->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0));
	wheel1->setPositionX(0);
	wheel1->setPositionY(10);
	wheel1->setPositionZ(0);
	wheel1->setGlobalZOrder(-1);
	wheel1->addComponent(wheel1_component);
	wheel1_component->syncNodeToPhysics();
	wheel1_component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
	wheel1->setCameraMask((unsigned short)CameraFlag::USER2);
	this->addChild(wheel1, 1);

	Physics3DRigidBodyDes rbd_wheel2;
	rbd_wheel2.disableSleep = true;
	rbd_wheel2.mass = 15.0f;
	//rbd_wheel2.shape = Physics3DShape::createCylinder(3, 1);
	rbd_wheel2.shape = Physics3DShape::createSphere(1.5);
	auto physics_rbd_wheel2 = Physics3DRigidBody::create(&rbd_wheel2);
	auto wheel2_component = Physics3DComponent::create(physics_rbd_wheel2);
	wheel2 = Sprite3D::create();
	//wheel2->setTexture("Gun.png");
	//wheel2->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0));
	wheel2->setPositionX(0);
	wheel2->setPositionY(10);
	wheel2->setPositionZ(0);
	wheel2->setGlobalZOrder(-1);
	wheel2->addComponent(wheel2_component);
	wheel2_component->syncNodeToPhysics();
	wheel2_component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
	wheel2->setCameraMask((unsigned short)CameraFlag::USER2);
	this->addChild(wheel2, 1);

	Physics3DRigidBodyDes rbd_wheel3;
	rbd_wheel3.disableSleep = true;
	rbd_wheel3.mass = 15.0f;
	rbd_wheel3.shape = Physics3DShape::createSphere(1.5);
	//rbd_wheel3.shape = Physics3DShape::createCylinder(3, 1);
	physics_rbd_wheel3 = Physics3DRigidBody::create(&rbd_wheel3);
	auto wheel3_component = Physics3DComponent::create(physics_rbd_wheel3);
	wheel3 = Sprite3D::create();
	//wheel3->setTexture("Gun.png");
	//wheel3->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0));
	wheel3->setPositionX(0);
	wheel3->setPositionY(10);
	wheel3->setPositionZ(0);
	wheel3->setGlobalZOrder(-1);
	wheel3->addComponent(wheel3_component);
	wheel3_component->syncNodeToPhysics();
	wheel3_component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
	wheel3->setCameraMask((unsigned short)CameraFlag::USER2);
	this->addChild(wheel3, 1);

	Physics3DRigidBodyDes rbd_wheel4;
	rbd_wheel4.disableSleep = true;
	rbd_wheel4.mass = 15.0f;
	//rbd_wheel4.shape = Physics3DShape::createCylinder(3, 1);
	rbd_wheel4.shape = Physics3DShape::createSphere(1.5);
	physics_rbd_wheel4 = Physics3DRigidBody::create(&rbd_wheel4);
	auto wheel4_component = Physics3DComponent::create(physics_rbd_wheel4);
	wheel4 = Sprite3D::create();
	//wheel3->setTexture("Gun.png");
	//wheel4->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0));
	wheel4->setPositionX(0);
	wheel4->setPositionY(10);
	wheel4->setPositionZ(0);
	wheel4->setGlobalZOrder(-1);
	wheel4->addComponent(wheel4_component);
	wheel4_component->syncNodeToPhysics();
	wheel4_component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
	wheel4->setCameraMask((unsigned short)CameraFlag::USER2);
	this->addChild(wheel4, 1);

	Physics3DRigidBodyDes rbd_wheel_bar;
	rbd_wheel_bar.disableSleep = true;
	rbd_wheel_bar.mass = 400.0f;
	rbd_wheel_bar.shape = Physics3DShape::createBox(Vec3(2, 2.0f, 6));
	physics_rbd_wheel_bar = Physics3DRigidBody::create(&rbd_wheel_bar);
	auto car_wheel_bar_component = Physics3DComponent::create(physics_rbd_wheel_bar);
	car_wheel_bar = Sprite3D::create();
	//car_wheel_bar->setTexture("Gun.png");
	car_wheel_bar->setScale(0.01);
	car_wheel_bar->setPositionX(0);
	car_wheel_bar->setPositionY(10);
	car_wheel_bar->setPositionZ(0);
	//car_wheel_bar->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0));
	car_wheel_bar->setGlobalZOrder(-1);
	car_wheel_bar->addComponent(car_wheel_bar_component);
	car_wheel_bar_component->syncNodeToPhysics();
	car_wheel_bar_component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
	car_wheel_bar->setCameraMask((unsigned short)CameraFlag::USER2);
	this->addChild(car_wheel_bar, 1);

	auto constraint = Physics3DHingeConstraint::create(physics_rbd_cabine, physics_rbd_wheel1, Vec3(0.0f, 0.0, 6.0f), Vec3(0.f, -3.0f, 0.f), Vec3(1.0f, 0.0, 0.0f), Vec3(0.f, 1.0f, 0.f));
	psychics_scene->getPhysics3DWorld()->addPhysics3DConstraint(constraint);
	auto constraint2 = Physics3DHingeConstraint::create(physics_rbd_cabine, physics_rbd_wheel2, Vec3(0.0f, 0.0, 6.0f), Vec3(0.f, 3.0f, 0.f), Vec3(1.0f, 0.0, 0.0f), Vec3(0.f, 1.0f, 0.f));
	psychics_scene->getPhysics3DWorld()->addPhysics3DConstraint(constraint2);


	constraint5 = Physics3DHingeConstraint::create(physics_rbd_cabine, physics_rbd_wheel_bar, Vec3(0.0f, 0.0, -6.0f), Vec3(0.f, 0.0f, 0.f), Vec3(0.0f, 1.0, 0.0f), Vec3(0.f, 1.0f, 0.f));
	constraint5->setLimit(CC_DEGREES_TO_RADIANS(-0.5), CC_DEGREES_TO_RADIANS(0.5));
	psychics_scene->getPhysics3DWorld()->addPhysics3DConstraint(constraint5);


	auto constraint3 = Physics3DHingeConstraint::create(physics_rbd_wheel_bar, physics_rbd_wheel3, Vec3(0.0f, 0.0, -3.0f), Vec3(0.f, -3.0f, 0.f), Vec3(1.0f, 0.0, 0.0f), Vec3(0.f, 1.0f, 0.f));
	psychics_scene->getPhysics3DWorld()->addPhysics3DConstraint(constraint3);
	auto constraint4 = Physics3DHingeConstraint::create(physics_rbd_wheel_bar, physics_rbd_wheel4, Vec3(0.0f, 0.0, -3.0f), Vec3(0.f, 3.0f, 0.f), Vec3(1.0f, 0.0, 0.0f), Vec3(0.f, 1.0f, 0.f));
	psychics_scene->getPhysics3DWorld()->addPhysics3DConstraint(constraint4);


	//add a point light
	auto light = PointLight::create(Vec3(0, 50, 0), Color3B(255, 255, 255), 150);
	addChild(light);
	//set the ambient light 
	auto ambient = AmbientLight::create(Color3B(55, 55, 55));
	addChild(ambient);


	/**
	Physics3DRigidBodyDes boxesrbDes;
	boxesrbDes.mass = 1.f;
	boxesrbDes.shape = Physics3DShape::createBox(Vec3(5, 5, 5));
	float start_x = 10- ARRAY_SIZE_X / 2;
	float start_y = 0 + 5.0f;
	float start_z = 10 - ARRAY_SIZE_Z / 2;

	for (int k = 0; k<ARRAY_SIZE_Y; k++)
	{
		for (int i = 0; i<ARRAY_SIZE_X; i++)
		{
			for (int j = 0; j<ARRAY_SIZE_Z; j++)
			{
				float x = 1.0*i + start_x;
				float y = 5.0 + 1.0*k + start_y;
				float z = 1.0*j + start_z;
				boxesrbDes.originalTransform.setIdentity();
				boxesrbDes.originalTransform.translate(x, y, z);

				auto sprite = PhysicsSprite3D::create("box.c3t", &boxesrbDes);
				sprite->setTexture("plane.png");
				sprite->setCameraMask((unsigned short)CameraFlag::USER1);
				sprite->setScale(1.0f / sprite->getContentSize().width);
				this->addChild(sprite);
				sprite->setPosition3D(Vec3(x, y, z));
				sprite->syncNodeToPhysics();

				sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
			}
		}
	}

	**/



	auto listener = EventListenerTouchAllAtOnce::create();
	listener->onTouchesBegan = CC_CALLBACK_2(HelloWorld::onTouchesBegan, this);
	listener->onTouchesMoved = CC_CALLBACK_2(HelloWorld::onTouchesMoved, this);
	listener->onTouchesEnded = CC_CALLBACK_2(HelloWorld::onTouchesEnded, this);
	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);


	//psychics_scene->setPhysics3DDebugCamera(camera); 
	schedule(schedule_selector(HelloWorld::myupdate), .005);
	//this->scheduleUpdate();
	
    return true;
}
Example #15
0
bool Physics3DTerrainDemo::init()
{
    if (!Physics3DTestDemo::init())
        return false;

    Terrain::DetailMap r("TerrainTest/dirt.jpg"),g("TerrainTest/Grass2.jpg",10),b("TerrainTest/road.jpg"),a("TerrainTest/GreenSkin.jpg",20);
    
    Terrain::TerrainData data("TerrainTest/heightmap129.jpg","TerrainTest/alphamap.png",r,g,b,a,Size(32,32), 20.0f, 1.0f);
    auto terrain = Terrain::create(data,Terrain::CrackFixedType::SKIRT);
    terrain->setMaxDetailMapAmount(4);
    terrain->setCameraMask(2);
    terrain->setDrawWire(false);
    
    terrain->setSkirtHeightRatio(3);
    terrain->setLODDistance(64,128,192);
    terrain->setCameraMask((unsigned short)CameraFlag::USER1);

    //create terrain
    Physics3DRigidBodyDes rbDes;
    rbDes.mass = 0.0f;
    std::vector<float> heidata = terrain->getHeightData();
    auto size = terrain->getTerrainSize();
    rbDes.shape = Physics3DShape::createHeightfield(size.width, size.height, &heidata[0], 1.0f, terrain->getMinHeight(), terrain->getMaxHeight(), true, false, true);
    auto rigidBody = Physics3DRigidBody::create(&rbDes);
    auto component = Physics3DComponent::create(rigidBody);
    terrain->addComponent(component);
    this->addChild(terrain);
    component->syncNodeToPhysics();
    component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::NONE);


    //create several spheres
    rbDes.mass = 1.f;
    rbDes.shape = Physics3DShape::createSphere(0.5f);
    float start_x = START_POS_X - ARRAY_SIZE_X/2 + 5.0f;
    float start_y = START_POS_Y + 20.0f;
    float start_z = START_POS_Z - ARRAY_SIZE_Z/2;

    for (int k=0;k<ARRAY_SIZE_Y;k++)
    {
        for (int i=0;i<ARRAY_SIZE_X;i++)
        {
            for(int j = 0;j<ARRAY_SIZE_Z;j++)
            {
                float x = 1.0*i + start_x;
                float y = 5.0+1.0*k + start_y;
                float z = 1.0*j + start_z;

                auto sprite = PhysicsSprite3D::create("Sprite3DTest/sphere.c3b", &rbDes);
                sprite->setTexture("Sprite3DTest/plane.png");
                sprite->setCameraMask((unsigned short)CameraFlag::USER1);
                sprite->setScale(1.0f / sprite->getContentSize().width);
                sprite->setPosition3D(Vec3(x, y, z));
                this->addChild(sprite);
                sprite->syncNodeToPhysics();
                sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
            }
        }
    }

    //create mesh
    std::vector<Vec3> trianglesList = Bundle3D::getTrianglesList("Sprite3DTest/boss.c3b");

    rbDes.mass = 0.0f;
    rbDes.shape = Physics3DShape::createMesh(&trianglesList[0], (int)trianglesList.size() / 3);
    rigidBody = Physics3DRigidBody::create(&rbDes);
    component = Physics3DComponent::create(rigidBody);
    auto sprite = Sprite3D::create("Sprite3DTest/boss.c3b");
    sprite->addComponent(component);
    sprite->setRotation3D(Vec3(-90.0f, 0.0f, 0.0f));
    sprite->setPosition3D(Vec3(0.0f, 15.0f, 0.0f));
    sprite->setCameraMask(2);
    this->addChild(sprite);

    std::vector<std::pair<Physics3DShape*, Mat4> > shapeList;
    {
        Mat4 localTrans;
        auto bodyshape = Physics3DShape::createBox(Vec3(2.0f, 4.0f, 2.0f));
        Mat4::createTranslation(0.0f, 2.0f, 0.0f, &localTrans);
        shapeList.push_back(std::make_pair(bodyshape, localTrans));
        auto headshape = Physics3DShape::createSphere(1.5f);
        Mat4::createTranslation(0.6f, 5.0f, -1.5f, &localTrans);
        shapeList.push_back(std::make_pair(headshape, localTrans));
        auto lhandshape = Physics3DShape::createBox(Vec3(1.0f, 3.0f, 1.0f));
        Mat4::createRotation(Vec3(1.0f, 0.0f, 0.0f), CC_DEGREES_TO_RADIANS(15.0f), &localTrans);
        localTrans.m[12] = -1.5f; localTrans.m[13] = 2.5f; localTrans.m[14] = -2.5f;
        shapeList.push_back(std::make_pair(lhandshape, localTrans));
        auto rhandshape = Physics3DShape::createBox(Vec3(1.0f, 3.0f, 1.0f));
        Mat4::createRotation(Vec3(1.0f, 0.0f, 0.0f), CC_DEGREES_TO_RADIANS(-15.0f), &localTrans);
        localTrans.m[12] = 2.0f; localTrans.m[13] = 2.5f; localTrans.m[14] = 1.f;
        shapeList.push_back(std::make_pair(rhandshape, localTrans));

        rbDes.mass = 10.0f;
        rbDes.shape = Physics3DShape::createCompoundShape(shapeList);
        rigidBody = Physics3DRigidBody::create(&rbDes);
        component = Physics3DComponent::create(rigidBody);
        auto sprite = Sprite3D::create("Sprite3DTest/orc.c3b");
        sprite->addComponent(component);
        sprite->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
        sprite->setPosition3D(Vec3(-5.0f, 20.0f, 0.0f));
        sprite->setScale(0.4f);
        sprite->setCameraMask(2);
        this->addChild(sprite);
    }


    physicsScene->setPhysics3DDebugCamera(_camera);
    return true;
}
    double TransparentScrollBarH::calcButtonHeight()
    {
        auto scrollButton = qobject_cast<TransparentScrollButtonH*>(getScrollButton());

        return std::max((int)(calcScrollBarRatio() * view_->height()), scrollButton->getMinHeight());
    }