You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.0 KiB

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
public class AVPro360 : MonoBehaviour
{
public Camera workingCamera;
public DShowMoviePlayer _movie;
//public bool fix_perspective = true;
[Range(0.0f, 1.0f)]
public float fix_perspective;
[Range(0.0f, 1.0f)]
public float fix_rotate;
public float degree = 0;
public int frameOffset;
public int currentFrame;
public int frameCount
{
get
{
return _frame_count;
}
}
private int _frame_count;
private float _f_frame;
private RawImage _rawImage;
void Start()
{
//Application.targetFrameRate = 60;
}
float deg_2_frame(float deg)
{
return Mathf.Repeat(deg / 360.0f * _frame_count + frameOffset, _frame_count);
}
float get_degree(Vector3 v)
{
Vector3 z = new Vector3(0.0f, 0.0f, 1.0f);
v.y = 0;
v.Normalize();
Vector3 axis = Vector3.Cross(v, z).normalized;
return Math.Sign(axis.y) * Mathf.Rad2Deg * Mathf.Acos(Vector3.Dot(v, z));
}
public bool isReady()
{
return _movie != null;
}
// Update is called once per frame
void Update()
{
if (isReady() == false)
return;
if (_frame_count == 0)
{
_frame_count = (int)_movie.TotalNumFrames;
}
float degree_offset = 0;
Camera cam = workingCamera == null ? Camera.main : workingCamera;
Ray ray = cam.ScreenPointToRay(cam.WorldToScreenPoint(transform.position));
degree_offset += get_degree(ray.direction) * fix_perspective;
Vector3 dir = transform.parent.forward;
degree_offset += -get_degree(dir) * fix_rotate;
_f_frame = deg_2_frame(degree + degree_offset);
currentFrame = Mathf.RoundToInt(_f_frame) % _frame_count;
//Debug.Log("currentFrame = " + currentFrame);
_movie.Frame = (uint)currentFrame;
transform.rotation = cam.transform.rotation;
}
}