///<summary>提交光源</summary> public void applyLight() { IntPtr ipPara = Marshal.AllocCoTaskMem(Marshal.SizeOf(lightSturPara)); Marshal.StructureToPtr(lightSturPara, ipPara, false); D3DManager.ChangeLightPara(parent.earth.earthkey, lightnum, ipPara); Marshal.FreeCoTaskMem(ipPara); }
///<summary>根据相机位置重计算缺省光源方向,并提交缺省光源</summary> public void applyLights() { if (lightset == null) { return; } applyAmbientLight(); foreach (var item in lightset.lights) { IntPtr ipPara = Marshal.AllocCoTaskMem(Marshal.SizeOf(item.lightSturPara)); Marshal.StructureToPtr(item.lightSturPara, ipPara, false); D3DManager.ChangeLightPara(earth.earthkey, item.num, ipPara); Marshal.FreeCoTaskMem(ipPara); } //if (earth.earthManager.earthpara.SceneMode == ESceneMode.局部平面) //{ // Vector3D vecGround = new Vector3D(0,0,-1); // Vector3D vecY = new Vector3D(0, 1, 0); // Vector3D vecX = new Vector3D(1, 0, 0); // //右侧上光源正常效果 // Vector3D vecDir; // RotateTransform3D rotate; // rotate = new RotateTransform3D(new AxisAngleRotation3D(vecY, -60)); // vecDir = rotate.Transform(vecGround); // rotate = new RotateTransform3D(new AxisAngleRotation3D(vecX, 60)); // vecDir = rotate.Transform(vecDir); // //vecDir.Negate(); // vecDir.Normalize(); // lights[0].Direction = vecDir; // lights[0].applyLight(); // //右侧上光源通透效果 // lights[1].Direction = vecDir; // lights[1].applyLight(); // //正前方光源 // lights[2].Direction =vecY; // lights[2].applyLight(); // lights[2].applyLight(); //} //else //{ // Vector3D vecGround = new Vector3D(earth.camera.cameraPosition.X, earth.camera.cameraPosition.Y, earth.camera.cameraPosition.Z); // vecGround = vecGround * (vecGround.Length / Para.Radius); // Vector3D vecY = new Vector3D(0, 1, 0); // Vector3D vecAxis = Vector3D.CrossProduct(vecGround, vecY); // vecAxis.Normalize(); // //右侧上光源正常效果 // Vector3D vecDir; // RotateTransform3D rotate; // rotate = new RotateTransform3D(new AxisAngleRotation3D(vecAxis, -60)); // vecDir = rotate.Transform(vecGround); // rotate = new RotateTransform3D(new AxisAngleRotation3D(vecGround, 60)); // vecDir = rotate.Transform(vecDir); // vecDir.Negate(); // vecDir.Normalize(); // lights[0].Direction = vecDir; // lights[0].applyLight(); // //右侧上光源通透效果 // rotate = new RotateTransform3D(new AxisAngleRotation3D(vecAxis, -60)); // vecDir = rotate.Transform(vecGround); // rotate = new RotateTransform3D(new AxisAngleRotation3D(vecGround, 60)); // vecDir = rotate.Transform(vecDir); // vecDir.Negate(); // vecDir.Normalize(); // lights[1].Direction = vecDir; // lights[1].applyLight(); // //正前方光源 // rotate = new RotateTransform3D(new AxisAngleRotation3D(vecAxis, -60)); // vecDir = rotate.Transform(vecGround); // //rotate = new RotateTransform3D(new AxisAngleRotation3D(vecGround, 60)); // //vecDir = rotate.Transform(vecDir); // vecDir.Negate(); // vecDir.Normalize(); // lights[2].Direction = vecDir; // lights[2].applyLight(); //} }