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

Feature/mousepaint #2

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions Assembly-CSharp-vs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Assets\scripts\MouseFollowBehaviour.cs" />
<Compile Include="Assets\scripts\MousePaintBehaviour.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
1 change: 1 addition & 0 deletions Assembly-CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Assets\scripts\MouseFollowBehaviour.cs" />
<Compile Include="Assets\scripts\MousePaintBehaviour.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
Binary file modified Assembly-CSharp.pidb
Binary file not shown.
Binary file added Assets/Prefabs/Cube.prefab
Binary file not shown.
Binary file added Assets/Prefabs/Plane.prefab
Binary file not shown.
Binary file added Assets/Prefabs/Sphere.prefab
Binary file not shown.
Binary file added Assets/scenes/MousePaint.unity
Binary file not shown.
7 changes: 4 additions & 3 deletions Assets/scripts/MouseFollowBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@

public class MouseFollowBehaviour : MonoBehaviour {

#region Fields
public Vector3 mousePosition;
private Plane plane;
private Ray ray;
private float raycast;
private Vector3 translationPoint;
#endregion


// Use this for initialization
void Awake () {

void Awake () {
}

// Update is called once per frame
Expand All @@ -22,7 +23,7 @@ void Update () {
//When the mouse drags, change the object's screen position accordingly.
private void OnMouseDrag()
{
plane = new Plane((Camera.mainCamera.transform.forward).normalized, this.transform.position);
plane = new Plane((Camera.mainCamera.transform.forward).normalized, gameObject.transform.position);
mousePosition = Input.mousePosition;
ray = Camera.mainCamera.ScreenPointToRay(mousePosition);
plane.Raycast(ray, out raycast);
Expand Down
63 changes: 63 additions & 0 deletions Assets/scripts/MousePaintBehaviour.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using UnityEngine;
using System.Collections;

public class MousePaintBehaviour : MonoBehaviour {

#region Fields
public GameObject Prefab;
private Plane plane;
private Ray ray;
private float raycast;
private float distance;
private Vector3 currentMousePosition;
private Vector3 newPosition;
private Vector3 oldPrefabPosition;
private bool first = true;
#endregion

// Use this for initialization
void Awake() {
#region take this plane to place Prefab always othogonal to camera
// plane = new Plane((Camera.mainCamera.transform.forward).normalized, new Vector3(0,0,0));
#endregion

#region take this plane to place Prefab always on x-z-plane
plane = new Plane(Vector3.up.normalized, new Vector3(0,0,0));
#endregion
}

// Update is called once per frame
void Update () {
if (Input.GetMouseButton(0)) {
PaintPrefab();
}
else{
first = true;
}
}

private void PaintPrefab(){
currentMousePosition = Input.mousePosition;
ConvertScreenPointToRay();
distance = Vector3.Distance(newPosition,oldPrefabPosition);
if (first) {
Instantiate(Prefab,newPosition,Quaternion.identity);
oldPrefabPosition = newPosition;
first = false;
}
if (distance > Prefab.renderer.bounds.extents.magnitude) {
float step = 1F/(distance);
for(float i = 0; i <=1; i+=step){
Vector3 tmp = oldPrefabPosition + (oldPrefabPosition-newPosition)*i;
Instantiate(Prefab,tmp,Quaternion.identity);
}
oldPrefabPosition = newPosition;
}
}

private void ConvertScreenPointToRay(){
ray = Camera.mainCamera.ScreenPointToRay(currentMousePosition);
plane.Raycast(ray, out raycast);
newPosition = ray.GetPoint(raycast);
}
}
Binary file added Library/AssetVersioning.db
Binary file not shown.
Binary file modified Library/InspectorExpandedItems.asset
Binary file not shown.
Binary file modified Library/expandedItems
Binary file not shown.
Binary file modified Library/guidmapper
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 3 additions & 2 deletions unitymodules.userprefs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Properties>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
<MonoDevelop.Ide.Workbench ActiveDocument="Assets\scripts\MouseFollowBehaviour.cs">
<MonoDevelop.Ide.Workbench ActiveDocument="Assets\scripts\MousePaintBehaviour.cs">
<Files>
<File FileName="Assets\scripts\MouseFollowBehaviour.cs" Line="24" Column="55" />
<File FileName="Assets\scripts\MousePaintBehaviour.cs" Line="51" Column="12" />
<File FileName="Assets\scripts\MouseFollowBehaviour.cs" Line="25" Column="81" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>
Expand Down