Skip to content

Commit edd84d8

Browse files
committed
Fix for mouse issues
Will be put into other tutorials and blog pages soon
1 parent 3c5c610 commit edd84d8

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

OpenTKTutorial8-2/OpenTKTutorial8-2.sln

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11

2-
Microsoft Visual Studio Solution File, Format Version 11.00
3-
# Visual Studio 2010
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25420.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
46
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTKTutorial8-2", "OpenTKTutorial8-2\OpenTKTutorial8-2.csproj", "{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}"
57
EndProject
68
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{ACBF192E-C0F1-4B53-958F-915EDD01BA71}"
79
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|x64 = Debug|x64
1013
Debug|x86 = Debug|x86
14+
Release|x64 = Release|x64
1115
Release|x86 = Release|x86
1216
EndGlobalSection
1317
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}.Debug|x64.ActiveCfg = Debug|x86
1419
{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}.Debug|x86.ActiveCfg = Debug|x86
1520
{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}.Debug|x86.Build.0 = Debug|x86
21+
{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}.Release|x64.ActiveCfg = Release|x86
1622
{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}.Release|x86.ActiveCfg = Release|x86
1723
{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}.Release|x86.Build.0 = Release|x86
1824
EndGlobalSection

OpenTKTutorial8-2/OpenTKTutorial8-2/Game.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public Game()
4343
void initProgram()
4444
{
4545
lastMousePos = new Vector2(Mouse.X, Mouse.Y);
46+
CursorVisible = false;
4647

4748
GL.GenBuffers(1, out ibo_elements);
4849

@@ -73,6 +74,8 @@ void initProgram()
7374
// Move camera away from origin
7475
cam.Position += new Vector3(0f, 0f, 3f);
7576

77+
cam.MouseSensitivity = 0.0025f;
78+
7679
textures.Add("earth.png", loadImage("earth.png"));
7780
ObjVolume earth = ObjVolume.LoadFromFile("earth.obj");
7881
earth.TextureID = textures["earth.png"];
@@ -313,7 +316,7 @@ protected override void OnUpdateFrame(FrameEventArgs e)
313316
lastMousePos += delta;
314317

315318
cam.AddRotation(delta.X, delta.Y);
316-
ResetCursor();
319+
lastMousePos = new Vector2(OpenTK.Input.Mouse.GetState().X, OpenTK.Input.Mouse.GetState().Y);
317320
}
318321

319322
view = cam.GetViewMatrix();
@@ -351,22 +354,13 @@ protected override void OnKeyPress(KeyPressEventArgs e)
351354
}
352355
}
353356

354-
/// <summary>
355-
/// Moves the mouse cursor to the center of the screen
356-
/// </summary>
357-
void ResetCursor()
358-
{
359-
OpenTK.Input.Mouse.SetPosition(Bounds.Left + Bounds.Width / 2, Bounds.Top + Bounds.Height / 2);
360-
lastMousePos = new Vector2(OpenTK.Input.Mouse.GetState().X, OpenTK.Input.Mouse.GetState().Y);
361-
}
362-
363357
protected override void OnFocusedChanged(EventArgs e)
364358
{
365359
base.OnFocusedChanged(e);
366360

367361
if (Focused)
368362
{
369-
ResetCursor();
363+
lastMousePos = new Vector2(OpenTK.Input.Mouse.GetState().X, OpenTK.Input.Mouse.GetState().Y);
370364
}
371365
}
372366

OpenTKTutorial8-2/OpenTKTutorial8-2/OpenTKTutorial8-2.csproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,24 @@
3636
<PropertyGroup>
3737
<StartupObject>OpenTKTutorial8.Program</StartupObject>
3838
</PropertyGroup>
39+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
40+
<DebugSymbols>true</DebugSymbols>
41+
<OutputPath>bin\x64\Debug\</OutputPath>
42+
<DefineConstants>DEBUG;TRACE</DefineConstants>
43+
<DebugType>full</DebugType>
44+
<PlatformTarget>x64</PlatformTarget>
45+
<ErrorReport>prompt</ErrorReport>
46+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
49+
<OutputPath>bin\x64\Release\</OutputPath>
50+
<DefineConstants>TRACE</DefineConstants>
51+
<Optimize>true</Optimize>
52+
<DebugType>pdbonly</DebugType>
53+
<PlatformTarget>x64</PlatformTarget>
54+
<ErrorReport>prompt</ErrorReport>
55+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
56+
</PropertyGroup>
3957
<ItemGroup>
4058
<Reference Include="OpenTK, Version=2.0.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
4159
<HintPath>..\packages\OpenTK.2.0.0\lib\net20\OpenTK.dll</HintPath>

0 commit comments

Comments
 (0)