Ejemplo n.º 1
0
        public Matrix4f SetToLookAt(Vector3f dir, Vector3f up)
        {
            this.SetToIdentity();

            l_vez.Set(dir);
            l_vez.NormalizeStore();
            l_vex.Set(dir);
            l_vex.NormalizeStore();
            l_vex.CrossStore(up);
            l_vex.NormalizeStore();
            l_vey.Set(l_vex);
            l_vey.CrossStore(l_vez);
            l_vey.NormalizeStore();

            this.values[Matrix4f.m00] = l_vex.x;
            this.values[Matrix4f.m01] = l_vex.y;
            this.values[Matrix4f.m02] = l_vex.z;

            this.values[Matrix4f.m10] = l_vey.x;
            this.values[Matrix4f.m11] = l_vey.y;
            this.values[Matrix4f.m12] = l_vey.z;

            this.values[Matrix4f.m20] = l_vez.x;
            this.values[Matrix4f.m21] = l_vez.y;
            this.values[Matrix4f.m22] = l_vez.z;

            return(this);
        }
Ejemplo n.º 2
0
        public BoundingBox Set(Vector3f minimum, Vector3f maximum)
        {
            min.Set(minimum);
            max.Set(maximum);
            center.Set(min).AddStore(max).MultiplyStore(0.5f);
            dimension.Set(max).SubtractStore(min).MultiplyStore(0.5f);
            UpdateCorners();

            return(this);
        }
Ejemplo n.º 3
0
 public Matrix4f SetToLookAt(Vector3f pos, Vector3f target, Vector3f up)
 {
     this.SetToIdentity();
     tempVec.Set(target);
     tempVec.SubtractStore(pos);
     tempVec2.Set(pos);
     tempVec2.MultiplyStore(-1);
     tmpMat.SetToTranslation(tempVec2);
     tmpMat2.SetToLookAt(tempVec, up);
     this.Set(tmpMat);
     this.MultiplyStore(tmpMat2);
     return(this);
 }
Ejemplo n.º 4
0
 private void CalculateBindingTranslation(Vector3f outv)
 {
     if (parentBone != null)
     {
         outv.Set(parentBone.GetModelRotation().Multiply(GetBindTranslation()));
         outv.AddStore(parentBone.GetModelTranslation());
     }
     else
         outv.Set(GetBindTranslation());
 }
Ejemplo n.º 5
0
        public override void Init()
        {
            ShadowMappingComponent smc;
            RenderManager.AddComponent(smc = new ShadowMappingComponent(cam, Environment));
            smc.RenderMode = ShadowMappingComponent.ShadowRenderMode.Forward;
            axisArrows = new Geometry[3];
            Node axisNode = (Node)AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\axis_arrows\\untitled.obj");
            axisArrows[0] = axisNode.GetChildGeom(0);
            axisArrows[1] = axisNode.GetChildGeom(1);
            axisArrows[2] = axisNode.GetChildGeom(2);

            foreach (Geometry g in axisArrows)
            {
                g.Material.SetValue(ApexEngine.Rendering.Material.MATERIAL_DEPTHTEST, false);
                //g.Material.SetValue(ApexEngine.Rendering.Material.MATERIAL_DEPTHMASK, false);
            }

            InputManager.AddMouseEvent(new ApexEngine.Input.MouseEvent(ApexEngine.Input.InputManager.MouseButton.Left, false, new Action(() =>
            {
                if (!holding)
                {
                    Ray ray = cam.GetCameraRay(InputManager.GetMouseX(), InputManager.GetMouseY());

                    Dictionary<Vector3f, GameObject> intersections = new Dictionary<Vector3f, GameObject>();
                    Vector3f closestIntersection = new Vector3f(float.MaxValue);
                    float minDistance = float.MaxValue;
                    List<GameObject> objectList = ApexEngine.Rendering.Util.RenderUtil.GatherObjects(rootNode);
                    foreach (GameObject g in objectList)
                    {
                        if (objectHolding == null || g != objectHolding)
                        {
                            if (g.HasController(typeof(ApexEngine.Scene.Physics.RigidBodyControl)))
                            {
                                Vector3f intersection = g.GetWorldBoundingBox().Intersect(ray);
                                if (intersection != null && !intersections.ContainsKey(intersection))
                                {
                                    intersections.Add(intersection, g);
                                }
                            }
                        }
                    }

                    if (intersections.Count == 0)
                        objectHolding = null;

                    foreach (Vector3f i in intersections.Keys)
                    {
                        float dist = i.Distance(Camera.Translation);
                        if (dist < minDistance)
                        {
                            minDistance = dist;
                            closestIntersection.Set(i);
                        }
                    }

                    GameObject hitObject = null;

                    if (intersections.TryGetValue(closestIntersection, out hitObject))
                    {
                        if (hitObject != null)
                        {
                            if (hitObject.HasController(typeof(ApexEngine.Scene.Physics.RigidBodyControl)))
                            {
                                // needs rigid body control or else the node is "locked"
                                // also we need this to test for intersection in the physics world
                                objectHolding = hitObject;
                                foreach (Geometry g in axisArrows)
                                {
                                    g.SetLocalTranslation((!centered ? objectHolding.GetLocalTranslation() : objectHolding.GetLocalTranslation().Add(objectHolding.GetLocalBoundingBox().Center.Subtract(new Vector3f(0f, objectHolding.GetLocalBoundingBox().Center.Y, 0f)))));
                                    g.UpdateTransform();
                                }
                            }
                            else
                            {
                                objectHolding = null;
                            }
                        }
                    }
                    holdTime = 0f;
                    holding = true;
                    /*

                    GameObject hitObject;
                    PhysicsWorld.Raycast(origin, direction, out hitObject);
                    objectHolding = hitObject;
                    holdTime = 0f;
                    holding = true;
                    if (hitObject != null)
                    {
                        foreach (Geometry g in axisArrows)
                        {
                            g.SetLocalTranslation((!centered ? objectHolding.GetLocalTranslation() : objectHolding.GetLocalTranslation().Add(objectHolding.GetLocalBoundingBox().Center.Subtract(new Vector3f(0f, objectHolding.GetLocalBoundingBox().Center.Y, 0f)))));
                            g.UpdateTransform();
                        }
                    }*/
                }
            })));
            InputManager.AddMouseEvent(new ApexEngine.Input.MouseEvent(ApexEngine.Input.InputManager.MouseButton.Left, true, new Action(() =>
            {
                holdTime = 0f;
                holding = false;
            })));
        }