//! Draws hardcoded platern that we start over //! This is a temporary function since land will be migrated to the databse void DrawLandscape() { IPicker3dModel picker3dmodel = RendererFactory.GetPicker3dModel(); int i, iy; // Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_AMBIENT_AND_DIFFUSE, new float[]{(float)rand.GetRandomFloat(0,1), 0.7f, 0.2f, 1.0f}); Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_AMBIENT_AND_DIFFUSE, new float[] { 0.7f, 0.7f, 0.2f, 1.0f }); int iLandCoord = 0; for (iy = -10; iy <= 10; iy++) { for (i = -10; i <= 10; i++) { LandCoords[iLandCoord] = new Vector2(-10.0F + i * 1.0F, -10.0F + iy * 1.0F); picker3dmodel.AddHitTarget(new HitTargetLandCoord(iLandCoord)); graphics.PushMatrix(); graphics.Translate(-10.0F + i * 1.0F, -10.0F + iy * 1.0F, MetaverseClient.GetInstance().fHeight - 0.5); graphics.DrawCube(); graphics.PopMatrix(); iLandCoord++; } } }
void GetDimensions() { TerrainModel terrain = MetaverseClient.GetInstance().worldstorage.terrainmodel; windowwidth = RendererFactory.GetInstance().WindowWidth; windowheight = RendererFactory.GetInstance().WindowHeight; mapwidth = terrain.MapWidth; mapheight = terrain.MapHeight; double mapheightwidthratio = terrain.MapHeight / terrain.MapWidth; minimapwidth = 0; minimapheight = 0; if (mapheightwidthratio > 1) { minimapheight = minimapsize; minimapwidth = (int)(minimapsize / mapheightwidthratio); } else { minimapwidth = minimapsize; minimapheight = (int)(minimapsize * mapheightwidthratio); } }
public void DrawEditHandles(Vector3 entityscale) { // + x graphics.SetMaterialColor(editing3d.GetEditHandleColor(Axis.PosX)); //graphics.SetMaterialColor( new double[]{ 1.0, 0.0, 0.0, 0.5 } ); RendererFactory.GetPicker3dModel().AddHitTarget(new HitTargetEditHandle(Axis.PosX)); graphics.PushMatrix(); graphics.Scale(entityscale); graphics.Rotate(90f, 0f, 1f, 0f); DrawSelectionHandle(); graphics.PopMatrix(); // + y graphics.SetMaterialColor(editing3d.GetEditHandleColor(Axis.PosY)); RendererFactory.GetPicker3dModel().AddHitTarget(new HitTargetEditHandle(Axis.PosY)); graphics.PushMatrix(); graphics.Scale(entityscale); graphics.Rotate(90, 1, 0, 0); DrawSelectionHandle(); graphics.PopMatrix(); // + z graphics.SetMaterialColor(editing3d.GetEditHandleColor(Axis.PosZ)); RendererFactory.GetPicker3dModel().AddHitTarget(new HitTargetEditHandle(Axis.PosZ)); graphics.PushMatrix(); graphics.Scale(entityscale); //Gl.glRotatef( 90, 0, 1, 0 ); DrawSelectionHandle(); graphics.PopMatrix(); }
// pass a pointer to a heightmap // when rendered, x pos will be multiplied by xscale, and y points by yscale public RenderableHeightMap(TerrainView terrainview, TerrainModel terrainmodel, int xscale, int yscale) { this.terrainmodel = terrainmodel; this.terrainview = terrainview; this.heightmap = terrainmodel.Map; width = heightmap.GetLength(0) - 1; height = heightmap.GetLength(1) - 1; this.xscale = xscale; this.yscale = yscale; //maptexturestageviews = terrainview.maptexturestageviews; maptexturestagemodels = terrainmodel.texturestages; // foreach (MapTextureStageView maptexturestageview in maptexturestageviews) // { // viewbymodel.Add( maptexturestageview.maptexturestagemodel, maptexturestageview ); //} CacheChunkTextureStageUsage(); normalsperquad = new Vector3[width, height]; terrain_HeightmapInPlaceEdited(0, 0, width - 1, height - 1); RendererFactory.GetInstance().WriteNextFrameEvent += new WriteNextFrameCallback(Render); terrainmodel.HeightmapInPlaceEdited += new TerrainModel.HeightmapInPlaceEditedHandler(terrain_HeightmapInPlaceEdited); terrainmodel.TerrainModified += new TerrainModel.TerrainModifiedHandler(terrain_TerrainModified); terrainmodel.BlendmapInPlaceEdited += new TerrainModel.BlendmapInPlaceEditedHandler(terrain_BlendmapInPlaceEdited); }
public WorldView(WorldModel worldmodel) { LogFile.WriteLine("WorldView(" + worldmodel + ")"); this.worldmodel = worldmodel; graphics = GraphicsHelperFactory.GetInstance(); terrainview = new TerrainView(worldmodel.terrainmodel); RendererFactory.GetInstance().WriteNextFrameEvent += new WriteNextFrameCallback(WorldView_WriteNextFrameEvent); }
SdlKeyCache() { //Diag.Debug("Instantiating KeyFilterFormsKeyCache()"); IRenderer renderer = RendererFactory.GetInstance(); renderer.KeyDown += new SdlDotNet.KeyboardEventHandler(renderer_KeyDown); renderer.KeyUp += new SdlDotNet.KeyboardEventHandler(renderer_KeyUp); }
public MouseCache() { IRenderer renderer = RendererFactory.GetInstance(); renderer.MouseMotion += new MouseMotionEventHandler(renderer_MouseMotion); renderer.MouseDown += new MouseButtonEventHandler(renderer_MouseDown); renderer.MouseUp += new MouseButtonEventHandler(renderer_MouseUp); }
public void InteractiveFreeEdit(bool bAltAxes, int x, int y) { Entity entity = selectionmodel.GetFirstSelectedEntity(); if (entity == null) { return; } Vector3 OurPos; Rot OurRot; if (camera.bRoamingCameraEnabled) { OurPos = camera.RoamingCameraPos; OurRot = camera.RoamingCameraRot; } else { Avatar ouravatar = MetaverseClient.GetInstance().myavatar; if (ouravatar != null) { OurPos = ouravatar.pos; OurRot = ouravatar.rot; } else { return; } } double HalfWinWidth = RendererFactory.GetInstance().WindowWidth / 2; double HalfWinHeight = RendererFactory.GetInstance().WindowHeight / 2; Vector3 translatevector = new Vector3(); if (bAltAxes) { translatevector = new Vector3( -(( double )(x - editing3d.iDragStartX)) / HalfWinWidth * 3.0, -(( double )(y - editing3d.iDragStartY)) / HalfWinWidth * 3.0, 0 ); } else { translatevector = new Vector3( 0, -((double)(x - editing3d.iDragStartX)) / HalfWinWidth * 3.0, -((double)(y - editing3d.iDragStartY)) / HalfWinWidth * 3.0 ); } Vector3 PosChangeWorldAxes = translatevector * OurRot.Inverse(); entity.pos = editing3d.startpos + PosChangeWorldAxes; MetaverseClient.GetInstance().worldstorage.OnModifyEntity(entity); }
void DrawSingleEditHandle(Vector3 entityscale, Vector3 handlescale, Axis handleaxis) { graphics.PushMatrix(); graphics.SetMaterialColor(editing3d.GetEditHandleColor(handleaxis)); RendererFactory.GetPicker3dModel().AddHitTarget(new HitTargetEditHandle(new Axis(handleaxis))); double fTranslateAmount = (handleaxis.GetAxisComponentIgnoreAxisDirection(entityscale) + handleaxis.GetAxisComponentIgnoreAxisDirection(handlescale)) / 2; graphics.Translate(fTranslateAmount * handleaxis.ToVector()); graphics.Scale(handlescale); graphics.Rotate(handleaxis.ToRot()); graphics.DrawCube(); graphics.PopMatrix(); }
public void InteractiveFreeEdit(int x, int y) { Vector3 OurPos; Rot OurRot; if (camera.bRoamingCameraEnabled) { OurPos = camera.RoamingCameraPos; OurRot = camera.RoamingCameraRot; } else { Avatar ouravatar = MetaverseClient.GetInstance().myavatar; if (ouravatar != null) { OurPos = ouravatar.pos; OurRot = ouravatar.rot; } else { return; } } Rot rInverseOurRot = OurRot.Inverse(); double HalfWinWidth = RendererFactory.GetInstance().WindowWidth / 2; double HalfWinHeight = RendererFactory.GetInstance().WindowHeight / 2; double zRoll = (x - editing3d.iDragStartX) / HalfWinWidth; double yRoll = -(y - editing3d.iDragStartY) / HalfWinHeight; double amount = Math.Sqrt((double)((editing3d.iDragStartX - x) * (editing3d.iDragStartX - x) + (editing3d.iDragStartY - y) * (editing3d.iDragStartY - y))) * mvMath.Pi2 / HalfWinHeight; Vector3 ArcBallAxis = new Vector3(0, yRoll, zRoll); Rot ArcBallRot = mvMath.AxisAngle2Rot(ArcBallAxis, amount); Rot rTransposedToAv = rInverseOurRot * editing3d.startrot; Rot rRotated = ArcBallRot * rTransposedToAv; Rot rNewRot = OurRot * rRotated; selectionmodel.GetFirstSelectedEntity().rot = rNewRot; MetaverseClient.GetInstance().worldstorage.OnModifyEntity(selectionmodel.GetFirstSelectedEntity()); }
public void InitiateScaleEdit(int mousex, int mousey) { EditingPreliminaries(); HitTarget hittarget = RendererFactory.GetPicker3dModel().GetClickedHitTarget(mousex, mousey); //Test.Debug( "Clicked target type: " + hittarget.TargetType ); // Test.Debug if (hittarget is HitTargetEditHandle) { Test.Debug("It's an edit handle :-O"); // Test.Debug editing3dscale.InitiateHandleEdit(mousex, mousey, (( HitTargetEditHandle)hittarget).axis); } else { Test.Debug("Not an edit handle"); // Test.Debug editing3dscale.InitiateFreeEdit(mousex, mousey); } }
public Editing3d() { selectionmodel = SelectionModel.GetInstance(); mousefiltermousecache = MouseCache.GetInstance(); CommandCombos.GetInstance().RegisterCommandGroup( new string[] { CMD_EDITPOSITION, CMD_EDITSCALE, CMD_EDITROTATION }, new KeyCommandHandler(EditModeKeyEvent)); CommandCombos.GetInstance().RegisterAtLeastCommand( "leftmousebutton", new KeyCommandHandler(MouseDown)); mousefiltermousecache.MouseMove += new MouseMoveHandler(MouseMove); editing3dpos = new Editing3dPos(this); editing3drot = new Editing3dRot(this); editing3dscale = new Editing3dScale(this); RendererFactory.GetInstance().WriteNextFrameEvent += new WriteNextFrameCallback(Editing3d_WriteNextFrameEvent); }
//! Feedback line buffer for OpenGL feedback, used by mvgraphics.cpp /* * class FeedbackLineBufferItem * { * public double type; * public Vector2[] vertices = new Vector2[2]; * } */ public Vector3 GetMouseVector(Vector3 OurPos, Rot OurRot, int mousex, int mousey) { IRenderer renderer = RendererFactory.GetInstance(); //Vector3 MouseVectorObserverAxes = new Vector3(-renderer.WindowWidth / 2 + mousex, -renderer.ScreenDistanceScreenCoords, renderer.WindowHeight / 2 - mousey); Vector3 MouseVectorObserverAxes = new Vector3( renderer.ScreenDistanceScreenCoords, renderer.WindowWidth / 2 - mousex, renderer.WindowHeight / 2 - mousey); //LogFile.WriteLine("MouseVectorObserverAxes: " + MouseVectorObserverAxes); MouseVectorObserverAxes.Normalize(); //LogFile.WriteLine("MouseVectorObserverAxes (normalized): " + MouseVectorObserverAxes); Vector3 MouseVectorWorldAxes = MouseVectorObserverAxes * OurRot.Inverse(); //LogFile.WriteLine("MouseVectorWorldAxes: " + MouseVectorWorldAxes.ToString()); MouseVectorWorldAxes.Normalize(); return(MouseVectorWorldAxes); }
// not to self: this is ugly, maybe simplify a little/lot? public Vector3 GetScreenPos(Vector3 ObserverPos, Rot ObserverRot, Vector3 TargetPos3D) { float[] feedbackbuffer = new float[1 * 3]; Gl.glFeedbackBuffer(3, Gl.GL_2D, feedbackbuffer); int[] viewport = new int[4]; // This Sets The Array <viewport> To The Size And Location Of The Screen Relative To The Window Gl.glGetIntegerv(Gl.GL_VIEWPORT, viewport); Gl.glPushMatrix(); Gl.glRenderMode(Gl.GL_FEEDBACK); Gl.glLoadIdentity(); // rotate so z axis is up, and x axis is forward Gl.glRotatef(90f, 0.0f, 0.0f, 1.0f); Gl.glRotatef(90f, 0.0f, 1.0f, 0.0f); Rotate(ObserverRot.Inverse()); Translate(-ObserverPos); Gl.glBegin(Gl.GL_POINTS); Gl.glVertex3f((float)TargetPos3D.x, (float)TargetPos3D.y, (float)TargetPos3D.z); Gl.glEnd(); Gl.glRenderMode(Gl.GL_RENDER); Gl.glPopMatrix(); //DEBUG( "Screencoords of input vertex: " << FeedbackBuffer.Vertices[0].x << " " << FeedbackBuffer.Vertices[0].y ); // DEBUG Vector2 screenpoint = GetFeedbackPointBufferItem(feedbackbuffer, 0); Vector3 ScreenPos = new Vector3( 0, RendererFactory.GetInstance().WindowWidth - screenpoint.x, screenpoint.y ); //DEBUG( "screenpos: " << ScreenPos ); // DEBUG return(ScreenPos); }
//const string CMD_ZOOM = "camerazoom"; //const string CMD_PAN = "camerapan"; //const string CMD_ORBIT = "cameraorbit"; public Camera() { MouseCache mousefiltermousecache = MouseCache.GetInstance(); ViewerState.GetInstance().StateChanged += new ViewerState.StateChangedHandler(Camera_StateChanged); // CommandCombos.GetInstance().RegisterCommandGroup( // new string[]{ CMD_ZOOM, CMD_PAN, CMD_ORBIT }, new KeyCommandHandler(CameraModeHandler)); //CommandCombos.GetInstance().RegisterCommand( // "cameraorbit", new KeyCommandHandler(CameraModeOrbitHandler)); //CommandCombos.GetInstance().RegisterCommand( // "camerapan", new KeyCommandHandler(CamerModePanHandler)); CommandCombos.GetInstance().RegisterAtLeastCommand( "toggleviewpoint", new KeyCommandHandler(ToggleViewpointHandler)); CommandCombos.GetInstance().RegisterAtLeastCommand( "leftmousebutton", new KeyCommandHandler(MouseDown)); MouseCache.GetInstance().MouseMove += new MouseMoveHandler(Camera_MouseMove); RendererFactory.GetInstance().PreDrawEvent += new PreDrawCallback(Camera_PreDrawEvent); }
public void Render() { //LogFile.WriteLine("singlefacedrawer.render"); IRenderer renderer = RendererFactory.GetInstance(); Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT); Gl.glLoadIdentity(); renderer.ApplyViewingMatrices(); for (int i = 0; i < prim.NumFaces; i++) { // LogFile.WriteLine("face " + i); HitTarget thishittarget = new HitTargetEntityFace(prim, i); //LogFile.WriteLine( "Renderering " + thishittarget.ToString() ); Picker3dModelGl.GetInstance().AddHitTarget(thishittarget); if (prim.Parent != null) { (prim.Parent as EntityGroup).ApplyTransforms(); } prim.RenderSingleFace(i); } }
// we want to find out the length something of 1 world unit takes up in screen pixels when it is fDepth away from us // into the screen (along our x axis) // we draw a lines in the world, at depth fDepth (in world axes) // and we use an OpenGl FeedbackBuffer to find out how long that line is on the screen // ( see http://msdn.microsoft.com/library/en-us/opengl/glfunc02_3m42.asp ) public double GetScalingFrom3DToScreen(double fDepth) { return(RendererFactory.GetInstance().ScreenDistanceScreenCoords / fDepth / RendererFactory.GetInstance().NearClip); /* * int iNumLines = 1; * // each line uses five floats in the buffer: * float[] feedbackbuffer = new float[iNumLines * 5]; * * int[] viewport = new int[4]; * // This Sets The Array <viewport> To The Size And Location Of The Screen Relative To The Window * Gl.glGetIntegerv(Gl.GL_VIEWPORT, viewport); * * Gl.glLoadIdentity(); * * RendererFactory.GetInstance().ApplyViewingMatrices(); * * // rotate so z axis is up, and x axis is forward * Gl.glRotatef(90f, 0.0f, 0.0f, 1.0f); * Gl.glRotatef(90f, 0.0f, 1.0f, 0.0f); * * Gl.glFeedbackBuffer(iNumLines * 5, Gl.GL_2D, feedbackbuffer); * Gl.glRenderMode(Gl.GL_FEEDBACK); * * Gl.glBegin(Gl.GL_LINES); * Gl.glVertex3d(fDepth, -0.5, 0); * Gl.glVertex3d(fDepth, 0.5, 0); * Gl.glEnd(); * * int iNumValues = Gl.glRenderMode(Gl.GL_RENDER); * * // A is distance of vector, at depth fDepth in world, in pixels * // Test.WriteOut( feedbackbuffer ); * Vector2 VectorA = GetFeedbackLineBufferItem(feedbackbuffer, 0, 1) - GetFeedbackLineBufferItem(feedbackbuffer, 0, 0); * double A = VectorA.Det(); * * return A; */ }
public void Render() { RendererFactory.GetInstance().DrawWorld(); }
// dependencies: // - RendererFactory.GetInstance() // - Tao.OpenGl public HitTarget GetClickedHitTarget(IRenderable renderable, int MouseX, int MouseY) { GraphicsHelperGl g = new GraphicsHelperGl(); g.CheckError(); IRenderer renderer = RendererFactory.GetInstance(); ArrayList results = new ArrayList(); int[] viewport = new int[4]; Gl.glGetIntegerv(Gl.GL_VIEWPORT, viewport); g.CheckError(); CreateSelectBuffer(); g.CheckError(); // This Creates A Matrix That Will Zoom Up To A Small Portion Of The Screen, Where The Mouse Is. Gl.glMatrixMode(Gl.GL_PROJECTION); g.CheckError(); Gl.glPushMatrix(); // save old matrix, we restore it at end g.CheckError(); Gl.glLoadIdentity(); g.CheckError(); Glu.gluPickMatrix((float)MouseX, (float)(renderer.WindowHeight - MouseY), 1.0f, 1.0f, viewport); g.CheckError(); Glu.gluPerspective(renderer.FieldOfView, (float)renderer.WindowWidth / (float)renderer.WindowHeight, renderer.NearClip, renderer.FarClip); g.CheckError(); Gl.glMatrixMode(Gl.GL_MODELVIEW); g.CheckError(); Gl.glRenderMode(Gl.GL_SELECT); g.CheckError(); Gl.glInitNames(); g.CheckError(); Gl.glPushName(0); // Push one entry onto the stack; we will use LoadName to change this value throughout the rendering g.CheckError(); bAddingNames = true; hittargets = new ArrayList(); renderable.Render(); bAddingNames = false; // return projection matrix to normal Gl.glMatrixMode(Gl.GL_PROJECTION); Gl.glPopMatrix(); Gl.glMatrixMode(Gl.GL_MODELVIEW); int iNumHits = Gl.glRenderMode(Gl.GL_RENDER); int hitname = GetNearestBufferName(iNumHits); LogFile.WriteLine("hitname: " + hitname.ToString()); if (hitname == -1 || hitname == 0) { LogFile.WriteLine("not in buffer"); return(null); } FreeSelectBuffer(); new GraphicsHelperGl().CheckError(); if (hittargets.Count == 0) { return(null); } if (iNumHits == 0) { //LogFile.WriteLine("no hits"); return(null); } //LogFile.WriteLine(hittargets[hitname - 1]); return((HitTarget)hittargets[hitname - 1]); }
public void _InteractiveFreeScaleEdit_Old(bool bAltAxes, int x, int y) { Vector3 OurPos = null; Rot OurRot = null; if (camera.bRoamingCameraEnabled) { OurPos = camera.RoamingCameraPos; OurRot = camera.RoamingCameraRot; } else { Avatar ouravatar = MetaverseClient.GetInstance().myavatar; if (ouravatar != null) { OurPos = ouravatar.pos; OurRot = ouravatar.rot; } else { return; } } Rot rInverseOurRot = OurRot.Inverse(); Entity entity = selectionmodel.GetFirstSelectedEntity(); // DEBUG( "interactive scale edit objectype=[" << World.GetEntity( iSelectedArrayNum ).EntityType << "]" ); // DEBUG double HalfWinWidth = RendererFactory.GetInstance().WindowWidth / 2; double HalfWinHeight = RendererFactory.GetInstance().WindowHeight / 2; Vector3 ScaleAvAxes = null; if (bAltAxes) { ScaleAvAxes = new Vector3( -((double)(y - editing3d.iDragStartY)) / HalfWinWidth * 1.0, ((double)(x - editing3d.iDragStartX)) / HalfWinWidth * 1.0, 0 ); } else { ScaleAvAxes = new Vector3( 0, ((double)(x - editing3d.iDragStartX)) / HalfWinWidth * 1.0, -((double)(y - editing3d.iDragStartY)) / HalfWinWidth * 1.0 ); } Vector3 CurrentScaleWorldAxes = editing3d.startscale * entity.rot.Inverse(); Vector3 CurrentScaleAvatarAxes = CurrentScaleWorldAxes * entity.rot; Vector3 ScaleNewScaleAvAxes = new Vector3( (1 + ScaleAvAxes.x) * CurrentScaleAvatarAxes.x, (1 + ScaleAvAxes.y) * CurrentScaleAvatarAxes.y, (1 + ScaleAvAxes.z) * CurrentScaleAvatarAxes.z ); Vector3 NewScaleWorldAxes = ScaleNewScaleAvAxes * rInverseOurRot; Vector3 NewScaleSeenByPrim = NewScaleWorldAxes * entity.rot; if (NewScaleSeenByPrim.x < 0) { NewScaleSeenByPrim.x = 0.05; } if (NewScaleSeenByPrim.y < 0) { NewScaleSeenByPrim.y = 0.05; } if (NewScaleSeenByPrim.z < 0) { NewScaleSeenByPrim.z = 0.05; } entity.scale = NewScaleSeenByPrim; // DEBUG( "setting new scale " << NewScaleSeenByPrim ); // DEBUG }
public CurrentEditSpot() { RendererFactory.GetInstance().WriteNextFrameEvent += new WriteNextFrameCallback(CurrentEditSpot_WriteNextFrameEvent); //Terrain.GetInstance().renderableminimap.Render += new RenderableMinimap.RenderHandler(renderableminimap_Render); }
double GetRotationAngleForEntityAndMouse(Vector3 EntityVector3, Rot EntityRot, Axis axis, int mousex, int mousey) { double fRotationAngle = 0; bool bRotAngleGot = false; Vector3 OurPos; Rot OurRot; if (camera.bRoamingCameraEnabled) { OurPos = camera.RoamingCameraPos; OurRot = camera.RoamingCameraRot; } else { Avatar ouravatar = MetaverseClient.GetInstance().myavatar; if (ouravatar != null) { OurPos = ouravatar.pos; OurRot = ouravatar.rot; } else { return(0); } } Rot rInverseOurRot = OurRot.Inverse(); double fDistanceFromUsToEntity = (EntityVector3 - OurPos).Det(); double fScalingFromPosToScreen = graphics.GetScalingFrom3DToScreen(fDistanceFromUsToEntity); Vector3 ScreenEntityPos = graphics.GetScreenPos(OurPos, OurRot, EntityVector3); Vector3 ScreenMousePos = new Vector3( 0, RendererFactory.GetInstance().WindowWidth - mousex, RendererFactory.GetInstance().WindowHeight - mousey); // mousepoint is a point on the mouseray into the screen, with x = entity.pos.x Vector3 ScreenVectorEntityToMousePoint = ScreenMousePos - ScreenEntityPos; Vector3 VectorEntityToMousePointObserverAxes = ScreenVectorEntityToMousePoint * (1.0f / fScalingFromPosToScreen); //Test.Debug( " screenobjectpos: " + ScreenEntityPos + " screenmousepos: " + ScreenMousePos + " objecttomouse: " + ScreenVectorEntityToMouse ); // Test.Debug Vector3 RotationAxisEntityAxes = axis.ToVector(); Rot rInverseEntityRot = EntityRot.Inverse(); Vector3 RotationAxisWorldAxes = RotationAxisEntityAxes * rInverseEntityRot; // Test.Debug( " RotationAxisWorldAxes " + RotationAxisWorldAxes ); // Test.Debug Vector3 RotationAxisObserverAxes = RotationAxisWorldAxes * OurRot; RotationAxisObserverAxes.Normalize(); double DistanceOfRotationPlaneFromOrigin = 0; // Lets move right up to the object // we're going to imagine a ray from the MousePoint going down the XAXIS, away from us // we'll intersect this ray with the rotation plane to get the point on the rotation plane // where we can consider the mouse to be. double fVectorDotRotationAxisObserverAxesWithXAxis = Vector3.DotProduct(RotationAxisObserverAxes, mvMath.XAxis); if (Math.Abs(fVectorDotRotationAxisObserverAxesWithXAxis) > 0.0005) { double fDistanceFromMousePointToRotationPlane = (DistanceOfRotationPlaneFromOrigin - Vector3.DotProduct(RotationAxisObserverAxes, VectorEntityToMousePointObserverAxes)) / fVectorDotRotationAxisObserverAxesWithXAxis; // Test.Debug( " fDistanceFromMousePointToRotationPlane " + fDistanceFromMousePointToRotationPlane ); // Test.Debug Vector3 VectorMouseClickOnRotationPlaneObserverAxes = new Vector3( fDistanceFromMousePointToRotationPlane, VectorEntityToMousePointObserverAxes.y, VectorEntityToMousePointObserverAxes.z); // Test.Debug( " VectorMouseClickOnRotationPlaneObserverAxes " + VectorMouseClickOnRotationPlaneObserverAxes ); // Test.Debug // We'll rotate this vector into object axes Vector3 VectorMouseClickOnRotationPlaneWorldAxes = VectorMouseClickOnRotationPlaneObserverAxes * rInverseOurRot; Vector3 VectorMouseClickOnRotationPlaneEntityAxes = VectorMouseClickOnRotationPlaneWorldAxes * EntityRot; // Test.Debug( " VectorMouseClickOnRotationPlaneEntityAxes " + VectorMouseClickOnRotationPlaneEntityAxes ); // Test.Debug // now we work out rotation angle double fDistanceOfPointFromOrigin; if (axis.IsXAxis) { fDistanceOfPointFromOrigin = Math.Sqrt(VectorMouseClickOnRotationPlaneEntityAxes.z * VectorMouseClickOnRotationPlaneEntityAxes.z + VectorMouseClickOnRotationPlaneEntityAxes.y * VectorMouseClickOnRotationPlaneEntityAxes.y); // Test.Debug( "Z axis distnace of point from origin: " + fDistanceOfPointFromOrigin ); // Test.Debug if (Math.Abs(fDistanceOfPointFromOrigin) > 0.0005) { fRotationAngle = -Math.Asin(VectorMouseClickOnRotationPlaneEntityAxes.y / fDistanceOfPointFromOrigin); if (VectorMouseClickOnRotationPlaneEntityAxes.z < 0) { fRotationAngle = mvMath.Pi - fRotationAngle; } // Test.Debug( "************RotANGLE: " + fRotationAngle ); // Test.Debug bRotAngleGot = true; } } else if (axis.IsYAxis) { fDistanceOfPointFromOrigin = Math.Sqrt(VectorMouseClickOnRotationPlaneEntityAxes.z * VectorMouseClickOnRotationPlaneEntityAxes.z + VectorMouseClickOnRotationPlaneEntityAxes.x * VectorMouseClickOnRotationPlaneEntityAxes.x); // Test.Debug( "Z axis distnace of point from origin: " + fDistanceOfPointFromOrigin ); // Test.Debug if (Math.Abs(fDistanceOfPointFromOrigin) > 0.0005) { fRotationAngle = Math.Asin(VectorMouseClickOnRotationPlaneEntityAxes.x / fDistanceOfPointFromOrigin); if (VectorMouseClickOnRotationPlaneEntityAxes.z < 0) { fRotationAngle = mvMath.Pi - fRotationAngle; } // Test.Debug( "************RotANGLE: " + fRotationAngle ); // Test.Debug bRotAngleGot = true; } } else { fDistanceOfPointFromOrigin = Math.Sqrt(VectorMouseClickOnRotationPlaneEntityAxes.x * VectorMouseClickOnRotationPlaneEntityAxes.x + VectorMouseClickOnRotationPlaneEntityAxes.y * VectorMouseClickOnRotationPlaneEntityAxes.y); // Test.Debug( "Z axis distnace of point from origin: " + fDistanceOfPointFromOrigin ); // Test.Debug if (Math.Abs(fDistanceOfPointFromOrigin) > 0.0005) { fRotationAngle = Math.Asin(VectorMouseClickOnRotationPlaneEntityAxes.y / fDistanceOfPointFromOrigin); if (VectorMouseClickOnRotationPlaneEntityAxes.x < 0) { fRotationAngle = mvMath.Pi - fRotationAngle; } // Test.Debug( "************RotANGLE: " + fRotationAngle ); // Test.Debug bRotAngleGot = true; } } } if (bRotAngleGot) { //fRotationAngle = fRotAngle; return(fRotationAngle); } else { return(0); } }
public BrushShapeController() { RendererFactory.GetInstance().WriteNextFrameEvent += new WriteNextFrameCallback(BrushShapeController_WriteNextFrameEvent); }
public int Init(IConfigSource commandlineConfig, IClientControllers controllers) { Type type = Type.GetType("OSMP.ObjectReplicationClientToServer"); LogFile.WriteLine("type: [" + type + "] " + type.AssemblyQualifiedName); //System.Environment.Exit( 0 ); Tao.DevIl.Il.ilInit(); Tao.DevIl.Ilu.iluInit(); config = Config.GetInstance(); string serverip = commandlineConfig.Configs["CommandLineArgs"].GetString("serverip", config.ServerIPAddress); int port = commandlineConfig.Configs["CommandLineArgs"].GetInt("serverport", config.ServerPort); network = new NetworkLevel2Controller(); network.NewConnection += new Level2NewConnectionHandler(network_NewConnection); network.ConnectAsClient(serverip, port); rpc = new RpcController(network); netreplicationcontroller = new NetReplicationController(rpc); renderer = RendererFactory.GetInstance(); renderer.Tick += new OSMP.TickHandler(MainLoop); renderer.Init(); worldstorage = new WorldModel(netreplicationcontroller); worldview = new WorldView(worldstorage); playermovement = PlayerMovement.GetInstance(); InitializePlayermovement(); myavatar = new Avatar(); worldstorage.AddEntity(myavatar); controllers.Plugin.LoadClientPlugins(); if (!commandlineConfig.Configs["CommandLineArgs"].Contains("nochat")) { LoadChat(); } if (commandlineConfig.Configs["CommandLineArgs"].Contains("url")) { string url = commandlineConfig.Configs["CommandLineArgs"].GetString("url"); LogFile.WriteLine("url: " + url); if (url.StartsWith("osmp://")) { targettoload = "http://" + url.Substring("osmp://".Length); LogFile.WriteLine("target: " + targettoload); } else { targettoload = url; } } renderer.StartMainLoop(); return(0); }
public FrustrumCulling() { //RendererSdl.GetInstance().WriteNextFrameEvent += new WriteNextFrameCallback(FrustrumCulling_WriteNextFrameEvent); RendererFactory.GetInstance().PreDrawEvent += new PreDrawCallback(FrustrumCulling_PreDrawEvent); //SetupFrustrum(); }
void SetupFrustrum() { //LogFile.WriteLine("setup frustrum"); camerapos = Camera.GetInstance().CameraPos; camerarot = Camera.GetInstance().CameraRot; Rot inversecamerarot = camerarot.Inverse(); //viewray = -mvMath.YAxis * inversecamerarot; //viewray.Normalize(); //right = mvMath.XAxis * inversecamerarot; //up = mvMath.ZAxis * inversecamerarot; //right.Normalize(); //up.Normalize(); viewray = mvMath.XAxis * inversecamerarot; viewray.Normalize(); right = -mvMath.YAxis * inversecamerarot; up = mvMath.ZAxis * inversecamerarot; right.Normalize(); up.Normalize(); nearclip = RendererFactory.GetInstance().NearClip; farclip = RendererFactory.GetInstance().FarClip; VNear = 2 * Math.Tan(RendererFactory.GetInstance().FieldOfView / 2 * Math.PI / 180) * nearclip; VFar = VNear * farclip / nearclip; HNear = VNear * (double)RendererFactory.GetInstance().OuterWindowWidth / RendererFactory.GetInstance().OuterWindowHeight; HFar = HNear * farclip / nearclip; //Console.WriteLine( "clips: " + nearclip + " " + farclip + " " + VNear + " " + VFar + " " + HNear + " " + HFar ); fc = camerapos + viewray * farclip; ftl = fc + (up * VFar / 2) - (right * HFar / 2); ftr = fc + (up * VFar / 2) + (right * HFar / 2); fbl = fc - (up * VFar / 2) - (right * HFar / 2); fbr = fc - (up * VFar / 2) + (right * HFar / 2); nc = camerapos + viewray * nearclip; ntl = nc + (up * VNear / 2) - (right * HNear / 2); ntr = nc + (up * VNear / 2) + (right * HNear / 2); nbl = nc - (up * VNear / 2) - (right * HNear / 2); nbr = nc - (up * VNear / 2) + (right * HNear / 2); // note: all normals point outwards planes[0] = new Plane(-viewray, nc); planes[1] = new Plane(viewray, fc); Vector3 vectoralongplane; Vector3 normal; vectoralongplane = (ntr - camerapos).Normalize(); normal = (up * vectoralongplane).Normalize(); planes[2] = new Plane(-normal, camerapos); vectoralongplane = (nbr - camerapos).Normalize(); normal = (right * vectoralongplane).Normalize(); planes[3] = new Plane(-normal, camerapos); vectoralongplane = (nbl - camerapos).Normalize(); normal = -(up * vectoralongplane).Normalize(); planes[4] = new Plane(-normal, camerapos); vectoralongplane = (ntl - camerapos).Normalize(); normal = -(right * vectoralongplane).Normalize(); planes[5] = new Plane(-normal, camerapos); }
public DrawAxes() { RendererFactory.GetInstance().WriteNextFrameEvent += new WriteNextFrameCallback(renderer_WriteNextFrameEvent); }
public RenderableWater(Vector3 pos, Vector2 scale) { this.pos = pos; this.scale = scale; RendererFactory.GetInstance().WriteAlpha += new WriteNextFrameCallback(RenderableWater_WriteNextFrameEvent); }