LZScene

Форк
0
/
GLStarRecord.pas 
93 строки · 3.0 Кб
1
//
2
// This unit is part of the GLScene Engine https://github.com/glscene
3
//
4
{
5
   Unit to interface with simple star records aimed for background skies.
6

7
	 History :  
8
	    05/07/03 - EG - Creation
9
	 
10
}
11
unit GLStarRecord;
12

13
interface
14

15
uses
16
  GLVectorGeometry;
17

18
type
19
   TGLStarRecord = packed record
20
      RA : Word;              // x100 builtin factor, degrees
21
      DEC : SmallInt;         // x100 builtin factor, degrees
22
      BVColorIndex : Byte;    // x100 builtin factor
23
      VMagnitude : Byte;      // x10 builtin factor
24
   end;
25
   PGLStarRecord = ^TGLStarRecord;
26

27
{ Computes position on the unit sphere of a star record (Z=up). }
28
function StarRecordPositionZUp(const starRecord : TGLStarRecord) : TAffineVector;
29
{ Computes position on the unit sphere of a star record (Y=up). }
30
function StarRecordPositionYUp(const starRecord : TGLStarRecord) : TAffineVector;
31
{ Computes star color from BV index (RGB) and magnitude (alpha). }
32
function StarRecordColor(const starRecord : TGLStarRecord; bias : Single) : TVector;
33

34
// ------------------------------------------------------------------
35
// ------------------------------------------------------------------
36
// ------------------------------------------------------------------
37
implementation
38

39
uses
40
  GLVectorTypes;
41
// ------------------------------------------------------------------
42
// ------------------------------------------------------------------
43
// ------------------------------------------------------------------
44

45
// StarRecordPositionYUp
46
//
47
function StarRecordPositionYUp(const starRecord : TGLStarRecord) : TAffineVector;
48
var
49
   f : Single;
50
begin
51
   SinCos(starRecord.DEC*(0.01*PI/180), Result.V[1], f);
52
   SinCos(starRecord.RA*(0.01*PI/180), f, Result.V[0], Result.V[2]);
53
end;
54

55
// StarRecordPositionZUp
56
//
57
function StarRecordPositionZUp(const starRecord : TGLStarRecord) : TAffineVector;
58
var
59
   f : Single;
60
begin
61
   SinCos(starRecord.DEC*(0.01*PI/180), Result.V[2], f);
62
   SinCos(starRecord.RA*(0.01*PI/180), f, Result.V[0], Result.V[1]);
63
end;
64

65
// StarRecordColor
66
//
67
function StarRecordColor(const starRecord : TGLStarRecord; bias : Single) : TVector;
68
const
69
   // very *rough* approximation
70
   cBVm035 : TVector = (X:0.7; Y:0.8; Z:1.0; W:1);
71
   cBV015  : TVector = (X:1.0; Y:1.0; Z:1.0; W:1);
72
   cBV060  : TVector = (X:1.0; Y:1.0; Z:0.7; W:1);
73
   cBV135  : TVector = (X:1.0; Y:0.8; Z:0.7; W:1);
74
var
75
   bvIndex100 : Integer;
76
begin
77
   bvIndex100:=starRecord.BVColorIndex-50;
78
   // compute RGB color for B&V index
79
   if bvIndex100<-035 then
80
      Result:=cBVm035
81
   else if bvIndex100<015 then
82
      VectorLerp(cBVm035, cBV015, (bvIndex100+035)*(1/(015+035)), Result)
83
   else if bvIndex100<060 then
84
      VectorLerp(cBV015, cBV060, (bvIndex100-015)*(1/(060-015)), Result)
85
   else if bvIndex100<135 then
86
      VectorLerp(cBV060, cBV135, (bvIndex100-060)*(1/(135-060)), Result)
87
   else Result:=cBV135;
88
   // compute transparency for VMag
89
   // the actual factor is 2.512, and not used here
90
   Result.V[3]:=Power(1.2, -(starRecord.VMagnitude*0.1-bias));
91
end;
92

93
end.
94

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.