- Replaced own UVector with unit matrix from the RTL
This commit is contained in:
parent
1e84b76c63
commit
12a28c79b2
|
@ -30,16 +30,16 @@ unit ULandscape;
|
|||
interface
|
||||
|
||||
uses
|
||||
SysUtils, Classes, math, LCLIntf, GL, GLu, ImagingOpenGL, Imaging,
|
||||
SysUtils, Classes, math, matrix, LCLIntf, GL, GLu, ImagingOpenGL, Imaging,
|
||||
ImagingClasses, ImagingTypes, ImagingUtility,
|
||||
UGenericIndex, UMap, UStatics, UArt, UTexture, UTiledata, UHue, UWorldItem,
|
||||
UMulBlock, UAnimData,
|
||||
UVector, UEnhancedMemoryStream, UGLFont,
|
||||
UEnhancedMemoryStream, UGLFont,
|
||||
UCacheManager;
|
||||
|
||||
type
|
||||
PNormals = ^TNormals;
|
||||
TNormals = array[0..3] of TVector;
|
||||
TNormals = array[0..3] of Tvector3_single;
|
||||
PRadarBlock = ^TRadarBlock;
|
||||
TRadarBlock = array[0..7, 0..7] of Word;
|
||||
|
||||
|
@ -1030,14 +1030,19 @@ end;
|
|||
procedure TLandscape.GetNormals(AX, AY: Word; var ANormals: TNormals);
|
||||
var
|
||||
cells: array[0..2, 0..2] of TNormals;
|
||||
north, west, south, east: TVector;
|
||||
north, west, south, east: Tvector3_single;
|
||||
i, j: Integer;
|
||||
|
||||
function Normalize(const AVector: Tvector3_single): Tvector3_single; inline;
|
||||
begin
|
||||
Result := AVector / AVector.length;
|
||||
end;
|
||||
|
||||
function GetPlainNormals(X, Y: SmallInt): TNormals;
|
||||
var
|
||||
cell: TMapCell;
|
||||
north, west, south, east: ShortInt;
|
||||
u, v: TVector;
|
||||
u, v: Tvector3_single;
|
||||
begin
|
||||
cell := GetMapCell(X, Y);
|
||||
if cell <> nil then
|
||||
|
@ -1056,27 +1061,27 @@ var
|
|||
|
||||
if (north = west) and (west = east) and (north = south) then
|
||||
begin
|
||||
Result[0] := Vector(0, 0, 1);
|
||||
Result[1] := Vector(0, 0, 1);
|
||||
Result[2] := Vector(0, 0, 1);
|
||||
Result[3] := Vector(0, 0, 1);
|
||||
Result[0].init(0, 0, 1);
|
||||
Result[1].init(0, 0, 1);
|
||||
Result[2].init(0, 0, 1);
|
||||
Result[3].init(0, 0, 1);
|
||||
end else
|
||||
begin
|
||||
u := Vector(-22, 22, (north - east) * 4);
|
||||
v := Vector(-22, -22, (west - north) * 4);
|
||||
Result[0] := VectorNorm(VectorCross(u, v));
|
||||
u.init(-22, 22, (north - east) * 4);
|
||||
v.init(-22, -22, (west - north) * 4);
|
||||
Result[0] := Normalize(u >< v);
|
||||
|
||||
u := Vector(22, 22, (east - south) * 4);
|
||||
v := Vector(-22, 22, (north - east) * 4);
|
||||
Result[1] := VectorNorm(VectorCross(u, v));
|
||||
u.init(22, 22, (east - south) * 4);
|
||||
v.init(-22, 22, (north - east) * 4);
|
||||
Result[1] := Normalize(u >< v);
|
||||
|
||||
u := Vector(22, -22, (south - west) * 4);
|
||||
v := Vector(22, 22, (east - south) * 4);
|
||||
Result[2] := VectorNorm(VectorCross(u, v));
|
||||
u.init(22, -22, (south - west) * 4);
|
||||
v.init(22, 22, (east - south) * 4);
|
||||
Result[2] := Normalize(u >< v);
|
||||
|
||||
u := Vector(-22, -22, (west - north) * 4);
|
||||
v := Vector(22, -22, (south - west) * 4);
|
||||
Result[3] := VectorNorm(VectorCross(u, v));
|
||||
u.init(-22, -22, (west - north) * 4);
|
||||
v.init(22, -22, (south - west) * 4);
|
||||
Result[3] := Normalize(u >< v);
|
||||
end;
|
||||
end;
|
||||
begin
|
||||
|
@ -1088,25 +1093,25 @@ begin
|
|||
west := cells[0, 1][1];
|
||||
east := cells[1, 0][3];
|
||||
south := cells[1, 1][0];
|
||||
ANormals[0] := VectorNorm(VectorAdd(VectorAdd(VectorAdd(north, west), east), south));
|
||||
ANormals[0] := Normalize(north + west + east + south);
|
||||
|
||||
north := cells[1, 0][2];
|
||||
west := cells[1, 1][1];
|
||||
east := cells[2, 0][3];
|
||||
south := cells[2, 1][0];
|
||||
ANormals[1] := VectorNorm(VectorAdd(VectorAdd(VectorAdd(north, west), east), south));
|
||||
ANormals[1] := Normalize(north + west + east + south);
|
||||
|
||||
north := cells[1, 1][2];
|
||||
west := cells[1, 2][1];
|
||||
east := cells[2, 1][3];
|
||||
south := cells[2, 2][0];
|
||||
ANormals[2] := VectorNorm(VectorAdd(VectorAdd(VectorAdd(north, west), east), south));
|
||||
ANormals[2] := Normalize(north + west + east + south);
|
||||
|
||||
north := cells[0, 1][2];
|
||||
west := cells[0, 2][1];
|
||||
east := cells[1, 1][3];
|
||||
south := cells[1, 2][0];
|
||||
ANormals[3] := VectorNorm(VectorAdd(VectorAdd(VectorAdd(north, west), east), south));
|
||||
ANormals[3] := Normalize(north + west + east + south);
|
||||
end;
|
||||
|
||||
procedure TLandscape.LoadNoDrawMap(AFileName: String);
|
||||
|
|
87
UVector.pas
87
UVector.pas
|
@ -1,87 +0,0 @@
|
|||
(*
|
||||
* CDDL HEADER START
|
||||
*
|
||||
* The contents of this file are subject to the terms of the
|
||||
* Common Development and Distribution License, Version 1.0 only
|
||||
* (the "License"). You may not use this file except in compliance
|
||||
* with the License.
|
||||
*
|
||||
* You can obtain a copy of the license at
|
||||
* http://www.opensource.org/licenses/cddl1.php.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
*
|
||||
* When distributing Covered Code, include this CDDL HEADER in each
|
||||
* file and include the License file at
|
||||
* http://www.opensource.org/licenses/cddl1.php. If applicable,
|
||||
* add the following below this CDDL HEADER, with the fields enclosed
|
||||
* by brackets "[]" replaced with your own identifying * information:
|
||||
* Portions Copyright [yyyy] [name of copyright owner]
|
||||
*
|
||||
* CDDL HEADER END
|
||||
*
|
||||
*
|
||||
* Portions Copyright 2009 Andreas Schneider
|
||||
*)
|
||||
unit UVector;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes;
|
||||
|
||||
type
|
||||
TVector = packed record
|
||||
X: Single;
|
||||
Y: Single;
|
||||
Z: Single;
|
||||
end;
|
||||
|
||||
function Vector(AX, AY, AZ: Single): TVector;
|
||||
function VectorAdd(AVector1, AVector2: TVector): TVector;
|
||||
function VectorDot(AVector1, AVector2: TVector): TVector;
|
||||
function VectorCross(AVector1, AVector2: TVector): TVector;
|
||||
function VectorNorm(AVector: TVector): TVector;
|
||||
|
||||
implementation
|
||||
|
||||
function Vector(AX, AY, AZ: Single): TVector;
|
||||
begin
|
||||
Result.X := AX;
|
||||
Result.Y := AY;
|
||||
Result.Z := AZ;
|
||||
end;
|
||||
|
||||
function VectorAdd(AVector1, AVector2: TVector): TVector;
|
||||
begin
|
||||
Result.X := AVector1.X + AVector2.X;
|
||||
Result.Y := AVector1.Y + AVector2.Y;
|
||||
Result.Z := AVector1.Z + AVector2.Z;
|
||||
end;
|
||||
|
||||
function VectorDot(AVector1, AVector2: TVector): TVector;
|
||||
begin
|
||||
Result.X := AVector1.X * AVector2.X;
|
||||
Result.Y := AVector1.Y * AVector2.Y;
|
||||
Result.Z := AVector1.Z * AVector2.Z;
|
||||
end;
|
||||
|
||||
function VectorCross(AVector1, AVector2: TVector): TVector;
|
||||
begin
|
||||
Result.X := AVector1.Y * AVector2.Z - AVector1.Z * AVector2.Y;
|
||||
Result.Y := AVector1.Z * AVector2.X - AVector1.X * AVector2.Z;
|
||||
Result.Z := AVector1.X * AVector2.Y - AVector1.Y * AVector2.X;
|
||||
end;
|
||||
|
||||
function VectorNorm(AVector: TVector): TVector;
|
||||
var
|
||||
abs: Real;
|
||||
begin
|
||||
abs := Sqrt(AVector.X * AVector.X + AVector.Y * AVector.Y + AVector.Z * AVector.Z);
|
||||
Result.X := AVector.X / abs;
|
||||
Result.Y := AVector.Y / abs;
|
||||
Result.Z := AVector.Z / abs;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
Loading…
Reference in New Issue