Пример #1
0
// public PictureResult(string path, int rotation) [instance] :99
void PictureResult::ctor_(uString* path, int rotation)
{
    Path(path);
    Rotation(rotation);
}
Пример #2
0
void Document::transform(qreal x, qreal y, qreal angle, qreal scale)
{
    qDebug() << "transform(" << x << "," << y << "," << angle << "," << scale << ")";
    translatePixels(Rotation(x, y, angle, scale));
}
Пример #3
0
// Update our rendering scene. Note, that displaying is separated form
// the actual simulation process.
void SceneController::updateScene() {

	if (m_bInternalError)
		// something goes terribly wrong
		return;

	{ // synchronize scene mines objects with back-end ones
		int diff = vecMines.size() - gsMines.size();
		if (diff > 0) {
			for (int i = diff; i; --i)
				gsMines.push_back(gs->addPolygon(objectMine));
		}
		else if (diff < 0) {
			for (int i = diff; i; ++i) {
				delete gsMines.back();
				gsMines.pop_back();
			}
		}
	}

	{ // synchronize scene minesweeper objects with back-end ones
		int diff = vecSweepers.size() - gsSweepers.size();
		if (diff > 0) {
			for (int i = diff; i; --i)
				gsSweepers.push_back(gs->addPolygon(objectSweeper));
		}
		else if (diff < 0) {
		}
	}

	// update mine positions
	for (auto i = vecMines.size(); i; --i) {
		auto object = vecMines[i - 1];
		auto *item = gsMines[i - 1];
		item->setPos(object.x, object.y);
		item->setScale(MainWindow::s.dMineScale);
		item->setPen(gsMinePen);
	}

	// get the fitness score list and sort it in the descending order
	// in order to get the fitness threshold value for elite classification
	QVector<int> fitness;
	for (auto i = vecSweepers.size(); i; --i)
		fitness.push_back(vecSweepers[i - 1].Fitness());
	qSort(fitness.begin(), fitness.end(), qGreater<int>());
	int fitnessThreshold = fitness[MainWindow::s.iNumElite] + 1;

	// update minesweeper positions, rotations and colors
	for (auto i = vecSweepers.size(); i; --i) {
		auto object = vecSweepers[i - 1];
		auto *item = gsSweepers[i - 1];
		item->setPos(object.Position().x, object.Position().y);
		item->setRotation(object.Rotation() * 180 / M_PI);
		item->setScale(MainWindow::s.dSweeperScale);

		// we want the fittest displayed in a different color
		if (object.Fitness() >= fitnessThreshold)
			item->setPen(gsElitePen);
		else
			item->setPen(gsDefaultPen);
	}

	// update info statistics
	QString textGeneration = QString("Generation: %1 [TTL: %2]\n")
		.arg(m_iGenerations).arg(MainWindow::s.iNumTicks - m_iTicks);
	QString textFitness = QString("Fitness: best: %1, avge: %2\n")
		.arg(m_pGA->BestFitness()).arg(m_pGA->AverageFitness());
	QString textElite = QString("Elite threshold: %1\n").arg(fitnessThreshold);
	gsInfo->setText(textGeneration + textFitness + textElite);

}
Пример #4
0
Matrix3 Matrix3::ChangeRotate(Matrix3 pos, float r)
{
	return (Rotation(r) * pos);
}
Пример #5
0
Adjoint::Adjoint()
{
  construct(Rotation(), Translation());
}
Пример #6
0
int cCamera::Control()
{
    if(m_Number != CurrCamera) return -1;


#ifndef DIMENSION_3D // 2D
    /* 상하좌우 이동 */
    float Speed = VFR(0.05f);

    if(cCore::Input.KeyPress('W'))
    {
        AddEyePt(0.f, Speed, 0.f);
        AddLookAt(0.f, Speed, 0.f);
    }
    else if(cCore::Input.KeyPress('S'))
    {
        AddEyePt(0.f, -Speed, 0.f);
        AddLookAt(0.f, -Speed, 0.f);
    }

    if(cCore::Input.KeyPress('A'))
    {
        AddEyePt(-Speed, 0.f, 0.f);
        AddLookAt(-Speed, 0.f, 0.f);
    }
    else if(cCore::Input.KeyPress('D'))
    {
        AddEyePt(Speed, 0.f, 0.f);
        AddLookAt(Speed, 0.f, 0.f);
    }
#else
#ifdef VIEW_3D
    /* 마우스 좌클릭 드래그로 카메라 회전 */
    if(cCore::Input.MousePress(VK_LBUTTON))
    {
#ifdef NOTUSE_VFR
        Rotation(VFR(+0.2f));
#else
        Rotation(VFR(+0.2f));
#endif
    }


    /* 쉬프트키와 스페이스키로 위아래 이동 */
    if(cCore::Input.KeyPress(VK_LSHIFT))
    {
        AddEyePt(0, VFR(-0.2f), 0);
        AddLookAt(0, VFR(-0.2f), 0);
    }
    else if(cCore::Input.KeyPress(VK_SPACE))
    {
        AddEyePt(0, VFR(0.2f), 0);
        AddLookAt(0, VFR(0.2f), 0);
    }


    /* 카메라가 보는 방향을 기준으로 앞, 뒤, 옆으로 이동 */
    if(cCore::Input.KeyPress('W'))
    {
        MoveForward(VFR(+0.2f));
    }
    else if(cCore::Input.KeyPress('S'))
    {
        MoveBackward(VFR(0.2f));
    }

    if(cCore::Input.KeyPress('A'))
    {
        MoveSideward(VFR(-0.1f));
    }
    else if(cCore::Input.KeyPress('D'))
    {
        MoveSideward(VFR(+0.1f));
    }


    /* 카메라가 보는곳을 중심으로 회전 */
    if(cCore::Input.KeyPress('Q'))
    {
        MoveSideward(VFR(-0.2f), false);
    }
    else if(cCore::Input.KeyPress('E'))
    {
        MoveSideward(VFR(+0.2f), false);
    }
#else
    /* 상하좌우 이동 */
    float Speed = VFR(0.05f);

    if(cCore::Input.KeyPress('W'))
    {
        AddEyePt(Speed, 0.f, Speed);
        AddLookAt(Speed, 0.f, Speed);
    }
    else if(cCore::Input.KeyPress('S'))
    {
        AddEyePt(-Speed, 0.f, -Speed);
        AddLookAt(-Speed, 0.f, -Speed);
    }

    if(cCore::Input.KeyPress('A'))
    {
        AddEyePt(-Speed, 0.f, Speed);
        AddLookAt(-Speed, 0.f, Speed);
    }
    else if(cCore::Input.KeyPress('D'))
    {
        AddEyePt(Speed, 0.f, -Speed);
        AddLookAt(Speed, 0.f, -Speed);
    }
#endif
#endif


    return 0;
}
Пример #7
0
/**
 * Adds delta movement into the tracker.
 */
