Всем привет. наверняка такие вопросы возникали на форуме, в поиске нечего не нашол . Погуглил пару дней.. тоже не помогло... Проблема такая. послезавтра нужно здать проект в школе. Пишу 3D Solar System. По названию темы можно понять что проблема в том что координаты текстуры остаються постоянными относительно положению камеры... Как бы не передвигай камеру всё равно текстура не передвигаеться... Помогите мне, только про File.X не пишите.. нету времени что то менять. Я уверен нужно пару строк поменять и всё ок станет.. вот мой код: Думаю проблема здесь... менял TextureCoordinateIndex, но не помогло. | Код |
MyDevice.TextureState[0].TextureCoordinateIndex = (int)TextureCoordinateIndex.CameraSpaceNormal;
|
навсякий случай скопировал код всего класа : | Код |
public class SphereObject { private Texture Texture; private string name; public string TextureIndex; private float Size; public float XLocation; public float YLocation; private float ZLocation;
public float tempX; private float tempSize;
private Device MyDevice; private Mesh MyMesh; public float OrbitRotationAngelX; // Orbital Rotation on X axis. private float OrbitRotationAngelY; // Orbital Rotation on Y axis. private float OrbitRotationAngelZ; // Orbital Rotation on Z axis.
public float OrbitRotationX = 0.0f; private float OrbitRotationY = 0.0f; private float OrbitRotationZ = 0.0f; private float TextureRotationANGEL; // Rotation of the texture. private Matrix OrbitRotationMatrix; public PointF PlanetLocation; public float tempPlus = 0.05f;
public SphereObject(string name, string TextureIndex, float size, float XLocation, float YLocation,float ZLocation, float OrbitRotationAngelX, float OrbitRotationAngelY, float OrbitRotationAngelZ, float TextureRotationANGEL, Device MyDevice) { this.name = name; this.TextureIndex = TextureIndex; this.Size = size; this.XLocation = XLocation; this.YLocation = YLocation; this.ZLocation = ZLocation; this.OrbitRotationAngelX = OrbitRotationAngelX; this.OrbitRotationAngelY = OrbitRotationAngelY; this.OrbitRotationAngelZ = OrbitRotationAngelZ; this.TextureRotationANGEL = TextureRotationANGEL; this.MyDevice = MyDevice; this.PlanetLocation = new PointF(this.XLocation, this.YLocation);
MyMesh = Mesh.Sphere(this.MyDevice, this.Size, 50, 50); this.LoadTexture(); } public SphereObject( string TextureIndex, float size, Vector3 ObjectLocation, Vector3 AngelsRotations, float TextureRotationANGEL, Device MyDevice) { this.TextureIndex = TextureIndex; this.Size = size; this.tempSize = this.Size; XLocation = ObjectLocation.X; YLocation = ObjectLocation.Y; ZLocation = ObjectLocation.Z;
OrbitRotationAngelX = AngelsRotations.X; OrbitRotationAngelY = AngelsRotations.Y; OrbitRotationAngelZ = AngelsRotations.Z;
this.TextureRotationANGEL = TextureRotationANGEL; this.MyDevice = MyDevice; this.MyMesh = Mesh.Sphere(this.MyDevice, this.tempSize, 50, 50); //this.MyMesh=Mesh.FromFile("sphere.x", MeshFlags.Managed,this.MyDevice); this.LoadTexture();
} public void LoadTexture() { using (FileStream textureFile = new FileStream(this.TextureIndex,FileMode.Open,FileAccess.Read,FileShare.Read,1)) { Texture = Texture.FromStream(this.MyDevice, textureFile, 0, Pool.Managed); textureFile.Close(); } }
public void DrawSphere(Matrix SecondOrbitRotation) {
TextureRotationANGEL += 0.5f;
OrbitRotationX += OrbitRotationAngelX; OrbitRotationY += OrbitRotationAngelY; OrbitRotationZ += OrbitRotationAngelZ;
[U] MyDevice.TextureState[0].TextureCoordinateIndex = (int)TextureCoordinateIndex.CameraSpaceNormal;[B][/U][/B] //MyDevice.SetTextureStageState(0, TextureStageStates.TextureCoordinateIndex, 1); //TextureCoordinateIndex.CameraSpaceNormal; //CameraSpaceNormal //Textur Scaling and rotation. this.MyDevice.Transform.Texture0 = Matrix.Scaling(0.3f, -0.5f, 0.0f) * /*Matrix.Translation(0, TextureRotationANGEL, 0);*/ Matrix.Translation(TextureRotationANGEL, 7.5f, 0.0f); //Texture Scaling. //Orbit rotation. this.OrbitRotationMatrix = Matrix.Translation(tempX, YLocation, ZLocation)* Matrix.RotationYawPitchRoll( (float)OrbitRotationX / (float)Math.PI, (float)OrbitRotationY / (float)Math.PI * 2.0f, (float)OrbitRotationZ / (float)Math.PI / 2.0f);
this.MyDevice.Transform.World = //Orbit scale/Translation this.OrbitRotationMatrix * SecondOrbitRotation;
TexturProperties(); SpherMaterial();
this.MyMesh.Dispose(); this.MyMesh = Mesh.Sphere(this.MyDevice, this.tempSize, 50, 50); MyMesh.DrawSubset(0); }
private void TexturProperties() { this.MyDevice.TextureState[0].TextureTransform = TextureTransform.Count2; this.MyDevice.SetTexture(0, this.Texture); this.MyDevice.SamplerState[0].MinFilter = TextureFilter.Linear; this.MyDevice.SamplerState[0].MagFilter = TextureFilter.Linear; }
private void SpherMaterial() { Material SphereMaterial = new Material(); SphereMaterial.Ambient = Color.Transparent; SphereMaterial.Diffuse = Color.Transparent; this.MyDevice.Material = SphereMaterial; }
public Matrix GetOrbitMatrix() { return this.OrbitRotationMatrix; } public void SetObjectLocation(float radius,bool PlanetMod) { if (PlanetMod!=true ) this.tempX = 100 + (this.XLocation * radius); else this.tempX = radius; } public void SetObjectRadius(float newradius, bool PlanetMod) { if (PlanetMod != true) this.tempSize = (this.Size * newradius); else this.tempSize = newradius; } public void SetTexturRotation(int temp) { this.TextureRotationANGEL = temp / 15; } } }
|
Присоединённый файл ( Кол-во скачиваний: 8 )
SSB.png 322,92 Kb
|