Click here to Skip to main content
Click here to Skip to main content
Articles » Multimedia » DirectX » Games » Downloads
 
Add your own
alternative version
Go to top

Game Engine

, 20 Nov 2009
A game engine first prototype
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MTV3D65;

namespace gefx
{
   public  class Camera
    {
        private TVCamera Cam;
        TV_3DVECTOR CamDirection = new TV_3DVECTOR(0,0,0);
        private TVMathLibrary Math = new TVMathLibrary();
        float fars = 2000.0f;
        float nears = 1.0f;
        float degs = 0.0f;
        float Z = 1;
        float UZ;

        public  TV_3DVECTOR kamerMouseSpacePos = new TV_3DVECTOR(0, 0, 0);

        public Camera()
        {
            Cam = new TVCamera();

            

        }

       

        public void SetUpCameraPosition(TV_3DVECTOR CameraPosition)
        {

            Cam.SetPosition(CameraPosition.x, CameraPosition.y, CameraPosition.z);
            Cam.SetViewFrustum(90, 2000);
        }

        public TV_3DVECTOR GetCameraPosition()
        {
            return Cam.GetPosition();

        }

        public void SetUpCameraDirection(float x,float y,float z)
        {
            CamDirection.x = x;
            CamDirection.y = y;
            CamDirection.z = z;
            Cam.SetLookAt(x, y, z);

        }

        public TV_3DVECTOR GetCameraDirection()
        {

            return CamDirection;
        }


        public void GetCameraViewStum(ref float  Far, ref float  Near, ref float deg)
        {
            Cam.GetViewFrustum(ref  deg, ref Far, ref  Near);

        }

        public void  GetMouseSpacePosition(float Mx, float My,ref TV_3DVECTOR vii)
        {
                GetCameraViewStum(ref fars, ref nears, ref degs);
                UZ = (fars / (fars - nears)) + ((nears * fars) / (fars - nears)) * (1 / Z);
                Math.Project2DPointTo3D(Mx, My, UZ, ref vii);
        }

        public void GetMSpacePos(float Mx, float My, ref TV_3DVECTOR rV)
        {
            float NearPl= new float();
            float FarPl= new float();
            float degres= new float();
            float Z= new float();

            Cam.GetViewFrustum(ref  degres, ref FarPl, ref  NearPl);
            float UZ = new float();
            //Z = 2;
            //UZ = (FarPl / (FarPl - NearPl)) + ((NearPl * FarPl) / (FarPl - NearPl)) * (1 / Z);

            //Math.Project2DPointTo3D(Mx, My, UZ, ref  rV);

            TV_3DVECTOR NearPos= new TV_3DVECTOR(0,0,0);
            TV_3DVECTOR   FarPos= new TV_3DVECTOR(0,0,0);

            Math.GetMousePickVectors(Mx, My, ref NearPos, ref FarPos);
            float sngDistFromNearPlane=2000;

            sngDistFromNearPlane = NearPl / FarPl;

            rV = NearPos + ((FarPos - NearPos) * ((sngDistFromNearPlane - NearPl) / (FarPl - NearPl)));

            kamerMouseSpacePos = rV;



        }



    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Common Public License Version 1.0 (CPL)

Share

About the Author

Member 3873633
Software Developer
Croatia Croatia
Programer

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 20 Nov 2009
Article Copyright 2009 by Member 3873633
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid