Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

Author Topic: Problem porting 3D world function to lazarus  (Read 6833 times)

crash_master25

• Newbie
• Posts: 2
Problem porting 3D world function to lazarus
« on: March 31, 2005, 04:44:19 pm »
Hi!!

I have a  problem, I'm working in a 3D creator appz, I'm useing a 3D engine library, but I need to port it to lazars, all the port now is ok, but I have a problem with one file, because it uses TBitmap.ScanLine, and lazarus don't, then I read many forums and articles by Mattias, but really I'm new in Object Pascal and I don't understand how to make this, I hoppe you can help me how to do this...

The code is this:

----------------------------------------------------------------------------------
unit World3D;

interface

uses
Windows, Model3D, Dialogs, Graphics, ColorConv, Global, Camera, Math;

type

TRGBTripleArray = array[0..32767] of TRGBTriple;
PRGBTripleArray = ^TRGBTripleArray;

TRGBFixed = record
R : integer;
G : integer;
B : integer;
end;

TPointColor = record
X : single;
Y : single;
RGB : TRGBTriple;
end;
TPointColorTriangle = array[0..2] of TPointColor;

TPointLight = record
X : single;
Y : single;
N : TPoint3DSingle;
S : TPoint3DSingle;
end;
TPointLightTriangle = array[0..2] of TPointLight;

TPointTriangle = array[0..2] of TPointFloat;

TLight = record
Position : TPoint3D; // position of light in world
Luminance : byte; // brightness
end;

TVisibleIndex = record
ObjectIndex : integer;
Index : integer;
Distance : Real;
end;
TVisibleIndexArray = array of TVisibleIndex;

T3DWorld = Class(TObject)
private

FWireframe : boolean;
FPhong : boolean;
FBackfaceRemoval : boolean;
FAmbient : byte; // ambient light intensity
FScreenRect : TRect;
FBackgroundColor : TColor;
Scanlines : array of pRGBTripleArray;

procedure SetScreenRect(ARect : TRect);
procedure RenderWireframe;
procedure QuickSort(var A: TVisibleIndexArray; iLo, iHi: Integer);
function PerspectiveProject(APoint3D : TPoint3D) : TPointFloat;
procedure FlatFace(AObject, AFace : integer);
procedure GouraudFace(AObject, AFace : integer);
procedure PhongFace(AObject, AFace : integer);
procedure GouraudPoly(W, H : integer ; V : TPointColorTriangle);
procedure PhongPoly(W, H : integer ; V : TPointLightTriangle ;
Hue, Sat, Lum, Amb : byte);
procedure WuLine(x1, y1, x2, y2 : integer ; R, G, B : byte);

public

Objects : array of T3DModel; // array of objects in world
Camera : TCamera;
Light : TLight;
OffScrBmp : TBitmap; // off screen bitmap for drawing to

procedure Render;
procedure ClearBitmap;

property ScreenRect : TRect read FScreenRect write SetScreenRect;
property Wireframe : boolean read FWireframe write FWireframe;
property Phong : boolean read FPhong write FPhong;
property BackfaceRemoval : boolean read FBackFaceRemoval write FBackFaceRemoval;
property Ambient : byte read FAmbient write FAmbient;
property BackgroundColor : TColor read FBackgroundColor write FBackgroundColor;

constructor Create;
destructor Destroy; override;

end;
----------------------------------------------------------------------------
Tks
Bruno Chavez

Marmin_

• Guest
Problem porting 3D world function to lazarus
« Reply #1 on: April 01, 2005, 07:41:43 am »
it seems scanline is not supported by Lazarus ..

crash_master25

• Newbie
• Posts: 2
Problem porting 3D world function to lazarus
« Reply #2 on: April 01, 2005, 04:41:13 pm »
Yep, I know it's not supported by lazarus, that's why I'm trying to search another way to make that function....

matthijs

• Hero Member
• Posts: 537
Problem porting 3D world function to lazarus
« Reply #3 on: April 03, 2005, 07:29:53 pm »
But to check over 1000 lines of code, is a bit much So if you extract the relevant part, we could have a look.
What's in a sig? Would my posting look less if it didnot have a sig? (Free after William S.)

Why cannot I upload my own Avatar?

fatg

• New Member
• Posts: 33
Problem porting 3D world function to lazarus
« Reply #4 on: April 10, 2005, 04:45:06 am »
Yes, or you could provide a link to the file ... Pasting large amounts of code on forums is rather unnecessary

Anonymous

• Guest
Problem porting 3D world function to lazarus
« Reply #5 on: April 13, 2005, 03:39:33 pm »
Sorry for that, I paste the only procedure with the problem:

procedure T3DWorld.SetScreenRect(ARect : TRect);
Var
LLine : integer;
begin
FScreenRect := ARect;

// set screen center position
Camera.ScreenMid.X := ARect.Right div 2;
Camera.ScreenMid.Y := ARect.Bottom div 2;

// set bitmap dimensions
OffScrBmp.Width  := ARect.Right;
OffScrBmp.Height := ARect.Bottom;

SetLength(Scanlines, ARect.Bottom);
for LLine := 0 to ARect.Bottom - 1 do
Scanlines[LLine] := OffScrBmp.ScanLine[LLine];
end;

Tks
Bruno Chavez