/// <summary> /// Create a copy of the point cloud in the current buffer. /// </summary> /// <param name="iLockWait">The amount of time to wait before giving up. The buffer might be locked.</param> /// <returns>A copy of the data in the current buffer.</returns> public SlimMath.Vector3[] CopyPointCloud(int iLockWait = 100) { // Bail if we are not active. if (!IsActive) { return(null); } // Attempt to get a lock if (pPointCloud.TryLockCurrent(iLockWait)) { // Take the first n values (i.e. the valid ones) from this point cloud. var tCopy = new SlimMath.Vector3[pPointCloud.Current.First]; Array.Copy(pPointCloud.Current.Second, tCopy, tCopy.Length); // Unlock the buffer. pPointCloud.UnlockCurrent(); // Return success! return(tCopy); } // Nothing to do so return. return(null); }
/// <summary> /// Convert a SlimDX coordiante into a JSObject. /// </summary> /// <remarks>X,Y,Z becomes x,y,z</remarks> /// <param name="tCoordinate">The SlimMath Vector3 to convert.</param> /// <returns>The instance JSObject with properties in the format { x : N, y : N, z : N } where N is the input coordinate.</returns> public static JSObject StoreCoordinate(this JSObject pCoord, SlimMath.Vector3 tCoordinate) { pCoord["x"] = tCoordinate.X; pCoord["y"] = tCoordinate.Y; pCoord["z"] = tCoordinate.Z; return(pCoord); }
internal Actor CreateActor <T>(SlimMath.Vector3 position, SlimMath.Quaternion rotation) where T : ActorDefinition, new() { var nActor = new Actor(new T(), context); nActor.position = position; nActor.rotation = rotation; var fnull = actors.FindIndex(a => a == null); if (fnull != -1) { nActor.Id = (ushort)fnull; actors[fnull] = nActor; } else { if (actors.Count > ushort.MaxValue) { log.Error("Cannot have more than {0} actors at any given time", ushort.MaxValue); return(null); } nActor.Id = (ushort)actors.Count; actors.Add(nActor); } return(nActor); }
/// <summary> /// Get the 3D point from the UI image given coordinates in the depth image. /// </summary> /// <remarks>This will throw an exception if x and y are out of bounds.</remarks> /// <param name="x">The x-coordinate of the image.</param> /// <param name="y">The y-coordinate of the image.</param> /// <returns>The 3D point at that location.</returns> public SlimMath.Vector3 ImageTo3DDepth(int x, int y) { // Bail if we are not active. if (!IsActive) { throw new Exception("Cannot access data before Kinect is started."); } // Create spmewhere to put the data. var vPoint = new SlimMath.Vector3(); // Get the 3D point from the index to the image. var idx = x + (y * iDepthWidth); // Acquire the index buffer lock. mIndexLock.WaitOne(); // If we have an error. if (idx < 0 || idx >= (iDepthWidth * iDepthHeight)) { mIndexLock.ReleaseMutex(); throw new ArgumentOutOfRangeException("Cannot access 3D depth at image point (" + x + "," + y + "). Out of bounds."); } // Copy the point. vPoint.X = tDepthToSkeleton[idx].X; vPoint.Y = tDepthToSkeleton[idx].Y; vPoint.Z = tDepthToSkeleton[idx].Z; // Release the lock. mIndexLock.ReleaseMutex(); // Return the 3D depth. return(vPoint); }
Actor spawnActor(Player owner, ushort playerId, int prefabId, SlimMath.Vector3 position) { Actor actor; ushort actorId; bool hasOwner = owner != null; if (!actorIdPool.Acquire(out actorId)) { log.Error("Can't spawn actor, failed to acquire a new actor id"); return(null); } if (hasOwner && owner.Connection == null) { log.Error("Owner supplied, but it has no connection object"); return(null); } Network.IConnection connection = hasOwner ? owner.Connection : null; if (Context.InstantiateActor(connection, prefabId, actorId, playerId, position, out actor)) { if (hasOwner) { owner.OwnedActors.Add(actor); } return(actor); } return(null); }
internal static GameObject CreateGameObject(SlimMath.Vector3 position, SlimMath.Quaternion rotation) { var gameObject = new GameObject { Position = position, Rotation = rotation }; return(gameObject); }
/// <summary> /// Convert a SlimDX coordiante into a JSObject. /// </summary> /// <remarks>X,Y,Z becomes x,y,z</remarks> /// <param name="tCoordinate">The SlimMath Vector3 to convert.</param> /// <returns>A JSObject of the format { x : N, y : N, z : N } where N is the input coordinate.</returns> public static JSObject MakeCoordinate(SlimMath.Vector3 tCoordinate) { var pCoord = new JSObject(); pCoord["x"] = tCoordinate.X; pCoord["y"] = tCoordinate.Y; pCoord["z"] = tCoordinate.Z; return(pCoord); }
public Actor SpawnActor <T>(SlimMath.Vector3 position) where T : ActorDefinition { ActorDefinition definition; if (ActorDefinition.ByType(typeof(T), out definition)) { return(spawnActor(null, Player.ServerPlayerId, definition.Id, position)); } else { log.Warn("No actor definition of type {0} found", typeof(T)); return(null); } }
public Actor SpawnActor <T>(Player player, SlimMath.Vector3 position) where T : ActorDefinition { if (Verify.Authenticated(player)) { ActorDefinition definition; if (ActorDefinition.ByType(typeof(T), out definition)) { return(spawnActor(player, player.Id, definition.Id, position)); } else { log.Warn("No actor definition of type {0} found", typeof(T)); return(null); } } return(null); }
/// <summary> /// Apply a rotation transformation to a given Vertex. /// </summary> /// <param name="vertex">The given vertex</param> /// <param name="focalPoint">The point to rotate around</param> /// <param name="rotation">The rotation to apply (in radians)</param> /// <returns>The transformed vertex</returns> public static Vertex VertexRotateRadianTransform(Vertex vertex, Vertex focalPoint, Vertex rotation) { //Convert to SlimMath Vectors SlimMath.Vector3 vector = Convert.VertexToSlimMathVector3( vertex); SlimMath.Vector3 focalPointV = Convert.VertexToSlimMathVector3( focalPoint); SlimMath.Vector3 rotationV = Convert.VertexToSlimMathVector3( rotation); SlimMath.Matrix transform = SlimMath.Matrix.Identity; transform.TranslationVector = vector; transform *= SlimMath.Matrix.Translation(focalPointV * -1); transform *= SlimMath.Matrix.RotationX(rotationV.X); transform *= SlimMath.Matrix.RotationY(rotationV.Y); transform *= SlimMath.Matrix.RotationZ(rotationV.Z); transform *= SlimMath.Matrix.Translation(focalPointV); return(Convert.SlimMathVector3ToVertex(transform.TranslationVector)); }
public static Vertex SlimMathVector3ToVertex(SlimMath.Vector3 vector) { return(new Vertex(vector.X, vector.Y, vector.Z)); }
public static UnityEngine.Vector3 Convert(SlimMath.Vector3 v) { return(new UnityEngine.Vector3(v.X, v.Y, v.Z)); }
/// <summary> /// Create a copy of the point cloud in the current buffer. /// </summary> /// <param name="iLockWait">The amount of time to wait before giving up. The buffer might be locked.</param> /// <returns>A copy of the data in the current buffer.</returns> public SlimMath.Vector3[] CopyPointCloud(int iLockWait = 100) { // Bail if we are not active. if (!IsActive) return null; // Attempt to get a lock if (pPointCloud.TryLockCurrent(iLockWait)) { // Take the first n values (i.e. the valid ones) from this point cloud. var tCopy = new SlimMath.Vector3[pPointCloud.Current.First]; Array.Copy(pPointCloud.Current.Second, tCopy, tCopy.Length); // Unlock the buffer. pPointCloud.UnlockCurrent(); // Return success! return tCopy; } // Nothing to do so return. return null; }
/// <summary> /// Get the 3D point from the UI image given coordinates in the depth image. /// </summary> /// <remarks>This will throw an exception if x and y are out of bounds.</remarks> /// <param name="x">The x-coordinate of the image.</param> /// <param name="y">The y-coordinate of the image.</param> /// <returns>The 3D point at that location.</returns> public SlimMath.Vector3 ImageTo3DDepth(int x, int y) { // Bail if we are not active. if (!IsActive) throw new Exception("Cannot access data before Kinect is started."); // Create spmewhere to put the data. var vPoint = new SlimMath.Vector3(); // Get the 3D point from the index to the image. var idx = x + (y * iDepthWidth); // Acquire the index buffer lock. mIndexLock.WaitOne(); // If we have an error. if (idx < 0 || idx >= (iDepthWidth*iDepthHeight)) { mIndexLock.ReleaseMutex(); throw new ArgumentOutOfRangeException("Cannot access 3D depth at image point ("+x+","+y+"). Out of bounds."); } // Copy the point. vPoint.X = tDepthToSkeleton[idx].X; vPoint.Y = tDepthToSkeleton[idx].Y; vPoint.Z = tDepthToSkeleton[idx].Z; // Release the lock. mIndexLock.ReleaseMutex(); // Return the 3D depth. return vPoint; }
/// <summary> /// Writes a Vector3 /// </summary> public void Write(SlimMath.Vector3 value) { Write(value.X); Write(value.Y); Write(value.Z); }
/// <summary> /// Initializes a new instance of the <see cref="GorgonColor"/> struct. /// </summary> /// <param name="color">The 3D vector to convert to a color.</param> public GorgonColor(Vector3 color) : this(color.X, color.Y, color.Z, 1.0f) { }