52 lines
2.2 KiB
C#
52 lines
2.2 KiB
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using System;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class Clock : MonoBehaviour
|
||
|
{
|
||
|
public GameObject clockHand;
|
||
|
void Start()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
void Update()
|
||
|
{
|
||
|
var dateTimeNow = DateTime.Now;
|
||
|
//float swHour = 0.0f;
|
||
|
//float swMinute = 0.0f;
|
||
|
//float swSecond = 0.0f;
|
||
|
// Global Time:
|
||
|
float hour = dateTimeNow.Hour;
|
||
|
float minute = dateTimeNow.Minute;
|
||
|
float second = dateTimeNow.Second;
|
||
|
Debug.Log("asdd");
|
||
|
Debug.Log($"Time: {hour}:{minute}:{second}");
|
||
|
// Ustaw pozycje, rozmiar i obrót wskazówek zegara z wykorzystaniem przekształceń macierzowych:
|
||
|
// (Matrix4x4.Translate, Matrix4x4.Scale, Matrix4x4.Rotate) dwa pierwsze przyjmują Vector3, a obroty przyjmują Quaternion.Euler( X, Y, Z) (już bez new, bo to funkcja)
|
||
|
|
||
|
var transformationHsw = Matrix4x4.Translate(new Vector3(0, 0, hour));
|
||
|
var transformationMsw = Matrix4x4.Translate(new Vector3(0, 0, minute));
|
||
|
var transformationSsw = Matrix4x4.Translate(new Vector3(0, 0, second));
|
||
|
|
||
|
var transformationH = Matrix4x4.Translate(new Vector3(0, 5.0f, 0.0f)) * Matrix4x4.Rotate(Quaternion.Euler(0.0f, 0.0f, hour * 30.0f)) * Matrix4x4.Scale(new Vector3(0.4f, 1.5f, 0.4f)) * Matrix4x4.Translate(new Vector3(0, 1.0f, 0.0f));
|
||
|
var transformationM = Matrix4x4.Translate(new Vector3(0, 5.0f, 0.0f)) * Matrix4x4.Rotate(Quaternion.Euler(0.0f, 0.0f, minute * 6.0f)) * Matrix4x4.Scale(new Vector3(0.3f, 2.5f, 0.3f)) * Matrix4x4.Translate(new Vector3(0, 1.0f, 0.0f));
|
||
|
var transformationS = Matrix4x4.Translate(new Vector3(0, 5.0f, 0.0f)) * Matrix4x4.Rotate(Quaternion.Euler(0.0f, 0.0f, second * 6.0f)) * Matrix4x4.Scale(new Vector3(0.1f, 3.0f, 0.1f)) * Matrix4x4.Translate(new Vector3(0, 1.0f, 0.0f));
|
||
|
|
||
|
// Create game objects instances
|
||
|
|
||
|
Graphics.DrawMeshInstanced(
|
||
|
clockHand.GetComponent<MeshFilter>().mesh,
|
||
|
0,
|
||
|
clockHand.GetComponent<MeshRenderer>().material,
|
||
|
new Matrix4x4[3]
|
||
|
{
|
||
|
transformationH,
|
||
|
transformationM,
|
||
|
transformationS
|
||
|
});
|
||
|
|
||
|
}
|
||
|
}
|