public Line3D GetRayFromScreenCoordinates(Position2D position, CameraSceneNode camera) { IntPtr cam = (camera == null ? IntPtr.Zero : camera.Raw); float[] outray = new float[6]; SceneCollisionManager_GetRayFromScreenCoordinates(_raw, position.ToUnmanaged(), cam, outray); return Line3D.FromUnmanaged(outray); }
public override void Collision() { if (node == null) return; if (Render.Scene.ActiveCamera == null) return; Vector3D intersection = new Vector3D(); Triangle3D triangle = new Triangle3D(); Position2D mouse = new Position2D((int)Ox.DataStore.Input.Position[0], (int)Ox.DataStore.Input.Position[1]); Line3D line = Render.Scene.CollisionManager.GetRayFromScreenCoordinates(mouse, Render.Scene.ActiveCamera); bool hit = Render.Scene.CollisionManager.GetCollisionPoint( line, node.TriangleSelector, out intersection, out triangle ); if (hit) { float[] point = Util.ToPositionArrayFromIrrlicht(ref intersection); float length = (float)intersection.DistanceFrom(line.Start); PointData.HitData data = new PointData.HitData(point[0], point[1], point[2], PointData.ObjectType.Ground, ClickActionType.None, length, string.Empty); Ox.DataStore.World.Point.Add(ref data); } }
public override void Collision() { if (Render.Scene.ActiveCamera == null) return; Position2D mouse = new Position2D((int)Ox.DataStore.Input.Position[0], (int)Ox.DataStore.Input.Position[1]); Line3D line = Render.Scene.CollisionManager.GetRayFromScreenCoordinates(mouse, Render.Scene.ActiveCamera); foreach (string key in list.Keys) { if (list[key].Node == null) continue; AnimatedMeshSceneNode node = list[key].Node; Box3D box; Util.CreateBox3DFromNode(node, out box); // Check inside bounding box if (box.IntersectsWithLimitedLine(line)) { Vector3D intersection = new Vector3D(); Triangle3D triangle = new Triangle3D(); Mesh mesh = node.AnimatedMesh.GetMesh(node.CurrentFrame); TriangleSelector ts = Render.Scene.CreateTriangleSelector(mesh, node); bool hit = Render.Scene.CollisionManager.GetCollisionPoint( line, ts, out intersection, out triangle ); if (!hit) continue; ObjectData data; if (!Ox.DataStore.World.SimCollection.TryGetObject(key, out data)) continue; if (!(data is AvatarData)) continue; AvatarData avatarData = data as AvatarData; float[] point = Util.ToPositionArrayFromIrrlicht(ref intersection); float length = (float)intersection.DistanceFrom(line.Start); PointData.HitData hitData = new PointData.HitData( point[0], point[1], point[2], (avatarData.Myself ? PointData.ObjectType.AvatarSelf : PointData.ObjectType.Avatar), ClickActionType.None, length, key ); Ox.DataStore.World.Point.Add(ref hitData); } } }
public void Set(Position2D pos, Dimension2D size) { UpperLeftCorner = pos; LowerRightCorner = new Position2D(pos.X + size.Width, pos.Y + size.Height); }
public GUIElement GetElementFromPoint(Position2D point) { return (GUIElement)NativeElement.GetObject(GuiElem_GetElementFromPoint(_raw, point.ToUnmanaged()), typeof(GUIElement)); }
public void DrawW(string text, Position2D pos, Color color, bool hcenter, bool vcenter, Rect cliprect) { GUIFont_DrawW(_raw, text, pos.ToUnmanaged(), color.ToUnmanaged(), hcenter, vcenter, cliprect.ToUnmanaged()); }
public void MakeColorKey(VideoDriver drv, Position2D colorKeyPixelPos) { drv.MakeColorKeyTexture(this, colorKeyPixelPos); }
public void Draw2DPolygon(Position2D center, float radius, Color color, int vertexCount) { VideoDriver_Draw2DPolygon(_raw, center.ToUnmanaged(), radius, color.ToUnmanaged(), vertexCount); }
public void Draw2DImage(Texture image, Position2D destPos, bool useAlphaChannel) { Draw2DImage(image, destPos, Color.White, useAlphaChannel); }
public void DrawCursor() { if (IsShowCursor == false) return; if (Reference.Viewer.EntityManager.PrimitiveUnderMouse == null) { currentCursorImage = cursorImageNormal; } else { if (Reference.Viewer.MenuManager.Visible || Reference.Viewer.GuiManager.Focused) { currentCursorImage = cursorImageNormal; } else if ((Reference.Viewer.EntityManager.PrimitiveUnderMouse.ClickAction == ClickAction.Sit)) { currentCursorImage = cursorImageChair; } else if ((Reference.Viewer.EntityManager.PrimitiveUnderMouse.Flags & PrimFlags.Touch) != 0) { currentCursorImage = cursorImageHand; } else { currentCursorImage = cursorImageNormal; } } Position2D position; if (currentCursorImage == cursorImageNormal) { position = new Position2D(Reference.Device.CursorControl.Position.X, Reference.Device.CursorControl.Position.Y); } else { position = new Position2D(Reference.Device.CursorControl.Position.X - currentCursorImage.OriginalSize.Width / 2, Reference.Device.CursorControl.Position.Y - currentCursorImage.OriginalSize.Height / 2); } Reference.VideoDriver.Draw2DImage(currentCursorImage, position + Reference.Viewer.CursolOffset, true); }
public GuiManager(Viewer viewer) : base(viewer, -1) { // Cursors stay during the whole lifecycle of this manager cursorImageNormal = Reference.VideoDriver.GetTexture(Util.ApplicationDataDirectory + @"/media/textures/cursor-arrow.png"); cursorImageHand = Reference.VideoDriver.GetTexture(Util.ApplicationDataDirectory + @"/media/textures/cursor-hand.png"); cursorImageChair = Reference.VideoDriver.GetTexture(Util.ApplicationDataDirectory + @"/media/textures/cursor-chair.png"); currentCursorImage = cursorImageNormal; Reference.Viewer.CursolOffset = new Position2D(-1, cursorImageNormal.OriginalSize.Height / 2 + 2); closeButton = Reference.VideoDriver.GetTexture(Util.ApplicationDataDirectory + @"/media/gui/windows/window_close.png"); chatIconPosition = new Position2D(Reference.Viewer.Width - 40 * 4, 4); imageChat = Reference.GUIEnvironment.AddImage(Reference.VideoDriver.GetTexture(Util.ApplicationDataDirectory + @"/media/gui/menu/menu_chat.png"), chatIconPosition, true, parentElement, -1, ""); imageChat.Visible = false; Texture chairTexture = Reference.VideoDriver.GetTexture(Util.ApplicationDataDirectory + @"/media/textures/stand_icon_master.png"); imageChair = Reference.GUIEnvironment.AddButton( new Rect(new Position2D(32, Reference.Viewer.Height - chairTexture.OriginalSize.Height - 32), new Dimension2D(chairTexture.OriginalSize.Width, chairTexture.OriginalSize.Height)), parentElement, (int)GUIElementIDS.STANDUP_BUTTON, ""); imageChair.SetImage(chairTexture); imageChair.UseAlphaChannel = true; imageChair.Visible = false; // timer. timer.Elapsed += FocuseLostTimer; timer.Enabled = false; blinkTimer.Elapsed += BlinkEffectTimer; blinkTimer.Enabled = true; }
private void CheckIconMouseOver(Position2D cursor) { if (cursor.Y <= MENU_HEIGHT && cursor.X > Reference.Viewer.Width - m_menuIcons.Count * (MENU_ICONWIDTH + MENU_SPACING) - MENU_ICONOFFSET_X && cursor.X <= Reference.Viewer.Width - MENU_ICONOFFSET_X) { int hit = (int)Math.Floor((double)(Reference.Viewer.Width - cursor.X - MENU_ICONOFFSET_X) / (double)(MENU_ICONWIDTH + MENU_SPACING)); if (mouseOver != -1 && mouseOver != hit) { m_menuIcons[mouseOver].MouseOver(false); mouseOver = -1; } mouseOver = hit; m_menuIcons[hit].MouseOver(true); } else { if (mouseOver != -1 && m_menuIcons.Count > 0) { m_menuIcons[mouseOver].MouseOver(false); mouseOver = -1; } } }
public bool Click(Position2D cursor) { // Icons are right-aligned 5px from the edge, all being a MENU_ICONWIDTHxMENU_ICONWIDTH image // {----------| 7 | 6 | 4 | 3 | 2 | 1 |} // ... -85 -65 -45 -25 // icon range starts at WindowWidth - iconCnt*MENU_ICONWIDTH+5 if (cursor.Y <= MENU_HEIGHT && cursor.X > Reference.Viewer.Width - m_menuIcons.Count * (MENU_ICONWIDTH + MENU_SPACING) - MENU_ICONOFFSET_X && cursor.X <= Reference.Viewer.Width - MENU_ICONOFFSET_X) { int hit = (int)Math.Floor((double)(Reference.Viewer.Width - cursor.X - MENU_ICONOFFSET_X) / (double)(MENU_ICONWIDTH + MENU_SPACING)); m_menuIcons[hit].Click(); } return (false); }
public bool CheckVisible(Position2D cursor) { if (m_menuBackground == null) return false; if (Reference.Viewer.StateManager.State != State.CONNECTED) return false; if (Reference.Viewer.IsDrawMenu == false) { m_menuVisible = false; m_textVisible = false; return false; } if ((Reference.Viewer.Width - MENU_R_WIDTH - MENU_OFFSET_X) < cursor.X && cursor.X < Reference.Viewer.Width && - 20 < cursor.Y && cursor.Y < (MENU_HEIGHT - MENU_OFFSET_Y)) { CheckIconMouseOver(cursor); m_menuVisible = Reference.Device.WindowActive; } else { m_menuVisible = false; } if (m_textEnabled) { if (0 < cursor.X && cursor.X < MENU_L_WIDTH && -20 < cursor.Y && cursor.Y < MENU_HEIGHT) { m_textVisible = Reference.Device.WindowActive; } else { m_textVisible = false; } m_textBackground.Visible = m_textVisible; } m_menuBackground.Visible = m_menuVisible; return m_textVisible; }
public Rect(Position2D upperLeft, Position2D lowerRight) { UpperLeftCorner = new Position2D(); LowerRightCorner = new Position2D(); Set(upperLeft, lowerRight); }
public void Draw2DImage(Texture image, Position2D destPos) { VideoDriver_Draw2DImageA(_raw, image.Raw, destPos.ToUnmanaged()); }
public void Draw2DImage(Texture image, Position2D destPos, Color color, bool useAlphaChannel) { Draw2DImage(image, destPos, new Rect(new Position2D(0, 0), image.OriginalSize), color, useAlphaChannel); }
/// <summary> /// Translate the mouse position on the screen into a ray in 3D space /// WARNING: cam.ProjectRayPoints seems buggy, use irrlicht CollisionManager.GetSceneNodeFromRay instead /// </summary> /// <param name="mpos"></param> /// <param name="WindowWidth_DIV2"></param> /// <param name="WindowHeight_DIV2"></param> /// <param name="aspect"></param> /// <returns></returns> public Vector3D[] ProjectRayPoints(Position2D mpos, float WindowWidth_DIV2, float WindowHeight_DIV2, float aspect) { Vector3 pos = Vector3.Zero; pos.X = (float)(Math.Tan(SNCamera.FOV * 0.5f) * (mpos.X / WindowWidth_DIV2 - 1.0f)); pos.Y = (float)(Math.Tan(SNCamera.FOV * 0.5f) * (1.0f - mpos.Y / WindowHeight_DIV2) / aspect); Vector3D p1 = new Vector3D(pos.X * SNCamera.NearValue, pos.Y * SNCamera.NearValue, SNCamera.NearValue); Vector3D p2 = new Vector3D(pos.X * SNCamera.FarValue, pos.Y * SNCamera.FarValue, SNCamera.FarValue); // Inverse the view matrix IrrlichtNETCP.Matrix4 viewm = SNCamera.ViewMatrix; viewm.MakeInverse(); p1 = viewm.TransformVect(ref p1); p2 = viewm.TransformVect(ref p2); //m_log.DebugFormat("Ray: <{0},{1},{2}>, <{3},{4},{5}>", p1.X, p1.Y, p1.Z, p2.X, p2.Y, p2.Z); Vector3D[] returnvectors = new Vector3D[2]; returnvectors[0] = p1; returnvectors[1] = p2; return returnvectors; }
public void Draw2DLine(Position2D start, Position2D end, Color color) { VideoDriver_Draw2DLine(_raw, start.ToUnmanaged(), end.ToUnmanaged(), color.ToUnmanaged()); }
public GUIImage AddImage(Texture image, Position2D position, bool useAlphaChannel, GUIElement parent, int id, string text) { IntPtr par = (parent == null ? IntPtr.Zero : parent.Raw); return (GUIImage)NativeElement.GetObject(GuiEnv_AddImageA(_raw, image.Raw, position.ToUnmanaged(), useAlphaChannel, par, id, text), typeof(GUIImage)); }
/// <summary> /// Creates an 1bit alpha channel of the texture based on a pixel position color /// </summary> /// <param name="texture">Input texture that will be modified</param> /// <param name="colorKeyPixelPos">Position of the pixel with the color key</param> public void MakeColorKeyTexture(Texture texture, Position2D colorKeyPixelPos) { VideoDriver_MakeColorKeyTexture(_raw, texture.Raw, colorKeyPixelPos.ToUnmanaged()); }
public static Position2D From(int X, int Y) { Position2D toR = new Position2D(); toR.Set(X, Y); return toR; }
public override void Move (Position2D absolutemovement) { CGE_PVOID_METHODS(_raw, CGE_VOID_METHOD.MOVE, IntPtr.Zero, 0, 0, absolutemovement.ToUnmanaged()); }
private bool FindPositionFromMousePosition(Position2D _mousePosition, out Vector3D _targetPosition, out Triangle3D _triangle) { Vector3D intersection = new Vector3D(); Triangle3D triangle = new Triangle3D(); bool find = false; Line3D line = Reference.SceneManager.CollisionManager.GetRayFromScreenCoordinates(_mousePosition, Reference.SceneManager.ActiveCamera); if (pickSceneNode != null) { find = Reference.SceneManager.CollisionManager.GetCollisionPoint( line, pickSceneNode.TriangleSelector, out intersection, out triangle ); } _targetPosition = intersection; _triangle = triangle; return find; }
public override void Draw() { if (Reference.Viewer.StateManager.State == State.CONNECTED) { Texture tex = Reference.Viewer.GuiManager.TeleportWindowBackground; if (tex != null && fadeAlpha.IsEnd == false) { Position2D pos = new Position2D( Reference.Viewer.Width / 2 - tex.OriginalSize.Width / 2, Reference.Viewer.Height / 2 - tex.OriginalSize.Height / 2 ); Reference.VideoDriver.Draw2DImage(tex, pos, new Color((int)fadeAlpha.Value255, 255, 255, 255), true); } } base.Draw(); }
private void UserAvatarMoveMouse(Position2D _position) { if (Reference.Viewer.GuiManager.Focused) { Reference.Viewer.ProtocolManager.AvatarConnection.Forward = false; return; } // Get target position from mouse cursor position. Vector3D targetPosition = new Vector3D(); Triangle3D triangle = new Triangle3D(); bool find = FindPositionFromMousePosition(_position, out targetPosition, out triangle); if (find == false) { return; } targetPosition.Y = 0; // Get user avatar position. Vector3D userPosition = m_userPosition; //userObject.Node.Position; userPosition.Y = 0; bool isRunLenght = false; // Create target vector. Vector3D targetVec = targetPosition - userPosition; if (targetVec.LengthSQ < (ignoreMoveArea * ignoreMoveArea)) { return; } else { if (targetVec.LengthSQ > (runLength * runLength)) isRunLenght = true; targetVec.Normalize(); } Vector3D baseVector = new Vector3D(0, 0, -1); Vector3D verticalVector = baseVector.CrossProduct(targetVec); bool flipVector = verticalVector.Y > 0; if (flipVector == false) { baseVector = new Vector3D(0, 0, 1); } radHeading = baseVector.DotProduct(targetVec) * div2pi; radHeadingSmoothReset = true; if (flipVector) { radHeading += pi; } UserAvatarRotation(0); Reference.Viewer.ProtocolManager.AvatarConnection.Forward = true; Reference.Viewer.ProtocolManager.AvatarConnection.Run = isRunLenght; }
public void DrawW(string text, Position2D pos, Color color, bool hcenter, bool vcenter) { GUIFont_DrawW(_raw, text, pos.ToUnmanaged(), color.ToUnmanaged(), hcenter, vcenter, null); }
public void UserUpdateMousePosition(Position2D _position) { UserAvatarMoveMouse(_position); }
public virtual void Move(Position2D absolutemovement) { GuiElem_Move(_raw, absolutemovement.ToUnmanaged()); }
public void Draw2DImage(Texture image, Position2D destPos, Rect sourceRect, Color color, bool useAlpha) { VideoDriver_Draw2DImageB(_raw, image.Raw, destPos.ToUnmanaged(), sourceRect.ToUnmanaged(), color.ToUnmanaged(), useAlpha); }