première ébauche PlanetManager

This commit is contained in:
Jean-Sébastien Gervais 2016-04-08 00:44:04 -04:00
parent 5546304506
commit ef07f70d65
3 changed files with 131 additions and 0 deletions

View File

@ -0,0 +1,93 @@
using UnityEngine;
using System.Collections;
public class PlanetManager : MonoBehaviour
{
public int NbCartiers = 10;
public float TailleCartiersEnDegres = 0; //radian -> valeurs 0 a 360
var wedges = new List<Wedge>();
// Use this for initialization
void Start () {
TailleCartiersEnRadiants = 360.0 / NbCartiers;
float debutAngleTheta = 0.0;
for(int i = 0; i < NbCartiers; i++)
{
debutAngleTheta = i*TailleCartiersEnRadiants;
wedges.Add(new wedges(){tMin = debutAngleTheta, tMax = debutAngleTheta + TailleCartiersEnRadiants});
}
}
// Update is called once per frame
void Update () {
}
public float GetPlanetRadius()
{
}
public Vector3 GetPlanetCoordinatesFromPlayerXY(float playerLocalX, float playerLocalY)
{
var theta = playerLocalX;
double x = r * Math.Cos(theta * Math.PI / 180);
double y = r * Math.Sin(theta * Math.PI / 180) + playerLocalY;
return new Vector3(x,y,0);
}
/// <summary>
/// retourn le no de plateforme
/// </summary>
/// <param name="thetaPlayerX"></param>
public int GetWedgeIndex(float thetaPlayerX)
{
return Math.Floor(thetaPlayerX / TailleCartiersEnRadiants);
}
/// <summary>
///
/// </summary>
/// <param name="wedgeIndex"></param>
/// <returns></returns>
public int GetWedgeOpposé(int wedgeIndex)
{
//(i + 5) % 10 => [0,9]
return (wedgeIndex + NbCartiers / 2) % (NbCartiers);
}
/// <summary>
/// retourne l'objet interne
/// </summary>
/// <param name="thetaPlayerX"></param>
/// <returns></returns>
public Wedge GetWedgeFromTheta(float thetaPlayerX)
{
return wedges[GetWedgeIndex(thetaPlayerX)];
}
/// <summary>
/// Représente une plateforme qui bouge.
/// </summary>
public class Wedge
{
float yoffset = 0; //valeurs entre -1 et 1; -1 étant renfoncé, 0 position normale, et 1 vers l'extérieur
float tMin = 0; //theta min et theta max : angle thetat de début et fin du cartier;
float tMax = 0;
}
}

View File

@ -0,0 +1,38 @@
using System;
using UnityEngine;
using System.Collections;
public class testRotate : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
/// <summary>
/// Juste pour tester le mouvement du player autour du cercle.
/// Le player se déplace de gauche a droite en x et la valeur de x représente l'angle theta
/// saute en y
/// </summary>
void FixedUpdate()
{
var speed = 13.2;
var theta = Time.realtimeSinceStartup * speed % 360.0; // Position X du player = angle theta
var r = 5.0; //sphereradius
// XY coordinates
double x = r * Math.Cos(theta * Math.PI / 180);
double y = r * Math.Sin(theta * Math.PI / 180); // + y0 du player
var player = GameObject.Find("CubePlayer").gameObject;
player.transform.position = Vector3.Lerp(player.transform.position, new Vector3( (float)x, (float)y, 0 ), Time.deltaTime);
}
}

BIN
Assets/_Scenes/planet.unity Normal file

Binary file not shown.