Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Camera Settings tab and features #91

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
404 changes: 404 additions & 0 deletions BrawlCrate/UI/SettingsDialog.cs

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion BrawlLib/Internal/Windows/Controls/Model Panel/ModelPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,16 @@ public void SetCamWithBox(Vector3 min, Vector3 max)

cam.Reset();

cam.Translate(frontMidPt._x, frontMidPt._y, Maths.Max(distX, distY, max._z) + 2.0f);
cam.Translate(frontMidPt._x, frontMidPt._y, 0);
if (CurrentViewport.GetProjectionType() == ViewportProjection.Orthographic)
{
cam.Translate(0, 0, Maths.Max(distX, distY, max._z) + 2.0f);
cam.Zoom(Maths.Max(distX, distY, max._z) / (Maths.Max(Size.Height, Size.Width) * 0.01f));
}
else if (CurrentViewport.GetProjectionType() == ViewportProjection.Perspective)
{
CurrentViewport.Zoom(Maths.Max(distX, distY, max._z) + 2.0f, true);
}

Invalidate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public ModelPanelViewportInfo GetInfo()
_spotExponent = _spotExponent,
_transFactor = _transFactor,
_type = _type,
_viewDistance = _viewDistance,
//_viewDistance = _viewDistance,
_zoomFactor = _zoomFactor,
_allowSelection = _allowSelection,
_showCamCoords = _showCamCoords,
Expand All @@ -73,7 +73,7 @@ public ModelPanelViewportInfo GetInfo()
public float _rotFactor = 0.4f;
public float _transFactor = 0.05f;
public float _zoomFactor = 2.5f;
public float _viewDistance = 5.0f;
public float _viewDistance = 0f;
public float _spotCutoff = 180.0f;
public float _spotExponent = 100.0f;

Expand Down Expand Up @@ -818,6 +818,23 @@ public void RecalcLight()

#endregion

#region Mouse/Keyboard Enumerations
public enum CameraControlMode
{
Flycam,
Turntable
}

public enum CameraDragAction
{
Rotate = 0,
Pan,
Zoom,
Roll
}

#endregion

#region Mouse/Keyboard Functions

private Point? lastHeldMouseLocat = null;
Expand Down Expand Up @@ -964,7 +981,18 @@ public void HandleMouseMove(TKContext ctx, MouseEventArgs e)
bool shift = (mod & Keys.Shift) != 0;
bool alt = (mod & Keys.Alt) != 0;

if (ViewType != ViewportProjection.Perspective && !ctrl)
CameraDragAction action;
if (_scrolling)
action = Properties.Settings.Default.CameraMiddleMouse;
else if (ctrl)
if (alt)
action = Properties.Settings.Default.CameraCtrlAltRMB;
else
action = Properties.Settings.Default.CameraCtrlRMB;
else
action = Properties.Settings.Default.CameraRightMouse;

if (ViewType != ViewportProjection.Perspective && action != CameraDragAction.Roll && action != CameraDragAction.Rotate)
{
xDiff *= 20;
yDiff *= 20;
Expand All @@ -976,24 +1004,29 @@ public void HandleMouseMove(TKContext ctx, MouseEventArgs e)
yDiff *= 16;
}