void FMouseDeltaTracker::AddDelta(FEditorViewportClient* InViewportClient, FKey InKey, const int32 InDelta, bool InNudge)
{
	const bool LeftMouseButtonDown = InViewportClient->Viewport->KeyState(EKeys::LeftMouseButton);
	const bool RightMouseButtonDown = InViewportClient->Viewport->KeyState(EKeys::RightMouseButton);
	const bool MiddleMouseButtonDown = InViewportClient->Viewport->KeyState(EKeys::MiddleMouseButton);
	const bool bAltDown = InViewportClient->IsAltPressed();
	const bool bShiftDown = InViewportClient->IsShiftPressed();
	const bool bControlDown = InViewportClient->IsCtrlPressed();

	if( !LeftMouseButtonDown && !MiddleMouseButtonDown && !RightMouseButtonDown && !InNudge )
	{
		return;
	}

	// Accumulate raw delta
	RawDelta += FVector(InKey == EKeys::MouseX ? InDelta : 0,
						InKey == EKeys::MouseY ? InDelta : 0,
						0);

	// Note that AddDelta has been called since StartTracking
	bHasReceivedAddDelta = true;

	// If we are using a drag tool, the widget isn't involved so set it to having no active axis.  This
	// means we will get unmodified mouse movement returned to us by other functions.

	const EAxisList::Type SaveAxis = InViewportClient->GetCurrentWidgetAxis();

	// If the user isn't dragging with the left mouse button, clear out the axis 
	// as the widget only responds to the left mouse button.
	//
	// We allow an exception for dragging with the left and/or right mouse button while holding control
	// as that simulates moving objects with the gizmo
	//
	// We also allow the exception of the middle mouse button when Alt is pressed as it 
	// allows movement of only the pivot.
	const bool bIsOrthoObjectRotation = bControlDown && InViewportClient->IsOrtho();
	const bool bUsingDragTool = UsingDragTool();
	const bool bUsingAxis = !bUsingDragTool && (LeftMouseButtonDown || (bAltDown && MiddleMouseButtonDown) || ((bIsOrthoObjectRotation || bControlDown) && RightMouseButtonDown));

	ConditionalBeginUsingDragTool( InViewportClient );

	if( bUsingDragTool || !InViewportClient->IsTracking() || !bUsingAxis )
	{
		InViewportClient->SetCurrentWidgetAxis( EAxisList::None );
	}

	FVector Wk = InViewportClient->TranslateDelta( InKey, InDelta, InNudge );

	EndScreen += Wk;

	if( InViewportClient->GetCurrentWidgetAxis() != EAxisList::None )
	{
		// Affect input delta by the camera speed

		FWidget::EWidgetMode WidgetMode = InViewportClient->GetWidgetMode();
		bool bIsRotation = (WidgetMode == FWidget::WM_Rotate) 
			|| ( ( WidgetMode == FWidget::WM_TranslateRotateZ ) && ( InViewportClient->GetCurrentWidgetAxis() == EAxisList::ZRotation ) )
			|| ( ( WidgetMode == FWidget::WM_2D) && (InViewportClient->GetCurrentWidgetAxis() == EAxisList::Rotate2D ) );
		if (bIsRotation)
		{
			Wk *= GetDefault<ULevelEditorViewportSettings>()->MouseSensitivty;
		}
		else if( WidgetMode == FWidget::WM_Scale && !GEditor->UsePercentageBasedScaling() )
		{
			const float ScaleSpeedMultipler = 0.01f;
			Wk *= ScaleSpeedMultipler;
		}

		// Make rotations occur at the same speed, regardless of ortho zoom

		if( InViewportClient->IsOrtho() )
		{
			if (bIsRotation)
			{
				float Scale = 1.0f;

				if( InViewportClient->IsOrtho() )
				{
					Scale = DEFAULT_ORTHOZOOM / (float)InViewportClient->GetOrthoZoom();
				}

				Wk *= Scale;
			}
		}
		//if Absolute Translation, and not just moving the camera around
		else if (InViewportClient->IsUsingAbsoluteTranslation())
		{
			// Compute a view.
			FSceneViewFamilyContext ViewFamily(FSceneViewFamily::ConstructionValues( 
				InViewportClient->Viewport, 
				InViewportClient->GetScene(),
				InViewportClient->EngineShowFlags )
				.SetRealtimeUpdate( InViewportClient->IsRealtime() ));

			FSceneView* View = InViewportClient->CalcSceneView( &ViewFamily );

			//calculate mouse position
			check(InViewportClient->Viewport);
			FVector2D MousePosition(InViewportClient->Viewport->GetMouseX(), InViewportClient->Viewport->GetMouseY());
			FVector WidgetPosition = InViewportClient->GetWidgetLocation();

			FRotator TempRot;
			FVector TempScale;
			InViewportClient->Widget->AbsoluteTranslationConvertMouseMovementToAxisMovement(View, InViewportClient, WidgetPosition, MousePosition, Wk, TempRot, TempScale );
		}
	}

	End += Wk;
	EndSnapped = End;

	
	if( UsingDragTool() )
	{
		FVector Drag = Wk;
		if( DragTool->bConvertDelta )
		{
			FRotator Rot;
			InViewportClient->ConvertMovementToDragRot( Wk, Drag, Rot );
		}

		if ( InViewportClient->IsPerspective() )
		{
			DragTool->AddDelta(Wk);
		}
		else
		{
			DragTool->AddDelta( Drag );
		}

		InViewportClient->SetCurrentWidgetAxis( SaveAxis );
	}
	else
	{
		switch( InViewportClient->GetWidgetMode() )
		{
			case FWidget::WM_Translate:
				FSnappingUtils::SnapPointToGrid( EndSnapped, FVector(GEditor->GetGridSize(),GEditor->GetGridSize(),GEditor->GetGridSize()) );
				break;

			case FWidget::WM_Scale:
				FSnappingUtils::SnapScale( EndSnapped, FVector(GEditor->GetGridSize(),GEditor->GetGridSize(),GEditor->GetGridSize()) );
				break;

			case FWidget::WM_Rotate:
			{
				FRotator Rotation( EndSnapped.X, EndSnapped.Y, EndSnapped.Z );
				FSnappingUtils::SnapRotatorToGrid( Rotation );
				EndSnapped = FVector( Rotation.Pitch, Rotation.Yaw, Rotation.Roll );
			}
			break;
			case FWidget::WM_TranslateRotateZ:
			case FWidget::WM_2D:
			{
				if (InViewportClient->GetCurrentWidgetAxis() == EAxisList::Rotate2D)
				{
					FRotator Rotation( EndSnapped.X, EndSnapped.Y, EndSnapped.Z );
					FSnappingUtils::SnapRotatorToGrid( Rotation );
					EndSnapped = FVector( Rotation.Pitch, Rotation.Yaw, Rotation.Roll );
				}
				else
				{
					//translation (either xy plane or z)
					FSnappingUtils::SnapPointToGrid( EndSnapped, FVector(GEditor->GetGridSize(),GEditor->GetGridSize(),GEditor->GetGridSize()) );
				}
			}

			default:
				break;
		}
	}

}
Пример #8
0
Matrix4 Matrix4::Rotation(const Vec3f &Axis, float Angle, const Vec3f &Center)
{
    return Translation(-Center) * Rotation(Axis, Angle) * Translation(Center);
}
Пример #9
0
/*
============
idClip::Motion
============
*/
bool idClip::Motion( trace_t &results, const idVec3 &start, const idVec3 &end, const idRotation &rotation,
					const idClipModel *mdl, const idMat3 &trmAxis, int contentMask, const idEntity *passEntity ) {
	int i, num;
	idClipModel *touch, *clipModelList[MAX_GENTITIES];
	idVec3 dir, endPosition;
	idBounds traceBounds;
	float radius;
	trace_t translationalTrace, rotationalTrace, trace;
	idRotation endRotation;
	const idTraceModel *trm;

	assert( rotation.GetOrigin() == start );

	if ( TestHugeTranslation( results, mdl, start, end, trmAxis ) ) {
		return true;
	}

	if ( mdl != NULL && rotation.GetAngle() != 0.0f && rotation.GetVec() != vec3_origin ) {
		// if no translation
		if ( start == end ) {
			// pure rotation
			return Rotation( results, start, rotation, mdl, trmAxis, contentMask, passEntity );
		}
	} else if ( start != end ) {
		// pure translation
		return Translation( results, start, end, mdl, trmAxis, contentMask, passEntity );
	} else {
		// no motion
		results.fraction = 1.0f;
		results.endpos = start;
		results.endAxis = trmAxis;
		return false;
	}

	trm = TraceModelForClipModel( mdl );

	radius = trm->bounds.GetRadius();

	if ( !passEntity || passEntity->entityNumber != ENTITYNUM_WORLD ) {
		// translational collision with world
		idClip::numTranslations++;
		collisionModelManager->Translation( &translationalTrace, start, end, trm, trmAxis, contentMask, 0, vec3_origin, mat3_default );
		translationalTrace.c.entityNum = translationalTrace.fraction != 1.0f ? ENTITYNUM_WORLD : ENTITYNUM_NONE;
	} else {
		memset( &translationalTrace, 0, sizeof( translationalTrace ) );
		translationalTrace.fraction = 1.0f;
		translationalTrace.endpos = end;
		translationalTrace.endAxis = trmAxis;
	}

	if ( translationalTrace.fraction != 0.0f ) {

		traceBounds.FromBoundsRotation( trm->bounds, start, trmAxis, rotation );
		dir = translationalTrace.endpos - start;
		for ( i = 0; i < 3; i++ ) {
			if ( dir[i] < 0.0f ) {
				traceBounds[0][i] += dir[i];
			}
			else {
				traceBounds[1][i] += dir[i];
			}
		}

		num = GetTraceClipModels( traceBounds, contentMask, passEntity, clipModelList );

		for ( i = 0; i < num; i++ ) {
			touch = clipModelList[i];

			if ( !touch ) {
				continue;
			}

			if ( touch->renderModelHandle != -1 ) {
				idClip::numRenderModelTraces++;
				TraceRenderModel( trace, start, end, radius, trmAxis, touch );
			} else {
				idClip::numTranslations++;
				collisionModelManager->Translation( &trace, start, end, trm, trmAxis, contentMask,
										touch->Handle(), touch->origin, touch->axis );
			}

			if ( trace.fraction < translationalTrace.fraction ) {
				translationalTrace = trace;
				translationalTrace.c.entityNum = touch->entity->entityNumber;
				translationalTrace.c.id = touch->id;
				if ( translationalTrace.fraction == 0.0f ) {
					break;
				}
			}
		}
	} else {
		num = -1;
	}

	endPosition = translationalTrace.endpos;
	endRotation = rotation;
	endRotation.SetOrigin( endPosition );

	if ( !passEntity || passEntity->entityNumber != ENTITYNUM_WORLD ) {
		// rotational collision with world
		idClip::numRotations++;
		collisionModelManager->Rotation( &rotationalTrace, endPosition, endRotation, trm, trmAxis, contentMask, 0, vec3_origin, mat3_default );
		rotationalTrace.c.entityNum = rotationalTrace.fraction != 1.0f ? ENTITYNUM_WORLD : ENTITYNUM_NONE;
	} else {
		memset( &rotationalTrace, 0, sizeof( rotationalTrace ) );
		rotationalTrace.fraction = 1.0f;
		rotationalTrace.endpos = endPosition;
		rotationalTrace.endAxis = trmAxis * rotation.ToMat3();
	}

	if ( rotationalTrace.fraction != 0.0f ) {

		if ( num == -1 ) {
			traceBounds.FromBoundsRotation( trm->bounds, endPosition, trmAxis, endRotation );
			num = GetTraceClipModels( traceBounds, contentMask, passEntity, clipModelList );
		}

		for ( i = 0; i < num; i++ ) {
			touch = clipModelList[i];

			if ( !touch ) {
				continue;
			}

			// no rotational collision detection with render models
			if ( touch->renderModelHandle != -1 ) {
				continue;
			}

			idClip::numRotations++;
			collisionModelManager->Rotation( &trace, endPosition, endRotation, trm, trmAxis, contentMask,
								touch->Handle(), touch->origin, touch->axis );

			if ( trace.fraction < rotationalTrace.fraction ) {
				rotationalTrace = trace;
				rotationalTrace.c.entityNum = touch->entity->entityNumber;
				rotationalTrace.c.id = touch->id;
				if ( rotationalTrace.fraction == 0.0f ) {
					break;
				}
			}
		}
	}

	if ( rotationalTrace.fraction < 1.0f ) {
		results = rotationalTrace;
	} else {
		results = translationalTrace;
		results.endAxis = rotationalTrace.endAxis;
	}

	results.fraction = Max( translationalTrace.fraction, rotationalTrace.fraction );

	return ( translationalTrace.fraction < 1.0f || rotationalTrace.fraction < 1.0f );
}
Пример #10
0
Rotation operator-(const Rotation& lhs, const Rotation& rhs) {
	return Rotation(static_cast<Rotation>((static_cast<int64_t>(lhs) - static_cast<int64_t>(rhs) + c::nRotations) % c::nRotations));
}
Пример #11
0
void
FontDemoView::_DrawView(BView* view)
{
	if (!view)
		return;

	view->SetDrawingMode(B_OP_COPY);


	BRect rect = view->Bounds();
	view->SetHighColor(255, 255, 255);
	view->FillRect(rect);

	if (!fString)
		return;

	view->SetFont(&fFont, B_FONT_ALL);

	const size_t size = strlen(fString);
	BRect boundBoxes[size];

	if (OutLineLevel())
		fFont.GetGlyphShapes(fString, size, fShapes);
	else
		fFont.GetBoundingBoxesAsGlyphs(fString, size, B_SCREEN_METRIC, boundBoxes);

	float escapementArray[size];
	//struct escapement_delta escapeDeltas[size];
	struct edge_info edgeInfo[size];
/*
	for (size_t j = 0; j < size; j++) {
		escapeDeltas[j].nonspace = 0.0f;
		escapeDeltas[j].space = 0.0f;
	}
*/
	fFont.GetEdges(fString, size, edgeInfo);
	fFont.GetEscapements(fString, size, /*escapeDeltas,*/ escapementArray);

	font_height fh;
	fFont.GetHeight(&fh);

	float xCoordArray[size];
	float yCoordArray[size];

	float yCoord = (rect.Height() + fh.ascent - fh.descent) / 2;
	float xCoord = -rect.Width() / 2;
	const float xCenter = xCoord * -1;
	const float r = Rotation() * (M_PI / 180.0);
	const float cosinus = cos(r);
	const float sinus = -sin(r);

	// When the bounding boxes workes properly we will invalidate only the
	// region area instead of the whole view.

	fBoxRegion.MakeEmpty();

	for (size_t i = 0; i < size; i++) {
		xCoordArray[i] = 0.0f;
		yCoordArray[i] = 0.0f;

		yCoordArray[i] = sinus * (xCoord - xCoordArray[i]);
		xCoordArray[i] = cosinus * xCoord;

		xCoordArray[i] += xCenter;
		yCoordArray[i] += yCoord;

		boundBoxes[i].OffsetBy(xCoordArray[i], yCoordArray[i]);

		if (OutLineLevel()) {
			view->MovePenTo(xCoordArray[i], yCoordArray[i]);
			view->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
			view->FillShape(fShapes[i]);
			view->SetPenSize(OutLineLevel());
			view->SetHighColor(0, 0, 0);
			view->StrokeShape(fShapes[i]);
		} else {
			view->SetHighColor(0, 0, 0);
			view->SetDrawingMode(fDrawingMode);
			view->DrawChar(fString[i], BPoint(xCoordArray[i], yCoordArray[i]));
		}

		if (BoundingBoxes() && !OutLineLevel()) {
			if (i % 2)
				view->SetHighColor(0, 255, 0);
			else
				view->SetHighColor(255, 0, 0);
			view->SetDrawingMode(B_OP_COPY);
			view->StrokeRect(boundBoxes[i]);
		}

		// add the bounding to the region.
		fBoxRegion.Include(boundBoxes[i]);

		xCoord += (escapementArray[i] /*+ escapeDeltas[i].nonspace + escapeDeltas[i].space*/)
			* FontSize() + Spacing();
		//printf("xCoord %f\n", xCoord);
	}
}
Пример #12
0
// ----------------------------------------------------------------------------
Rotation Rotation::inv()
{
    return Rotation(a,-b,-c,-d);
}
Пример #13
0
mat3x3 S(const vec3& axis)
{
    return Rotation(axis, 360.0/n)*Reflection(axis);
}
Пример #14
0
mat3x3 C(const vec3& axis)
{
    return Rotation(axis, 360.0/n);
}
Пример #15
0
// Create Objects
void TestScene::SetupObjects()
{    
    spObject sun(new Object);
    sun->SetVO(MakeShareable(new PrimitiveUVSphere(256, 128)));
    sun->GetTransform().SetScale(Vector3(2.f, 2.f, 2.f));
    Texture sunTexture;
    LoadTexture(sunTexture, "textures/texture_sun.png");
    sun->GetVO()->GetTexture() = sunTexture;
    sun->SetGLMode(GL_TRIANGLES);
    sun->EnableTexture();
    sun->SetName(L"Sun");
    objects.push_back(sun);
    objectMap.insert(std::make_pair(sun->GetName(), sun));

    spObject world(new Object);
    world->SetVO(MakeShareable(new PrimitiveUVSphere(256, 128)));
    world->GetTransform().SetPosition(Vector3(5.f, 0.f, 0.f));
    Texture worldTexture;
    LoadTexture(worldTexture, "textures/4kworld.png");
    world->GetVO()->GetTexture() = worldTexture;
    world->SetGLMode(GL_TRIANGLES);
    world->EnableTexture();
    world->SetName(L"Earth");
    world->SetParent(sun.Get(), TransformInheritance(true, false, true, false));
    objects.push_back(world);
    objectMap.insert(std::make_pair(world->GetName(), world));


    spObject clouds(new Object);
    clouds->SetVO(MakeShareable(new PrimitiveUVSphere(256, 128)));
    clouds->GetTransform().SetScale(Vector3(1.01f, 1.01f, 1.01f));
    Texture cloudTexture;
    LoadTexture(cloudTexture, "textures/clouds.png");
    clouds->GetVO()->GetTexture() = cloudTexture;
    clouds->SetGLMode(GL_TRIANGLES);
    clouds->EnableTexture();
    clouds->EnableTransparency();
    clouds->SetName(L"Clouds");
    clouds->SetParent(world.Get(), TransformInheritance(true, false, true, false));
    objects.push_back(clouds);
    objectMap.insert(std::make_pair(clouds->GetName(), clouds));

    //spObject disc(new Object);
    //disc->SetVO(new PrimitiveDisc(64));
    //Texture discTexture;
    //LoadTexture(discTexture, "crate.png");
    //disc->GetVO()->GetTexture() = discTexture;
    //disc->SetGLMode(GL_TRIANGLE_FAN);
    //disc->GetTransform().SetPosition(Vector3(2.5f, 0.0f, 0.0f));
    //disc->EnableTexture();
    //disc->SetName(L"Disc");
    //objects.push_back(disc);

    spObject moon(new Object);
    moon->SetVO(MakeShareable(new PrimitiveUVSphere(256, 128)));
    moon->GetTransform().SetScale(Vector3(0.27f, 0.27f, 0.27f));
    moon->GetTransform().SetPosition(Vector3(0.f, 0.f, -2.2f));
    Texture moonTexture;
    LoadTexture(moonTexture, "textures/moonmap1k.png");
    moon->GetVO()->GetTexture() = moonTexture;
    moon->SetGLMode(GL_TRIANGLES);
    moon->EnableTexture();
    moon->SetName(L"Moon");
    moon->SetParent(world.Get(), TransformInheritance(true, false, true, false));
    objects.push_back(moon);
    objectMap.insert(std::make_pair(moon->GetName(), moon));

    spObject hst(new Object);
    hst->SetVO(MakeShareable(new Model));
    static_cast<Model*>(hst->GetVO().Get())->Load("models/hst.obj", "textures/hst.png");
    hst->GetTransform().SetScale(Vector3(0.0001f, 0.0001f, 0.0001f)); // This thing is yuge!
    hst->GetTransform().SetPosition(Vector3(-1.1f, 0.f, 0.f));
    hst->GetTransform().SetPreRotation(Rotation(0.f, Vector3(0.25f, 0.25f, -0.25f)));
    hst->GetTransform().SetRotation(Rotation(0.f, Vector3(-0.2f, 0.8f, -0.2f)));
    hst->SetGLMode(GL_TRIANGLES);
    hst->SetName(L"HST");
    hst->EnableTexture();
    hst->SetParent(world.Get(), TransformInheritance(true, false, true, false));
    objects.push_back(hst);
    objectMap.insert(std::make_pair(hst->GetName(), hst));

    spObject iss(new Object);
    iss->SetVO(MakeShareable(new Model));
    static_cast<Model*>(iss->GetVO().Get())->Load("models/iss.obj", "textures/iss.png");
    iss->GetTransform().SetScale(Vector3(0.01f, 0.01f, 0.01f));
    iss->GetTransform().SetPreRotation(Rotation(0.f, Vector3(0.f, 0.5f, 0.f)));
    iss->GetTransform().SetRotation(Rotation(0.f, Vector3(0.25f, 0.5f, 0.25f)));
    iss->GetTransform().SetPosition(Vector3(0.f, 0.f, 1.2f));
    iss->SetGLMode(GL_TRIANGLES);
    iss->SetName(L"ISS");
    iss->EnableTexture();
    iss->SetParent(world.Get(), TransformInheritance(true, false, true, false));
    objects.push_back(iss);
    objectMap.insert(std::make_pair(iss->GetName(), iss));

    spObject teapot(new Object);
    teapot->SetVO(MakeShareable(new Model));
    static_cast<Model*>(teapot->GetVO().Get())->Load("Models/teapot.obj", "textures/teapot.png");
    teapot->GetTransform().SetPosition(Vector3(5.f, 5.f, -3.f));
    teapot->GetTransform().SetPreRotation(Rotation(0.f, Vector3(1.f, 0.f, 0.f)));
    teapot->GetTransform().SetRotation(Rotation(0.f, Vector3(0.f, 0.f, 1.f)));
    teapot->GetTransform().SetScale(Vector3(0.05f, 0.05f, 0.05f));
    teapot->SetGLMode(GL_TRIANGLES);
    teapot->SetName(L"Teapot");
    teapot->EnableTexture();
    teapot->SetParent(iss.Get(), TransformInheritance(true, true, true, false));
    objects.push_back(teapot);
    objectMap.insert(std::make_pair(teapot->GetName(), teapot));
}
void FirstPersonLook::Update()
{
    Rotation();
}
GError GAnimTRSNode2D::SetFather(GAnimTRSNode2D *NewFather, const GBool AffectTracks) {

	GTimeInterval tmpValid;

	// if specified father is NULL, detach this node (it will become a root node)
	if (!NewFather) {
		if (AffectTracks) {
			// offset position track
			GPoint2 wPos = Position(0, G_WORLD_SPACE, tmpValid);
			GPoint2 lPos = Position(0, G_LOCAL_SPACE, tmpValid);
			OffsetPositionTrack(wPos - lPos);
			// offset rotation track
			GReal wRot = Rotation(0, G_WORLD_SPACE, tmpValid);
			GReal lRot = Rotation(0, G_LOCAL_SPACE, tmpValid);
			OffsetRotationTrack(wRot - lRot);
			// offset scale track
			GVector2 wScl = Scale(0, G_WORLD_SPACE, tmpValid);
			GVector2 lScl = Scale(0, G_LOCAL_SPACE, tmpValid);
			GVector2 tmpScale(wScl);
			if (GMath::Abs(lScl[G_X]) > G_EPSILON)
				tmpScale[G_X] /= lScl[G_X];
			if (GMath::Abs(lScl[G_Y]) > G_EPSILON)
				tmpScale[G_Y] /= lScl[G_Y];
			OffsetScaleTrack(tmpScale);
		}
		// detach me from my current father (if it exists)
		if (gFather)
			gFather->DetachChildNode(this);
	}
	else {
		if (AffectTracks) {
			// offset position track
			GPoint2 wPos = Position(0, G_WORLD_SPACE, tmpValid);
			GPoint2 lPos = Position(0, G_LOCAL_SPACE, tmpValid);
			GPoint2 fwPos = NewFather->Position(0, G_WORLD_SPACE, tmpValid);
			OffsetPositionTrack(fwPos - wPos - lPos);
			// offset rotation track
			GReal wRot = Rotation(0, G_WORLD_SPACE, tmpValid);
			GReal lRot = Rotation(0, G_LOCAL_SPACE, tmpValid);
			GReal fwRot = NewFather->Rotation(0, G_WORLD_SPACE, tmpValid);
			OffsetRotationTrack(fwRot - wRot - lRot);
			// offset scale track
			GVector2 wScl = Scale(0, G_WORLD_SPACE, tmpValid);
			GVector2 lScl = Scale(0, G_LOCAL_SPACE, tmpValid);
			GPoint2 fwScl = NewFather->Scale(0, G_WORLD_SPACE, tmpValid);
			GVector2 tmpScale(fwScl);
			GVector2 tmpDen(wScl[G_X] * lScl[G_X], wScl[G_Y] * lScl[G_Y]);
			if (GMath::Abs(tmpDen[G_X]) > G_EPSILON)
				tmpScale[G_X] /= tmpDen[G_X];
			else
				tmpScale[G_X] = 1;

			if (GMath::Abs(tmpDen[G_Y]) > G_EPSILON)
				tmpScale[G_Y] /= tmpDen[G_Y];
			else
				tmpScale[G_Y] = 1;
			OffsetScaleTrack(tmpScale);
		}
		// detach me from my current father (if it exists)
		if (gFather)
			gFather->DetachChildNode(this);
		// attach me to the new father
		NewFather->AttachChildNode(this);
	}
	return G_NO_ERROR;
}
Пример #18
0
		//	if (*t >= -0.0001 && *t <= 1.0001)
			{
				return true;
			}
		}
	}

	return false;
}

