public DenseMatrixQuaternion(int rows, int columns) { datas = new Quaternion[rows, columns]; this.rowCount = rows; this.columnCount = columns; }
private static int SetRotations(string[] pieceFile, int index, ref Quaternion[,] rotations) { int a = 0; for (int i = index; i < pieceFile.Length; i++) { if (pieceFile[i].Trim() == "~") { return(Mathf.Clamp(i + 1, 0, pieceFile.Length - 1)); } for (int j = 0; j < pieceFile[i].Length; j++) { char c = pieceFile[i][j]; if (c == ' ') { continue; } int rotation = Convert.ToInt32(c); rotations[a, j] = BasePiece.ParseRotation(rotation); } a++; } return(Mathf.Clamp(index + 1, 0, pieceFile.Length)); }
void Start() { Objects = GameObject.FindGameObjectsWithTag("TimeControlled"); Positions = new Vector3[Objects.Length, Scale]; Rotations = new Quaternion[Objects.Length, Scale]; }
public static DenseMatrixQuaternion operator *(DenseMatrixQuaternion left, SparseMatrixQuaternion right) { //Make sure matrix dimensions are equal if (left.columnCount != right.RowCount) { throw new Exception("The dimension of two matrix must be equal"); } DenseMatrixQuaternion resultMatrix = new DenseMatrixQuaternion(left.RowCount, right.ColumnCount); Quaternion[,] result = resultMatrix.datas; for (int i = 0; i < left.rowCount; i++) { foreach (KeyValuePair <Pair, Quaternion> item in right.Datas) { Pair pair = item.Key; Quaternion value = item.Value; int m = pair.Key; int n = pair.Value; //M: mutiply index N: vector store index result[i, n] += left[i, m] * value; } } return(resultMatrix); }
// Use this for initialization void Start() { kinect = devOrEmu.getKinect(); players = new Kinect.NuiSkeletonTrackingState[Kinect.Constants.NuiSkeletonCount]; trackedPlayers = new int[Kinect.Constants.NuiSkeletonMaxTracked]; trackedPlayers[0] = -1; trackedPlayers[1] = -1; bonePos = new Vector3[2, (int)Kinect.NuiSkeletonPositionIndex.Count]; rawBonePos = new Vector3[2, (int)Kinect.NuiSkeletonPositionIndex.Count]; boneVel = new Vector3[2, (int)Kinect.NuiSkeletonPositionIndex.Count]; boneState = new Kinect.NuiSkeletonPositionTrackingState[2, (int)Kinect.NuiSkeletonPositionIndex.Count]; boneLocalOrientation = new Quaternion[2, (int)Kinect.NuiSkeletonPositionIndex.Count]; boneAbsoluteOrientation = new Quaternion[2, (int)Kinect.NuiSkeletonPositionIndex.Count]; //create the transform matrix that converts from kinect-space to world-space Matrix4x4 trans = new Matrix4x4(); trans.SetTRS(new Vector3(-kinect.getKinectCenter().x, kinect.getSensorHeight() - kinect.getKinectCenter().y, -kinect.getKinectCenter().z), Quaternion.identity, Vector3.one); Matrix4x4 rot = new Matrix4x4(); Quaternion quat = new Quaternion(); double theta = Mathf.Atan((kinect.getLookAt().y + kinect.getKinectCenter().y - kinect.getSensorHeight()) / (kinect.getLookAt().z + kinect.getKinectCenter().z)); float kinectAngle = (float)(theta * (180 / Mathf.PI)); quat.eulerAngles = new Vector3(-kinectAngle, 0, 0); rot.SetTRS(Vector3.zero, quat, Vector3.one); //final transform matrix offsets the rotation of the kinect, then translates to a new center kinectToWorld = flipMatrix * trans * rot; }
public PoseModel(Quaternion[,] initModel) { Assert.AreEqual(initModel.GetLength(0), numberOfJoints); Assert.AreEqual(initModel.GetLength(1), numberOfFrames); rotationModel = initModel; }
/// <summary> /// Calculates rotations for drawing the Scene GUI wireframe. /// </summary> /// <param name="cellArc">Grid cell arc angle</param> /// <param name="lonLatRect">Lon/Lat rectangle</param> /// <param name="shape">Grid shape</param> /// <param name="rotations">Rotations [lon, lat]</param> public static void CalcGridRotations(float cellArc, Rect lonLatRect, GridBuffer.Shape shape, ref Quaternion[,] rotations) { int nLon = shape.Width + 1; int nLat = shape.Height + 1; if (rotations == null || rotations.Length != nLon * nLat) { rotations = new Quaternion[nLon, nLat]; float x = lonLatRect.min.x; float y = lonLatRect.min.y; for (int iLat = 0; iLat < nLat; iLat++) { var qLat = Quaternion.AngleAxis(y + iLat * cellArc, Vector3.left); for (int iLon = 0; iLon < nLon; iLon++) { var qLon = Quaternion.AngleAxis(x + iLon * cellArc, Vector3.up); rotations[iLon, iLat] = qLon * qLat; } } } }
// Use this for initialization void Start () { kinect = devOrEmu.getKinect(); players = new Kinect.NuiSkeletonTrackingState[Kinect.Constants.NuiSkeletonCount]; trackedPlayers = new int[Kinect.Constants.NuiSkeletonMaxTracked]; trackedPlayers[0] = -1; trackedPlayers[1] = -1; bonePos = new Vector3[2,(int)Kinect.NuiSkeletonPositionIndex.Count]; rawBonePos = new Vector3[2,(int)Kinect.NuiSkeletonPositionIndex.Count]; boneVel = new Vector3[2,(int)Kinect.NuiSkeletonPositionIndex.Count]; boneState = new Kinect.NuiSkeletonPositionTrackingState[2,(int)Kinect.NuiSkeletonPositionIndex.Count]; boneLocalOrientation = new Quaternion[2, (int)Kinect.NuiSkeletonPositionIndex.Count]; boneAbsoluteOrientation = new Quaternion[2, (int)Kinect.NuiSkeletonPositionIndex.Count]; //create the transform matrix that converts from kinect-space to world-space Matrix4x4 trans = new Matrix4x4(); trans.SetTRS( new Vector3(-kinect.getKinectCenter().x, kinect.getSensorHeight()-kinect.getKinectCenter().y, -kinect.getKinectCenter().z), Quaternion.identity, Vector3.one ); Matrix4x4 rot = new Matrix4x4(); Quaternion quat = new Quaternion(); double theta = Mathf.Atan((kinect.getLookAt().y+kinect.getKinectCenter().y-kinect.getSensorHeight()) / (kinect.getLookAt().z + kinect.getKinectCenter().z)); float kinectAngle = (float)(theta * (180 / Mathf.PI)); quat.eulerAngles = new Vector3(-kinectAngle, 0, 0); rot.SetTRS( Vector3.zero, quat, Vector3.one); //final transform matrix offsets the rotation of the kinect, then translates to a new center kinectToWorld = flipMatrix*trans*rot; }
public void StartGame() { if (turn == 0) { bPos = new Vector3[boardSize.x, boardSize.y]; bRot = new Quaternion[boardSize.x, boardSize.y]; bSprites = new SpriteRenderer[boardSize.x, boardSize.y]; //Instantiate placeholders & get coordinates sheetObject = Instantiate(new GameObject(), transform); GameObject boardObj = Instantiate(boardPrefab, sheetObject.transform); for (int i = 0; i < boardSize.x; i++) { for (int j = 0; j < boardSize.y; j++) { float angle = 2 * j * Mathf.PI * 0.125f + rotOffset; bPos[i, j] = new Vector3(Mathf.Cos(angle), 0, Mathf.Sin(angle)) * vertSpacing[i]; bRot[i, j] = Quaternion.Euler(new Vector3(90, -Mathf.Rad2Deg * angle + 90, 0)); GameObject tempObj = Instantiate(placeholderPrefab, bPos[i, j], bRot[i, j], sheetObject.transform); bSprites[i, j] = tempObj.GetComponent <SpriteRenderer>(); //bSprites[i,j].sprite = objects[3]; //Peenify } } placeholder = Instantiate(placeholderPrefab).GetComponent <SpriteRenderer>(); boardController = boardObj.GetComponent <BoardController>(); boardController.boardSize = boardSize; boardController.board = new int[boardSize.x, boardSize.y]; boardController.tetrisMode = tetrisMode; championScores = new float[numPlayers + 1]; timerValue = new float[numPlayers]; if (!isMultiplayer) { computer = GetComponent <ComputerBrain>(); computer.ComputerStart(); computer.difficulty = 2 * difficulty + 1; numPlayers = 2; } cameraAnim.SetBool("gameStarted", true); ChangeTurn(); ResetTimer(); } else { print("fast as heck boi"); } }
void DestroyExistingShapes() { for (int i = 0; i < numberOfShapes; i++) { GameObject.Destroy(shapeList[i]); } shapeList.Clear(); shapeTypeList.Clear(); positionArray = null; rotationArray = null; localScaleArray = null; numberOfShapes = 0; }
// public Fingers() { convertor = new Convertor(); degreeRate = new float[5, 2]; preDegree = new float[5, 2]; fingerDegree = new float[5, 2]; fingers_obj = new GameObject[5, 2]; fingerRot = new Quaternion[5, 2]; readData = GameObject.Find("ReadData").GetComponent <ReadData>(); CM = GameObject.Find("CalibrateManager").GetComponent <CalibrateManager>(); Debug.Log("GetComponent : CalibrateManager"); this.minFlexAvg = (int[, ])CM.minFlexAvg.Clone(); this.rightAngleAvg = (int[])CM.rightAngleAvg.Clone(); this.maxFlexAvg = (int[, ])CM.maxFlexAvg.Clone(); Destroy(CM.gameObject); for (int i = 0; i < 5; i++) { degreeRate[i, 0] = convertor.calDegreeRate(maxFlexAvg[i, 0], minFlexAvg[i, 0]); degreeRate[i, 1] = convertor.calDegreeRate(maxFlexAvg[i, 1], minFlexAvg[i, 1]); Debug.Log("degreeRate[" + i + ", 0] " + degreeRate[i, 0]); Debug.Log("degreeRate[" + i + ", 1] " + degreeRate[i, 1]); } // 엄지 fingers_obj[0, 0] = GameObject.Find("thumb_r_001"); fingers_obj[0, 1] = GameObject.Find("thumb_r_002"); // 검지 fingers_obj[1, 0] = GameObject.Find("index_r"); fingers_obj[1, 1] = GameObject.Find("index_r_001"); // 중지 fingers_obj[2, 0] = GameObject.Find("middle_r"); fingers_obj[2, 1] = GameObject.Find("middle_r_001"); // 약지 fingers_obj[3, 0] = GameObject.Find("ring_r"); fingers_obj[3, 1] = GameObject.Find("ring_r_001"); // 소지 fingers_obj[4, 0] = GameObject.Find("pinky_r"); fingers_obj[4, 1] = GameObject.Find("pinky_r_001"); ReadData.FlexToFingerDegreeEvent += ReadData_FlexToFingerDegreeEvent; readData.setSceneNumber(1); }
public void UpdateAnimationFolderAndCreateObjects() { workingDirectory = new DirectoryInfo(Application.dataPath + "/Animation/" + animationFolderInput.text + "/"); if (workingDirectory.Exists) { FileInfo[] fileInfoList = workingDirectory.GetFiles("*.txt"); animationFilePaths.Clear(); DestroyExistingShapes(); numAnimationFiles = fileInfoList.Length; delayToNextFrameArray = null; currentFrameNumber = 0; for (int i = 0; i < numAnimationFiles; i++) { animationFilePaths.Add(fileInfoList[i].FullName); } numberOfShapes = FindNumberOfShapesFromFile(); if (numberOfShapes > 0) { positionArray = new Vector3[numAnimationFiles, numberOfShapes]; rotationArray = new Quaternion[numAnimationFiles, numberOfShapes]; localScaleArray = new Vector3[numAnimationFiles, numberOfShapes]; delayToNextFrameArray = new int[numAnimationFiles]; for (int i = 0; i < numAnimationFiles; i++) { LoadFrameFromFile(i); } } } else { numAnimationFiles = 0; numberOfShapes = 0; SetErrorText("FOLDER DOESNT EXIST!"); //clearNoticeButton.interactable = false; //this is how you grey out a button } if ((numberOfShapes > 0) && (numAnimationFiles > 0)) { CreateAllObjectsToAnimate(); } }
private void UpdateSegments() { var curShapeLength = (EndTransform.position - StartTransform.position).magnitude; if (Mathf.Abs((_ArcShapeLength - curShapeLength) / curShapeLength) < REINIT_THRESHOLD) { return; } _ArcShapeLength = curShapeLength; var maxSegmNum = 0; for (int n = 0; n < arcs.Length; n++) { //Segment and vertex initialization var sizeOptions = arcs[n].sizeOptions; var segmCount = Mathf.Max((int)(_ArcShapeLength / sizeOptions.segmentLength) + sizeOptions.minNumberOfSegments, 2); if (segmCount > maxSegmNum) { maxSegmNum = segmCount; } _SegmentNums[n] = segmCount; _VertexCounts[n] = segmCount * (sizeOptions.numberOfSmoothingSegments + 1) + 1; _Vertices[n] = new Vector3[_VertexCounts[n]]; _LineRenderers[n].positionCount = _VertexCounts[n]; } _ArcPoints = new Vector3[arcs.Length, maxSegmNum + 2]; _ShiftVectors = new Vector3[arcs.Length, maxSegmNum + 2]; _ArcTangents = new Vector3[arcs.Length, maxSegmNum + 2]; _ArcTangentsShift = new Quaternion[arcs.Length, maxSegmNum * 2 + 2]; for (int n = 0; n < arcs.Length; n++) { UpdateArcNoise(n, true); for (int i = 0; i < _SegmentNums[n]; i++) { var point = (float)i / _SegmentNums[n]; _ArcPoints[n, i] = CalcShapePoint(point) + _ShiftVectors[n, i]; } } }
Quaternion[,] cup_rotations; // stores the starting rotation of the cups // Use this for initialization void Start() { n_cups = 18; //save ball transform ball_start_pos = new Vector3(ball.transform.position.x, ball.transform.position.y, ball.transform.position.z); //save cups transforms cup_positions = new Vector3[3, 6]; cup_rotations = new Quaternion[3, 6]; for (int j = 0; j < 3; j++) { // each stack of cups is a child of the cups obj Transform cup_stack = cups.GetChild(j).transform; for (int i = 0; i < 6; i++) { cup_positions[j, i] = cup_stack.GetChild(i).transform.position; cup_rotations[j, i] = cup_stack.GetChild(i).transform.rotation; } } }
void Start() { int num_ar = ar_objects.Length; relative_pos = new Vector3[num_ar, num_ar]; relative_rot = new Quaternion[num_ar, num_ar]; rel_rec = new int[num_ar, num_ar]; for (int i = 0; i < num_ar; i++) { for (int j = 0; j < num_ar; j++) { relative_pos[i, j] = Vector3.zero; relative_rot[i, j] = Quaternion.identity; rel_rec[i, j] = 0; } } for (int i = 0; i < num_ar; i++) { scene_objects[i].transform.position = Vector3.one * 1000; scene_objects[i].transform.rotation = Quaternion.identity; } }
/// <summary> /// Writes a 2D array of quaternion structs to the output. /// </summary> /// <param name="name">Name of the value</param> /// <param name="value">2D array of quaternions</param> public void Write(string name, Quaternion[,] value) { if (value == null) { _output.Write(NULL_OBJECT); return; } else { _output.Write(A_OK); } int row = value.GetUpperBound(0); int col = value.GetUpperBound(1); _output.Write(row); _output.Write(col); for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { this.Write(null, value[i, j]); } } }
private void GenerateNoisePreview() { GenerateNoiseGenerator(); previewGradient = new Vector4[Res + 1,Res + 1]; previewRot = new Quaternion[Res + 1, Res + 1]; int y = Mathf.RoundToInt(PreviewSlice * Res); for (int z = 0; z < Res; ++z) { for (int x = 0; x < Res; ++x) { Vector3 val = GetValue(x, y, z); float mag = val.magnitude; val = val.normalized; previewGradient[x, z] = new Vector4(val.x, val.y, val.z, mag); previewRot[x, z] = Quaternion.FromToRotation(Vector3.up, val / mag); } } CalcPreviewDeriv(Res, Res); NeedsPreview = false; }
protected void Initialize () { oldShapeLength = shapeLength; bool anyLights = false; for(int n = 0; n < arcs.Length; n++) { //Particle emitter initialization for (int q = 0; q < arcs[n].emissionOptions.Length; q++) { if (emitterSystems[n][q] == null && arcs[n].emissionOptions[q].shurikenPrefab != null) { GameObject partGameObject = (GameObject)GameObject.Instantiate(arcs[n].emissionOptions[q].shurikenPrefab); partGameObject.name = "EmitterObject "+gameObject.name+" "+n.ToString()+","+q.ToString(); emitterSystems[n][q] = partGameObject.GetComponent<ParticleSystem>(); if (emitterSystems[n][q].enableEmission) emitterSystems[n][q].enableEmission = false; if (!arcs[n].emissionOptions[q].emitAfterRayDeath) partGameObject.transform.parent = transform; else { emitterDestructors[n][q] = partGameObject.AddComponent<ArcReactor_EmitterDestructor>(); emitterDestructors[n][q].partSystem = emitterSystems[n][q]; emitterDestructors[n][q].enabled = false; } partGameObject.transform.position = transform.position; partGameObject.transform.rotation = transform.rotation; } } //Lights initialization if (arcs[n].lightsOptions.lights) { for (int i = 0; i < lightsCount[n]; i++) { Destroy(lights[n,i].gameObject); } } anyLights |= arcs[n].lightsOptions.lights; lightsCount[n] = Mathf.Max ((int)(shapeLength * 2 / arcs[n].lightsOptions.lightsRange + 1),2); //Segment and vertex initialization segmNums[n] = Mathf.Max((int)(shapeLength / (arcs[n].sizeOptions.segmentLength * sizeMultiplier))+arcs[n].sizeOptions.minNumberOfSegments,2); vertexCount[n] = segmNums[n]*(arcs[n].sizeOptions.numberOfSmoothingSegments+1)+1; oldVertexCount[n] = vertexCount[n]; oldVertices[n] = new Vector3[vertexCount[n]]; vertices[n] = new Vector3[vertexCount[n]]; lrends[n].SetVertexCount(vertexCount[n]); //Flares placing if (arcs[n].flaresOptions.startFlare.enabled && startFlare == null) { GameObject obj = new GameObject(gameObject.name + "_Start_flare"); obj.transform.parent = transform; startFlare = obj.gameObject.AddComponent<LensFlare>(); startFlare.flare = arcs[n].flaresOptions.startFlare.flare; startFlare.fadeSpeed = arcs[n].flaresOptions.startFlare.fadeSpeed; } if (arcs[n].flaresOptions.endFlare.enabled && endFlare == null) { GameObject obj = new GameObject(gameObject.name + "_End_flare"); obj.transform.parent = transform; endFlare = obj.gameObject.AddComponent<LensFlare>(); endFlare.flare = arcs[n].flaresOptions.endFlare.flare; endFlare.fadeSpeed = arcs[n].flaresOptions.endFlare.fadeSpeed; } } //vertices = new Vector3[arcs.Length,vertexCount.Max()]; arcPoints = new Vector3[arcs.Length,segmNums.Max()+2]; shiftVectors = new Vector3[arcs.Length,segmNums.Max()+2]; arcTangents = new Vector3[arcs.Length,segmNums.Max()+2]; arcTangentsShift = new Quaternion[arcs.Length,segmNums.Max()*2+2]; for (int n = 0; n < arcs.Length; n++) { ResetArc(n); } if (anyLights) { GameObject lightObject; lights = new Light[arcs.Length,lightsCount.Max()]; lightsTransforms = new Transform[arcs.Length,lightsCount.Max()+1]; for(int n = 0; n < arcs.Length; n++) { if (arcs[n].lightsOptions.lights) { for (int i = 0; i < lightsCount[n]; i++) { lightObject = new GameObject("ArcLight"); lightObject.transform.parent = transform; lightsTransforms[n,i] = lightObject.transform; lights[n,i] = lightObject.AddComponent<Light>(); lights[n,i].type = LightType.Point; lights[n,i].renderMode = arcs[n].lightsOptions.renderMode; lights[n,i].range = arcs[n].lightsOptions.lightsRange; } } } } }
protected void UpdateGeometry() { m_GridResolution = Mathf.PI * 2 * m_MaxDistance / (360 / m_CellArc); float lonMin = -m_LonAngle; float lonMax = m_LonAngle; float latMin = -m_LatAngleSouth; float latMax = m_LatAngleNorth; float lonRange = lonMax - lonMin; float latRange = latMax - latMin; int nLon = Mathf.Max(1, Mathf.CeilToInt(lonRange / m_CellArc)); int nLat = Mathf.Max(1, Mathf.CeilToInt(latRange / m_CellArc)); m_GridDimensions.x = nLon; m_GridDimensions.y = nLat; float lonRangePadded = nLon * m_CellArc; float latRangePadded = nLat * m_CellArc; float lonPadding = (lonRangePadded - lonRange) * 0.5f; float latPadding = (latRangePadded - latRange) * 0.5f; float lonMinPad = lonMin - lonPadding; float lonMinPadClamp = Mathf.Max(-180, lonMinPad); float lonMaxPadClamp = Mathf.Min(180, lonMax + lonPadding); float latMinPad = latMin - latPadding; float latMinPadClamp = Mathf.Max(-90, latMinPad); float latMaxPadClamp = Mathf.Min(90, latMax + latPadding); m_LonLatRect = new Rect( lonMinPadClamp, latMinPadClamp, lonMaxPadClamp - lonMinPadClamp, latMaxPadClamp - latMinPadClamp); // Scene GUI Wireframe. nLat++; nLon++; if (Wireframe == null || Wireframe.Length != nLat * nLon) { m_Wireframe = new Quaternion[nLat, nLon]; } for (int iLat = 0; iLat < nLat; iLat++) { var qLat = Quaternion.AngleAxis( Mathf.Clamp(latMinPad + iLat * m_CellArc, latMinPadClamp, latMaxPadClamp), Vector3.left); for (int iLon = 0; iLon < nLon; iLon++) { var qLon = Quaternion.AngleAxis( Mathf.Clamp(lonMinPad + iLon * m_CellArc, lonMinPadClamp, lonMaxPadClamp), Vector3.up); Wireframe[iLat, iLon] = qLon * qLat; } } }
// Use this for initialization void Start() { if (transform.childCount == 0) { camPositions = new Vector3[levels,columns]; camRotations = new Quaternion[levels,columns]; builtMesh = new GameObject[levels,columns]; builtMeshVertices = new ViewPointMeshVertex[levels,columns]; float phi0 = anglePhiMin; float dPhi = (anglePhiMax-anglePhiMin)/(levels-1); float theta0 = transform.localRotation.eulerAngles.y + (thetaCentredAtOrigin ? -angleTheta/2f : 0f); float dTheta = angleTheta / (placeColumnAtBothEnds ? columns-1 : columns); for (int i = 0; i < levels; i++) { for (int j = 0; j < columns; j ++) { camPositions[i,j] = new Vector3( Mathf.Cos (Mathf.Deg2Rad * (theta0 + j*dTheta)) * Mathf.Cos (Mathf.Deg2Rad * (phi0 + i*dPhi)) * transform.localScale.x, Mathf.Sin (Mathf.Deg2Rad * (phi0 + i*dPhi)) * transform.localScale.y, Mathf.Sin (Mathf.Deg2Rad * (theta0 + j*dTheta)) * Mathf.Cos (Mathf.Deg2Rad * (phi0 + i*dPhi)) * transform.localScale.z); camRotations[i,j].eulerAngles = -transform.eulerAngles + (new Vector3(phi0 + i*dPhi,-90f + ((thetaCentredAtOrigin ? angleTheta/2f : 0f)) - j*dTheta,0)); builtMesh[i,j] = GameObject.Instantiate(viewPointMeshVertex,transform.position+camPositions[i,j],camRotations[i,j]) as GameObject; builtMesh[i,j].transform.parent = transform; } } for (int i = 0; i < levels; i++) { for (int j = 0; j < columns; j ++) { builtMeshVertices[i,j] = builtMesh[i,j].GetComponent<ViewPointMeshVertex>(); if (i > 0) { builtMeshVertices[i,j].down = builtMeshVertices[i-1,j]; builtMeshVertices[i-1,j].up = builtMeshVertices[i,j]; } if (j > 0) { builtMeshVertices[i,j].left = builtMeshVertices[i,j-1]; builtMeshVertices[i,j-1].right = builtMeshVertices[i,j]; } SetVertexVariables(builtMeshVertices[i,j]); } if (loopAround) { builtMeshVertices[i,0].left = builtMeshVertices[i,columns-1]; builtMeshVertices[i,columns-1].right = builtMeshVertices[i,0]; } } meshBuilt = true; if (connectAnotherBuilderOnTheLeft != null) { if (connectAnotherBuilderOnTheLeft.MeshIsBuilt()) { for (int i = 0; i < levels && i < connectAnotherBuilderOnTheLeft.levels; i++) { builtMeshVertices[i,0].left = connectAnotherBuilderOnTheLeft.builtMeshVertices[i,connectAnotherBuilderOnTheLeft.columns-1]; connectAnotherBuilderOnTheLeft.builtMeshVertices[i,connectAnotherBuilderOnTheLeft.columns-1].right = builtMeshVertices[i,0]; } } } if (connectAnotherBuilderOnTheRight != null) { if (connectAnotherBuilderOnTheRight.MeshIsBuilt()) { for (int i = 0; i < levels && i < connectAnotherBuilderOnTheRight.levels; i++) { builtMeshVertices[i,columns-1].right = connectAnotherBuilderOnTheRight.builtMeshVertices[i,0]; connectAnotherBuilderOnTheRight.builtMeshVertices[i,0].left = builtMeshVertices[i,columns-1]; } } } if (enterDefaultVertexOnStart) { if (defaultVertex.Length == 2) { ViewPointMesh mesh = GetComponentInParent<ViewPointMesh>(); mesh.defaultVertex = builtMeshVertices[defaultVertex[0],defaultVertex[1]]; GameObject.FindGameObjectWithTag("GameController").GetComponent<Controller>().ActivateVertex(mesh.defaultVertex); } else { Debug.Log ("Couldn't enter default vertex as incorrectly specified."); } } } else if (enterDefaultVertexOnStart) { camPositions = new Vector3[levels,columns]; camRotations = new Quaternion[levels,columns]; builtMesh = new GameObject[levels,columns]; builtMeshVertices = new ViewPointMeshVertex[levels,columns]; float phi0 = anglePhiMin; float dPhi = (anglePhiMax-anglePhiMin)/(levels-1); float theta0 = transform.localRotation.eulerAngles.y + (thetaCentredAtOrigin ? -angleTheta/2f : 0f); float dTheta = angleTheta / (placeColumnAtBothEnds ? columns-1 : columns); for (int i = 0; i < levels; i++) { for (int j = 0; j < columns; j ++) { camPositions[i,j] = new Vector3( Mathf.Cos (Mathf.Deg2Rad * (theta0 + j*dTheta)) * Mathf.Cos (Mathf.Deg2Rad * (phi0 + i*dPhi)) * transform.localScale.x, Mathf.Sin (Mathf.Deg2Rad * (phi0 + i*dPhi)) * transform.localScale.y, Mathf.Sin (Mathf.Deg2Rad * (theta0 + j*dTheta)) * Mathf.Cos (Mathf.Deg2Rad * (phi0 + i*dPhi)) * transform.localScale.z); camRotations[i,j].eulerAngles = -transform.eulerAngles + (new Vector3(phi0 + i*dPhi,-90f + ((thetaCentredAtOrigin ? angleTheta/2f : 0f)) - j*dTheta,0)); builtMesh[i,j] = GameObject.Instantiate(viewPointMeshVertex,transform.position+camPositions[i,j],camRotations[i,j]) as GameObject; builtMesh[i,j].transform.parent = transform; } } ViewPointMesh mesh = GetComponentInParent<ViewPointMesh>(); GameObject.FindGameObjectWithTag("GameController").GetComponent<Controller>().ActivateVertex(mesh.defaultVertex); } }
public void AppendRows(int rows) { rowCount += rows; datas = (Quaternion[, ])ResizeArray(datas, new int[] { this.rowCount, this.columnCount }); }
public void AppendColumns(int columns) { columnCount += columns; datas = (Quaternion[, ])ResizeArray(datas, new int[] { this.rowCount, this.columnCount }); }
public static void buildLevel(bool startFromLeft){ states = new Tile.State[Global.maxTileI+1,Global.maxTileJ+1]; bubbles = new BubbleModel[Global.maxTileI+1,Global.maxTileJ+1]; rotations = new Quaternion[Global.maxTileI+1,Global.maxTileJ+1]; for (int i=0; i<=Global.maxTileI; i++) for (int j=0; j<=Global.maxTileJ; j++){ states[i,j] = Tile.State.Neutral; bubbles[i,j] = new BubbleModel(i,j); rotations[i,j] = Quaternion.identity; } int currentTileI = 0; if (!startFromLeft) currentTileI = Global.maxTileI; int currentTileJ = 0; Global.rotatingCube.initParams(); Global.Direction lastDirection = Global.Direction.Left; bool shouldAvoidLastDirection = false; int shouldAvoidLastDirectionCounter = 0; BubbleModel currentBubble = null; while ((currentTileI < Global.maxTileI && startFromLeft) || (currentTileI > 0 && !startFromLeft)){ int probBubble = (int)(1.0f*bubbleProbLeft * (Global.maxTileI-currentTileI)/Global.maxTileI + 1.0f*bubbleProbRight * (currentTileI)/Global.maxTileI); if (shouldAvoidLastDirection){ if (shouldAvoidLastDirectionCounter++ > 20) shouldAvoidLastDirection = false; } else if (currentTileI > 2 && currentTileI < Global.maxTileI-2 && Random.Range(0,100) < probBubble){ currentBubble = bubbles[currentTileI, currentTileJ]; if (Random.Range(0,3) == 0) currentBubble.bubbleType = Bubble.Type.Red; else if (Random.Range(0,2) == 0) currentBubble.bubbleType = Bubble.Type.Green; else currentBubble.bubbleType = Bubble.Type.Blue; shouldAvoidLastDirection = true; shouldAvoidLastDirectionCounter = 0; rotations[currentTileI, currentTileJ] = Global.rotatingCube.transform.localRotation; states[currentTileI, currentTileJ] = Tile.State.Neutral; } if (Random.Range(0,2) == 0){ if (startFromLeft){ currentTileI++; Global.rotatingCube.quickMove(Global.Direction.Right); lastDirection = Global.Direction.Right; } else { currentTileI--; Global.rotatingCube.quickMove(Global.Direction.Left); lastDirection = Global.Direction.Left; } } else { if (currentTileJ > 0 && Random.Range(0,2) == 0 && (!shouldAvoidLastDirection || lastDirection != Global.Direction.Up)){ currentTileJ--; Global.rotatingCube.quickMove(Global.Direction.Down); lastDirection = Global.Direction.Down; } else if (currentTileJ < Global.maxTileJ && (!shouldAvoidLastDirection || lastDirection != Global.Direction.Down)){ currentTileJ++; Global.rotatingCube.quickMove(Global.Direction.Up); lastDirection = Global.Direction.Up; } else{ if (startFromLeft){ currentTileI++; Global.rotatingCube.quickMove(Global.Direction.Right); lastDirection = Global.Direction.Right; } else{ currentTileI--; Global.rotatingCube.quickMove(Global.Direction.Left); lastDirection = Global.Direction.Left; } } } states[currentTileI,currentTileJ] = Global.rotatingCube.getState(); if (shouldAvoidLastDirection && currentBubble != null){ currentBubble.addBlinkingTile(currentTileI,currentTileJ); } } Global.rotatingCube.initParams(); }
private void GenerateTexturePreview() { if (target.forceTexture == null) { return; } int xres = target.forceTexture.width; int yres = target.forceTexture.height; int zres = target.forceTexture.depth; previewGradient = new Vector4[xres + 1,zres + 1]; previewRot = new Quaternion[xres + 1, zres + 1]; Color[] cols = target.forceTexture.GetPixels(0); int y = target.forceTexture.height / 2; for (int z = 0; z < zres; ++z) { for (int x = 0; x < xres; ++x) { Vector3 val = DecodeVector(cols[x + y * xres + z * xres * yres]); float mag = val.magnitude; val = val.normalized; previewGradient[x, z] = new Vector4(val.x, val.y, val.z, mag); previewRot[x, z] = Quaternion.FromToRotation(Vector3.up, val / mag); } } CalcPreviewDeriv(xres, zres); }
using UnityEngine;
public void AppendColumns(int columns) { columnCount += columns; datas = (Quaternion[,])ResizeArray(datas, new int[] { this.rowCount, this.columnCount }); }
public PoseModel() { rotationModel = new Quaternion[numberOfJoints, numberOfFrames]; }
void Start() { material = new Material[3]; pipes = new GameObject[3, 20]; position = new Vector3[3, 50]; rotation = new Quaternion[3, 50]; numOfPipe = new int[3]; kindOfPipe = new int[3]; tier = transform.parent.parent.parent.GetSiblingIndex() + 1; switch (tier) { case 1: material = (Material[])Resources.LoadAll <Material>("Pipe/Materials/Tier1"); break; case 2: material = (Material[])Resources.LoadAll <Material>("Pipe/Materials/Tier2"); break; case 3: material = (Material[])Resources.LoadAll <Material>("Pipe/Materials/Tier3"); break; } for (int x = 0; x < transform.childCount; x++) { numOfPipe[x] = transform.GetChild(x).GetChild(0).childCount; kindOfPipe[x] = transform.GetChild(x).childCount - 1; for (int i = 0; i < numOfPipe[x]; i++) { position[x, i] = transform.GetChild(x).GetChild(0).GetChild(i).localPosition; rotation[x, i] = transform.GetChild(x).GetChild(0).GetChild(i).localRotation; } if (x == 0) { y = 3; } else { y = 0; } for (int i = y; i < kindOfPipe[x]; i++) { pipes[x, i] = transform.GetChild(x).GetChild(i + 1).gameObject; for (int j = 0; j < numOfPipe[x]; j++) { pipes[x, i].transform.GetChild(j).localPosition = position[x, j]; pipes[x, i].transform.GetChild(j).localRotation = rotation[x, j]; for (int k = 0; k < pipes[x, i].transform.GetChild(j).childCount; k++) { pipes[x, i].transform.GetChild(j).GetChild(k).GetComponent <Renderer>().sharedMaterial = material[x]; } if (pipes[x, i].transform.GetChild(j).childCount == 0) { pipes[x, i].transform.GetChild(j).GetComponent <Renderer>().sharedMaterial = material[x]; } } } } //special pipes pipes[0, 0] = transform.GetChild(0).GetChild(1).gameObject; mats = pipes[0, 0].transform.GetChild(0).GetChild(0).GetComponent <Renderer>().materials; mats[3] = material[0]; for (int i = 0; i < pipes[0, 0].transform.childCount; i++) { pipes[0, 0].transform.GetChild(i).GetChild(0).GetComponent <Renderer>().materials = mats; } pipes[0, 1] = transform.GetChild(0).GetChild(2).gameObject; mats1 = pipes[0, 1].transform.GetChild(0).GetChild(1).GetComponent <Renderer>().materials; mats1[0] = material[0]; for (int i = 0; i < pipes[0, 1].transform.childCount; i++) { if (i % 2 == 0) { pipes[0, 1].transform.GetChild(i).GetChild(1).GetComponent <Renderer>().materials = mats1; } else { pipes[0, 1].transform.GetChild(i).GetChild(0).GetComponent <Renderer>().sharedMaterial = material[0]; } } pipes[0, 2] = transform.GetChild(0).GetChild(3).gameObject; mats2 = pipes[0, 2].transform.GetChild(0).GetChild(0).GetComponent <Renderer>().materials; mats2[0] = material[0]; for (int i = 0; i < pipes[0, 2].transform.childCount; i++) { if (i % 2 == 0) { pipes[0, 2].transform.GetChild(i).GetChild(0).GetComponent <Renderer>().materials = mats2; } else { pipes[0, 2].transform.GetChild(i).GetChild(0).GetComponent <Renderer>().sharedMaterial = material[0]; } } }
// Use this for initialization void Start() { camPositions = new Vector3[levels,columns]; camRotations = new Quaternion[levels,columns]; builtMesh = new GameObject[levels,columns]; builtMeshVertices = new ViewPointMeshVertex[levels,columns]; float phi0 = anglePhiMin; float dPhi = (anglePhiMax-anglePhiMin)/(levels-1); float theta0 = transform.localRotation.eulerAngles.y + (thetaCentredAtOrigin ? -angleTheta/2f : 0f); float dTheta = angleTheta / (placeColumnAtBothEnds ? columns-1 : columns); for (int i = 0; i < levels; i++) { for (int j = 0; j < columns; j ++) { camPositions[i,j] = new Vector3( Mathf.Cos (Mathf.Deg2Rad * (theta0 + j*dTheta)) * Mathf.Cos (Mathf.Deg2Rad * (phi0 + i*dPhi)) * transform.localScale.x, Mathf.Sin (Mathf.Deg2Rad * (phi0 + i*dPhi)) * transform.localScale.y, Mathf.Sin (Mathf.Deg2Rad * (theta0 + j*dTheta)) * Mathf.Cos (Mathf.Deg2Rad * (phi0 + i*dPhi)) * transform.localScale.z); camRotations[i,j].eulerAngles = transform.localRotation.eulerAngles + (new Vector3(phi0 + i*dPhi,90f - j*dTheta,0)); builtMesh[i,j] = GameObject.Instantiate(viewPointMeshVertex,transform.position+camPositions[i,j],camRotations[i,j]) as GameObject; } } for (int i = 0; i < levels; i++) { for (int j = 0; j < columns; j ++) { builtMeshVertices[i,j] = builtMesh[i,j].GetComponent<ViewPointMeshVertex>(); if (i > 0) { builtMeshVertices[i,j].down = builtMeshVertices[i-1,j]; builtMeshVertices[i-1,j].up = builtMeshVertices[i,j]; } if (j > 0) { builtMeshVertices[i,j].left = builtMeshVertices[i,j-1]; builtMeshVertices[i,j-1].right = builtMeshVertices[i,j]; } } if (loopAround) { builtMeshVertices[i,0].left = builtMeshVertices[i,columns-1]; builtMeshVertices[i,columns-1].right = builtMeshVertices[i,0]; } } gameController.OnBuildMeshToEnter(this); }
private static int SetPieces(string[] pieceFile, int index, PieceColor[,] colors, Quaternion[,] rotations, ref IPiece[,] pieces) { int a = 0; for (int i = index; i < pieceFile.Length; i++) { if (pieceFile[i].Trim() == "~") { return(Mathf.Clamp(i + 1, 0, pieceFile.Length - 1)); } for (int j = 0; j < pieceFile[i].Length; j++) { char c = pieceFile[i][j]; IPiece gp; switch (c) { case 'I': gp = new Pharaoh(new Point(a, j), rotations[a, j], colors[a, j], null); break; case 'S': gp = new Sphynx(new Point(a, j), rotations[a, j], colors[a, j], null); break; case 'C': gp = new Scarab(new Point(a, j), rotations[a, j], colors[a, j], null); break; case 'A': gp = new Anubis(new Point(a, j), rotations[a, j], colors[a, j], null); break; case 'P': gp = new Pyramid(new Point(a, j), rotations[a, j], colors[a, j], null); break; default: gp = new EmptyPoint(null, new Point(a, j)); break; } pieces[a, j] = gp; } a++; } return(Mathf.Clamp(index + 1, 0, pieceFile.Length - 1)); }
private void DrawWireFrame() { int nLon = m_Comp.GridSize.x; int nLat = m_Comp.GridSize.y; Quaternion[,] wf = m_Comp.Wireframe; if ((nLon + 1) * (nLat + 1) != wf.Length) { return; } UI.GLMaterial.SetPass(0); GL.PushMatrix(); GL.MultMatrix(m_Comp.transform.localToWorldMatrix); Vector3 min = Vector3.forward * m_Comp.MinDistance; Vector3 max = Vector3.forward * m_Comp.MaxDistance; // Grid Cells for (int iLat = 0; iLat <= nLat; iLat++) { GL.Begin(GL.LINE_STRIP); GL.Color(s_WireColorA); for (int iLon = 0; iLon <= nLon; iLon++) { var v = wf[iLat, iLon] * max; GL.Vertex3(v.x, v.y, v.z); } GL.End(); } for (int iLon = 0; iLon <= nLon; iLon++) { GL.Begin(GL.LINE_STRIP); GL.Color(s_WireColorA); for (int iLat = 0; iLat <= nLat; iLat++) { var v = wf[iLat, iLon] * max; GL.Vertex3(v.x, v.y, v.z); } GL.End(); } // Angles if (m_Comp.LatAngleSouth < 90) { GL.Begin(GL.LINES); GL.Color(s_WireColorB); for (int iLon = 0; iLon <= nLon; iLon++) { var a = wf[0, iLon] * min; GL.Vertex3(a.x, a.y, a.z); var b = wf[0, iLon] * max; GL.Vertex3(b.x, b.y, b.z); } GL.End(); } if (m_Comp.LatAngleNorth < 90) { GL.Begin(GL.LINES); GL.Color(s_WireColorB); for (int iLon = 0; iLon <= nLon; iLon++) { var a = wf[nLat, iLon] * min; GL.Vertex3(a.x, a.y, a.z); var b = wf[nLat, iLon] * max; GL.Vertex3(b.x, b.y, b.z); } GL.End(); } if (m_Comp.LonAngle < 180) { for (int iLon = 0; iLon <= nLon; iLon += nLon) { GL.Begin(GL.LINES); GL.Color(s_WireColorB); for (int iLat = 0; iLat <= nLat; iLat++) { var a = wf[iLat, iLon] * min; GL.Vertex3(a.x, a.y, a.z); var b = wf[iLat, iLon] * max; GL.Vertex3(b.x, b.y, b.z); } GL.End(); } } GL.PopMatrix(); }
public void AppendRows(int rows) { rowCount += rows; datas = (Quaternion[,])ResizeArray(datas, new int[] { this.rowCount, this.columnCount }); }