oliver schmahl
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Assignment 3 - Starting on your app (graded) **Date**: 20/02/2022 **Group members participating**: Jakob Overgaard (201706812), Oilver Rask Schmahl (201805260), Tobias Fabrin Gade (201809466) **Activity duration**: ## Goal ## Plan ## Results **Exercise 1.1** After exercise 1.1 our application is very basic. It features a Marker that is permanetly AR Raycasted onto the AR Trackable Planes: <p align="center"> <img src="https://i.imgur.com/y2YGdrC.jpg" alt="drawing" width="200"/> </p> Code for displaying the Marker located in the Marker Script: ```C# private void Update() { List<ARRaycastHit> hits = new List<ARRaycastHit>(); raycastManager.Raycast(Camera.main.ViewportToScreenPoint(new Vector2(0.5f, 0.5f)), hits, TrackableType.Planes); if (hits.Count <= 0) return; var transformMarker = transform; transformMarker.position = hits[0].pose.position; transformMarker.rotation = hits[0].pose.rotation; } ``` A UI Button section at the bottom, with a button for placeing an object on the markers current location and a button for deleting all objects placed. <p align="center"> <img src="https://i.imgur.com/yLB1T42.jpg" alt="drawing" width="200"/> </p> The buttons work simply by calling the two public methods SpawnObject() and RemoveObjects() inside the Object Adder Script. Their code looks like this: ```C# public void SpawnObject() { Transform markerTransform = marker.transform; Instantiate( objectToSpawn, markerTransform.position, markerTransform.rotation, objectsHolder.transform); } ``` and ```C# public void RemoveObjects() { foreach (Transform child in objectsHolder.transform) { GameObject.Destroy(child.gameObject); } } ``` **Exercise 2.1** With exercise 2.1 we added the functionality to select objects placed within the world. This is done through a new Object Manipulator Script, which will be responsible for manipulation of objects. The code for selecting an object uses Raycast to find objects that the user clicks on. When an object is selected it stores the object's transform inside *_selectedGameObject*. Aditionally, for visualizing the selection to the user, we have chosen to use the outline package, which allows us to add an outline to objects using shaders through the outline component. The code for this can be seen below *(without the update() function and touch detection shown, as it has been covered in previous assignments)*: ```C# Ray ray = _mainCamera.ScreenPointToRay(touch.position); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { if (_selectedGameObject != null) { Destroy(_selectedGameObject.gameObject.GetComponent<Outline>()); } _selectedGameObject = hit.transform; Outline outline = _selectedGameObject.gameObject.AddComponent<Outline>(); outline.OutlineMode = Outline.Mode.OutlineAll; outline.OutlineColor = Color.white; outline.OutlineWidth = 10f; } else { Destroy(_selectedGameObject.gameObject.GetComponent<Outline>()); _selectedGameObject = null; } ``` The result can be seen in the image below: | None Selected | Cube Selected | |:-------------:|:-------------:| | ![](https://i.imgur.com/XNUx1t5.jpg) | ![](https://i.imgur.com/tW28dtv.jpg) | **Bonus:** we decided to create a object menu in the top left cornor of the screen, for this exercise it only shows the name (disregard the button for now). This name is updated with the addition of the code seen below inside the update() function: ```C# if (_selectedGameObject == null) { selectedText.text = "None"; } else { selectedText.text = _selectedGameObject.name; } ``` **Exercise 2.2** For exercise 2.2 we added a new button to the object toolbar that appears when an object is selected. This was done by simply adding the new UI button element to a parent gameObject in the canvas, which we in the *ObjectManipulatorScript* toggle on and off when objects are selected and deselected. When the button is clicked, we call the DeleteObject() method inside the *ObjectManipulatorScript* which simply destroys the selected object. The code can be seen below: Toggle: ```C# if (_selectedGameObject == null) { selectedText.text = "None"; manipulatorUI.SetActive(false); } else { selectedText.text = _selectedGameObject.name; manipulatorUI.SetActive(true); } ``` DeleteObject(): ```C# public void DeleteObject() { Destroy(_selectedGameObject.gameObject); } ``` Button: | Object Tree | Delete Button | |:-------------:|:-------------:| | ![](https://i.imgur.com/Jh8LG7A.png) | ![](https://i.imgur.com/fJbvXP4.png) | **Exercise 3.1** For exercise 3.1 we implemented movement for the objects. The movement is implemented using the phase.moved property under touch.phase, which then, when a game object is selected, casts an AR Raycast each time the finger moves and moves the object to that location if the ray hits the trackable planes. The code for this can be seen below along with a gif showing the movement in the app. ```C# if (_selectedGameObject == null) return; if (touch.phase == TouchPhase.Moved) { List<ARRaycastHit> hits = new List<ARRaycastHit>(); arRaycastManager.Raycast(touch.position, hits, TrackableType.PlaneWithinPolygon); if (hits.Count <= 0) return; _selectedGameObject.position = hits[0].pose.position; _selectedGameObject.rotation = hits[0].pose.rotation; } ``` ## insert gif!! **Exercise 3.2** For exercise 3.2 we implemented rotation of the object. This was done by checking when two touches are registered on the screen and an object is selected; Then calculating the angle between the line going through the two touch points and the line going through the previous two touch points. We calculate the signed angle between these two lines using Unity's build-in function Vector2.SignedAngle(). The math is illustrated in the image below: The code for the rotation can be seen below: *Note: we have multiplied by a constant (2), because the rotation seemed just a bit too slow.* ```C# if (Input.touchCount == 2 && _selectedGameObject != null) { Touch touch1 = Input.GetTouch(0); Touch touch2 = Input.GetTouch(1); float angle = Vector2.SignedAngle(touch2.position - touch1.position, touch2.deltaPosition - touch1.deltaPosition); _selectedGameObject.Rotate(0, -angle * 2 * Time.deltaTime, 0); } ``` Additionally, we need to also change the old movement code, to not update the objects y-rotation on movement - as it seems to not make sense that the objects rotation is reset if moved: ```C# if (touch.phase == TouchPhase.Moved) { List<ARRaycastHit> hits = new List<ARRaycastHit>(); arRaycastManager.Raycast(touch.position, hits, TrackableType.PlaneWithinPolygon); if (hits.Count <= 0) return; _selectedGameObject.position = hits[0].pose.position; var rotation = _selectedGameObject.rotation; rotation = new Quaternion(hits[0].pose.rotation.x, rotation.y, hits[0].pose.rotation.z, rotation.w); _selectedGameObject.rotation = rotation; } } ``` A gif of how the rotation looks in app can be seen below:

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully