Documentation (ENG)
  • Setup Guide
  • Getting Started
    • Prerequisites
    • VPS Map Coverage
  • 3D Object
    • 3D Object Placement
  • Unity Scene
    • Unity Scene Components
  • Scene Manager
    • SceneManager Description
  • Samples
    • AR Navigation
    • Placement by Raycast
  • NReal
    • Nreal Support
  • API Reference
Powered by GitBook
On this page
Export as PDF
  1. Samples

Placement by Raycast

PreviousAR NavigationNextNreal Support

Last updated 3 years ago

Placement by Raycast

This is a sample of placing 3D objects on to the surface of buildings with the point of contact. Using mouse or touch panel, ray is casted that connects to camera's focal point, and thus calculate code based on transactional points with building mesh.

MaxstSceneManager.cs
public void AttachLogo()
{
    Vector2 vTouchPos = Input.mousePosition;

    Ray ray = Camera.main.ScreenPointToRay(vTouchPos);

    RaycastHit vHit;
    if (Physics.Raycast(ray.origin, ray.direction, out vHit))
    {
        maxstLogObject.transform.position = vHit.point;
        maxstLogObject.transform.rotation = Quaternion.FromToRotation(Vector3.forward, vHit.normal) * Quaternion.Euler(-90.0f ,0.0f, 0.0f);
    }
}
Example of Placement by Raycasting