예제 #1
0
        public void CalculateDimensions()
        {
            float minX = float.MaxValue, minY = float.MaxValue, minZ = float.MaxValue;
            float maxX = float.MinValue, maxY = float.MinValue, maxZ = float.MinValue;
            float avgX = 0, avgY = 0, avgZ = 0;

            foreach (var v in Vertices)
            {
                minX = Math.Min(minX, v.Position.X);
                minY = Math.Min(minY, v.Position.Y);
                minZ = Math.Min(minZ, v.Position.Z);

                maxX = Math.Max(maxX, v.Position.X);
                maxY = Math.Max(maxY, v.Position.Y);
                maxZ = Math.Max(maxZ, v.Position.Z);

                avgX += v.Position.X;
                avgY += v.Position.Y;
                avgZ += v.Position.Z;
            }
            Min    = new Vector3(minX, minY, minZ);
            Max    = new Vector3(maxX, maxY, maxZ);
            Center = new Vector3(avgX, avgY, avgZ) / Vertices.Length;
            Radius = Math.Max(
                VectorMath.Distance(Center, Min),
                VectorMath.Distance(Center, Max)
                );
        }
예제 #2
0
        /// <inheritdoc />
        public void Render(Matrix4 viewMatrix, Matrix4 projectionMatrix, ViewportCamera camera)
        {
            if (!this.IsInitialized)
            {
                return;
            }

            this.Shader.Wireframe.Enabled = this.ShouldRenderWireframe;
            if (this.Shader.Wireframe.Enabled)
            {
                this.Shader.Wireframe.SetViewportMatrix(camera.GetViewportMatrix());
            }

            Matrix4 modelView           = this.ActorTransform.GetModelMatrix() * viewMatrix;
            Matrix4 modelViewProjection = modelView * projectionMatrix;

            // TODO: Fix frustum culling
            foreach (ModelGroup modelGroup in this.Model.Groups
                     .OrderByDescending(modelGroup => VectorMath.Distance(camera.Position, modelGroup.GetPosition().AsOpenTKVector())))
            {
                RenderGroup(modelGroup, modelViewProjection);

                if (this.ShouldRenderBounds)
                {
                    // Now, draw the model's bounding box

                    // Transform the bounding box into world space
                    BoundingBox groupBoundingBox = modelGroup.GetBoundingBox().ToOpenGLBoundingBox().Transform(ref modelView);
                    if (camera.CanSee(groupBoundingBox))
                    {
                        // continue;
                        RenderBoundingBox(modelGroup, modelViewProjection, Color4.LimeGreen);
                    }
                    else
                    {
                        RenderBoundingBox(modelGroup, modelViewProjection, Color4.Red);
                    }
                }
            }

            // TODO: Summarize the render batches from each group that has the same material ID

            // TODO: Render each block of batches with the same material ID

            // TODO: Shade light effects and vertex colours

            // TODO: Render each doodad in the currently selected doodad set

            // TODO: Play sound emitters here?
        }
예제 #3
0
 public override float ScaledDistance(Vector3 point)
 {
     return(VectorMath.Distance(Zone.Position, point) / Radius);
 }
예제 #4
0
        public void Update(SceneContext c, GameTime gt)
        {
            if (c.IsFlagSetOR(GameFlagMask.CROSSHAIR_HIDE_MASK))
            {
                pj.WorldAnchorB = this.FocusedEntity.Mesh.Body.Position;
                return;
            }



            float dx = 0;
            float dy = 0;

            //InputConfig ic = InputConfig.Instance;
            //if (ic.RIGHT_AXIS.WasMoved)
            //{
            //    dx = ic.RIGHT_AXIS.DX;
            //    dy = ic.RIGHT_AXIS.DY;
            //}
            //else
            //{
            //    dx = ic.MOUSE.DX;
            //    dy = ic.MOUSE.DY;
            //}


            foreach (Axis a in this.ListeningAxis)
            {
                if (a.WasMoved)
                {
                    dx = a.DX;
                    dy = a.DY;
                    break;
                }
            }

            //   // Ray berechnen -> das ist die richtung/bahn auf der projektiele fliegen werden -> wird vom offsetpunkt an berechnet
            CursorDirection = this.FocusedEntity.Mesh.Body.Position - this.Sensor.Position; //Vector2.Subtract(actorData.RightHandOffset, new Vector2(this.X, this.Y));
            CursorDirection.Normalize();
            CursorDirection = Vector2.Negate(CursorDirection);


            // player rotation setzen
            float bodyAngle = this.FocusedEntity.Mesh.Body.Rotation;

            float desiredAngle = -VectorMath.GetAngle(CursorDirection);



            float speed = this.FocusedEntity.GetAttribute <ActorDataAttribute>().RotationSpeed;

            /// source: http://www.iforce2d.net/b2dtut/rotate-to-angle
            float nextAngle     = bodyAngle + this.FocusedEntity.Mesh.Body.AngularVelocity / speed;
            float totalRotation = desiredAngle - nextAngle;

            while (totalRotation < -180 * DEGTORAD)
            {
                totalRotation += 360 * DEGTORAD;
            }
            while (totalRotation > 180 * DEGTORAD)
            {
                totalRotation -= 360 * DEGTORAD;
            }
            float desiredAngularVelocity = totalRotation * speed;

            float torque = this.FocusedEntity.Mesh.Body.Inertia * desiredAngularVelocity / (1 / speed);

            this.FocusedEntity.Mesh.Body.ApplyTorque(torque);


            // position:
            this.relativePos -= ConvertUnits.ToSimUnits(new Vector2(dx, dy) * CursorSensitivity);

            if (VectorMath.Distance(new Vector2(), this.relativePos) >= ConvertUnits.ToSimUnits(this.CursorRange))
            {
                //nicht die ray nemen, sondern vom mittelpunkt des spielers ausgehen
                Vector2 rangeDir = this.relativePos;
                rangeDir.Normalize();

                this.relativePos = rangeDir * ConvertUnits.ToSimUnits(this.CursorRange);
            }

            pj.WorldAnchorB = this.FocusedEntity.Mesh.Body.Position + this.relativePos;


            foreach (ICrosshairDrawableProcessor dp in this.drawableProcessor)
            {
                dp.Update(c, gt);
            }

            // Update Tool
            if (this.SelectedTool != null)
            {
                if (this.PrimaryAction.WasPressed)
                {
                    this.SelectedTool.OnPrimaryDown(c);
                }

                if (this.PrimaryAction.WasReleased)
                {
                    this.SelectedTool.OnPrimaryUp(c);
                }

                if (this.SecondaryAction.WasPressed)
                {
                    this.SelectedTool.OnSecondaryDown(c);
                }

                if (this.SecondaryAction.WasReleased)
                {
                    this.SelectedTool.OnSecondaryUp(c);
                }

                this.SelectedTool.Update(c, gt);
            }
        }
예제 #5
0
 public override float ScaledDistance(Vector3 point)
 {
     return(VectorMath.Distance(point, centre) / Radius);
 }
예제 #6
0
        public override float ScaledDistance(Vector3 point)
        {
            var max = Math.Max(Math.Max(Size.X, Size.Y), Size.Z);

            return(VectorMath.Distance(transformedPos, point) / max);
        }