namespace x3d
{

IMP_X3DFIELD0(Transform, SFVec3f, center, inputOutput)
IMP_X3DFIELD1(Transform, SFRotation, rotation, inputOutput, Rotation(Vec3f(0.0f, 0.0f, 1.0f), 0.0f))
IMP_X3DFIELD1(Transform, SFVec3f, scale, inputOutput, Vec3f(1.0f, 1.0f, 1.0f))
IMP_X3DFIELD1(Transform, SFRotation, scaleOrientation, inputOutput, Rotation(Vec3f(0.0f, 0.0f, 1.0f), 0.0f))
IMP_X3DFIELD0(Transform, SFVec3f, translation, inputOutput)

NodeType* Transform::GetNodeType()
{
	static X3DFieldDefinition* fields[] =
	{
		/*
		X3DFieldDefinition(WSTR("addChildren"), FieldType_MFNode, SAIFieldAccess_inputOnly,-1),
		X3DFieldDefinition(WSTR("removeChildren"), FieldType_MFNode, SAIFieldAccess_inputOnly,-1),
		X3DFieldDefinition(WSTR("bboxCenter"), FieldType_SFVec3f, SAIFieldAccess_initializeOnly,-1),
		X3DFieldDefinition(WSTR("bboxSize"), FieldType_SFVec3f, SAIFieldAccess_initializeOnly,-1),
		*/
		get_centerFieldDef(),
Пример #19
0
Rotation Rotation::operator+(Rotation const& rot) const
{
	Matrix mult = rot.matrix.mult(matrix);
	return Rotation(mult);
}
Пример #20
0
/**
 * Begin tracking at the specified location for the specified viewport.
 */
void FMouseDeltaTracker::StartTracking(FEditorViewportClient* InViewportClient, const int32 InX, const int32 InY, const FInputEventState& InInputState, bool bNudge, bool bResetDragToolState)
{
	DetermineCurrentAxis(InViewportClient);

	// Initialize widget axis (in case it hasn't been set by the hovered hit proxy)

	if (InViewportClient->Widget && InViewportClient->GetCurrentWidgetAxis() == EAxisList::None)
	{
		check(InViewportClient->Viewport);
		HHitProxy* HitProxy = InViewportClient->Viewport->GetHitProxy(InX, InY);
		if (HitProxy && HitProxy->IsA(HWidgetAxis::StaticGetType()))
		{
			EAxisList::Type ProxyAxis = ((HWidgetAxis*)HitProxy)->Axis;
			InViewportClient->SetCurrentWidgetAxis(ProxyAxis);
		}
	}

	const bool AltDown = InViewportClient->IsAltPressed();
	const bool ShiftDown = InViewportClient->IsShiftPressed();
	const bool ControlDown = InViewportClient->IsCtrlPressed();
	const bool LeftMouseButtonDown = InViewportClient->Viewport->KeyState(EKeys::LeftMouseButton);
	const bool RightMouseButtonDown = InViewportClient->Viewport->KeyState(EKeys::RightMouseButton);
	const bool MiddleMouseButtonDown = InViewportClient->Viewport->KeyState(EKeys::MiddleMouseButton);

	bool bIsDragging = ((ControlDown || ShiftDown) && (LeftMouseButtonDown || RightMouseButtonDown || MiddleMouseButtonDown)) ||
		(InViewportClient->GetCurrentWidgetAxis() != EAxisList::None) || bNudge;

	// Update bWidgetAxisControlledByDrag since we now know that we have begun dragging an object with the mouse.
	if ( bIsDragging )
	{
		InViewportClient->bWidgetAxisControlledByDrag = true;
	}

	InViewportClient->TrackingStarted( InInputState, bIsDragging, bNudge );

	if (InViewportClient->Widget)
	{
		InViewportClient->Widget->SetDragStartPosition(FVector2D(InX, InY));
		InViewportClient->Widget->SetDragging(bIsDragging);
		if (InViewportClient->GetWidgetMode() == FWidget::WM_Rotate)
		{
			InViewportClient->Invalidate();
		}
	}

	// Clear bool that tracks whether AddDelta has been called
	bHasReceivedAddDelta = false;

	if( bResetDragToolState )
	{
		bHasAttemptedDragTool = false;
	}


	ensure( !DragTool.IsValid() );

	StartSnapped = Start = StartScreen = FVector( InX, InY, 0 );
	RawDelta = FVector::ZeroVector;
	TrackingWidgetMode = InViewportClient->GetWidgetMode();

	// No drag tool is active, so handle snapping.
	switch( TrackingWidgetMode )
	{
		case FWidget::WM_Translate:
			FSnappingUtils::SnapPointToGrid( StartSnapped, FVector(GEditor->GetGridSize(),GEditor->GetGridSize(),GEditor->GetGridSize()) );
			break;

		case FWidget::WM_Scale:
			FSnappingUtils::SnapScale( StartSnapped, FVector(GEditor->GetGridSize(),GEditor->GetGridSize(),GEditor->GetGridSize()) );
			break;

		case FWidget::WM_Rotate:
		{
			FRotator Rotation( StartSnapped.X, StartSnapped.Y, StartSnapped.Z );
			FSnappingUtils::SnapRotatorToGrid( Rotation );
			StartSnapped = FVector( Rotation.Pitch, Rotation.Yaw, Rotation.Roll );
		}
		break;
		case FWidget::WM_TranslateRotateZ:
		case FWidget::WM_2D:
			FSnappingUtils::SnapPointToGrid( StartSnapped, FVector(GEditor->GetGridSize(),GEditor->GetGridSize(),GEditor->GetGridSize()) );
			break;

		default:
			break;
	}

	// Clear any snapping helpers on new movement
	const bool bClearImmediatley = true;
	FSnappingUtils::ClearSnappingHelpers( bClearImmediatley );

	End = EndScreen = Start;
	EndSnapped = StartSnapped;

	bExternalMovement = false;	//no external movement has occurred yet.
	InViewportClient->Widget->ResetDeltaRotation();

}