if (_scrolling)
{
Translate(0, 0, -yDiff * 0.01f);
}
else if (ctrl)
switch (action)
{
if (alt)
{
Rotate(0, 0, -yDiff * RotationScale);
}
else
{
case CameraDragAction.Zoom:
Translate(0, 0, -yDiff * 0.01f);
break;
case CameraDragAction.Pan:
if (Properties.Settings.Default.CameraPanInvertX)
xDiff *= -1;
if (Properties.Settings.Default.CameraPanInvertY)
yDiff *= -1;
Translate(-xDiff * TranslationScale, -yDiff * TranslationScale, 0.0f);
break;
case CameraDragAction.Rotate:
if (Properties.Settings.Default.CameraRotateInvertX)
xDiff *= -1;
if (Properties.Settings.Default.CameraRotateInvertY)
yDiff *= -1;
Pivot(yDiff * RotationScale, -xDiff * RotationScale);
}
}
else
{
Translate(-xDiff * TranslationScale, -yDiff * TranslationScale, 0.0f);
break;
case CameraDragAction.Roll:
Rotate(0, 0, -yDiff * RotationScale);
break;

}
}
}
Expand Down Expand Up @@ -1145,6 +1178,7 @@ public void Zoom(float amt, bool invoked = false)
{
_scrolling = true;
Camera.Zoom(amt);
_viewDistance += amt;
_scrolling = false;

if (!invoked)
Expand Down Expand Up @@ -1192,7 +1226,14 @@ public void Pivot(float x, float y)
x *= _multiplier;
y *= _multiplier;

Camera.Pivot(_viewDistance, x, y);
if (Properties.Settings.Default.CameraControlMode == CameraControlMode.Flycam)
{
Camera.Pivot(0, x, y);
}
else
{
Camera.Pivot(_viewDistance, x, y);
}

if (Pivoted != null)
{
Expand Down Expand Up @@ -1235,6 +1276,18 @@ public Vector3 ProjectCameraSphere(Vector2 mousePoint, Vector3 center, float rad
out xy, out yz, out xz);
}

public override void ResetCamera()
{
_viewDistance = 0;
base.ResetCamera();
}

public override void SetProjectionType(ViewportProjection type)
{
_viewDistance = 0;
base.SetProjectionType(type);
}

#endregion

#region Default Viewports
Expand Down Expand Up @@ -1415,7 +1468,7 @@ public void GetObjectData(SerializationInfo info, StreamingContext context)
public float _rotFactor = 0.4f;
public float _transFactor = 0.05f;
public float _zoomFactor = 2.5f;
public float _viewDistance = 5.0f;
public float _viewDistance = 0.0f;
public float _spotCutoff = 180.0f;
public float _spotExponent = 100.0f;
private const float v = 1.0f / 255.0f;
Expand Down Expand Up @@ -1472,7 +1525,7 @@ public ModelPanelViewport AsViewport()
v._spotCutoff = _spotCutoff;
v._spotExponent = _spotExponent;
v._transFactor = _transFactor;
v._viewDistance = _viewDistance;
//v._viewDistance = _viewDistance;
v._zoomFactor = _zoomFactor;
v._lightEnabled = _lightEnabled;
v._renderSCN0Controls = _renderSCN0Controls;
Expand Down
4 changes: 2 additions & 2 deletions BrawlLib/OpenGL/GLViewport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ internal void SetPercentageIndex(int p, float v, bool resize = true)
}
}

public void ResetCamera()
public virtual void ResetCamera()
{
_camera.Reset();
}
Expand Down Expand Up @@ -203,7 +203,7 @@ public ViewportProjection GetProjectionType()
return Camera.Orthographic ? ViewportProjection.Orthographic : ViewportProjection.Perspective;
}

public void SetProjectionType(ViewportProjection type)
public virtual void SetProjectionType(ViewportProjection type)
{
bool diff = type == ViewportProjection.Orthographic && _type != ViewportProjection.Perspective;

Expand Down
125 changes: 124 additions & 1 deletion BrawlLib/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 28 additions & 1 deletion BrawlLib/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Setting Name="SaveGCTWithInfo" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="ColladaImportOptions" Type="BrawlLib.Modeling.Collada.ImportOptions" Scope="User">
<Setting Name="ColladaImportOptions" Type="BrawlLib.Modeling.Collada.Collada.ImportOptions" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="CompatibilityMode" Type="System.Boolean" Scope="User">
Expand Down Expand Up @@ -47,5 +47,32 @@
<Setting Name="ParseMoveDef" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="CameraControlMode" Type="BrawlLib.Internal.Windows.Controls.Model_Panel.ModelPanelViewport.CameraControlMode" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="CameraRightMouse" Type="BrawlLib.Internal.Windows.Controls.Model_Panel.ModelPanelViewport.CameraDragAction" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="CameraMiddleMouse" Type="BrawlLib.Internal.Windows.Controls.Model_Panel.ModelPanelViewport.CameraDragAction" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="CameraCtrlRMB" Type="BrawlLib.Internal.Windows.Controls.Model_Panel.ModelPanelViewport.CameraDragAction" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="CameraCtrlAltRMB" Type="BrawlLib.Internal.Windows.Controls.Model_Panel.ModelPanelViewport.CameraDragAction" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="CameraPanInvertX" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="CameraPanInvertY" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="CameraRotateInvertX" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="CameraRotateInvertY" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>