Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

NaliXL

[Delphi/GLScene] AddNewChild

This topic is 5225 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello there, I''m diving into GLScene a bit, but there''s one thing I don''t understand about object creation at runtime. The documentations sais this:
Creating scene object as root object in scene.

To add a object to scene object  list, you will use the "AddNewChild" method of the list.
"AddNewChild" requires you to define the class of the type of object you want to create.
Thus if I want to create a cube, the class parameter must be "TGLCube".
The result of this method is of type TGLBaseSceneObject. 
My problem is, if I create a TGLCube object useing the AddNewChild function, how can I access the properties of that TGLCube instance? Since the result of AddNewChild is of the TGLBaseSceneObject type, it I can''t access, for example, the "CubeWidth" property. So this
procedure TForm1.FormShow(Sender: TObject);
var Cubes : Array[0..7] of Array[0..7] of Array[0..7] of TGLBaseSceneObject;
var TellerX, TellerY, TellerZ : Byte;
begin
    for TellerX := 0 to 7 do for TellerY := 0 to 7 do for TellerZ := 0 to 7 do begin
        Cubes[TellerX][TellerY][TellerZ] := GLScene1.Objects.AddNewChild(TGLCube);
        Cubes[TellerX][TellerY][TellerZ].CubeWidth  := 0.125;
        Cubes[TellerX][TellerY][TellerZ].CubeHeight := 0.125;
        Cubes[TellerX][TellerY][TellerZ].CubeDepth  := 0.125;
        Cubes[TellerX][TellerY][TellerZ].Position.X := (TellerX * 0.125);
        Cubes[TellerX][TellerY][TellerZ].Position.Y := (TellerY * 0.125);
        Cubes[TellerX][TellerY][TellerZ].Position.Z := (TellerZ * 0.125);
    end;
end;
 
would not work. Anyone an idea?

Share this post


Link to post
Share on other sites
Advertisement
I've not used GLScene but I gotta ask the obvious question before this thread goes any further: can't you just typecast it?

EDIT: the following code compiles, although I don't know if it works...

var
Cubes: array[0..7] of array[0..7] of array[0..7] of TGLBaseSceneObject;
TellerX, TellerY, TellerZ : Byte;
Temp: TGLCube;
begin
for TellerX := 0 to 7 do
begin
for TellerY := 0 to 7 do
begin
for TellerZ := 0 to 7 do
begin
Cubes[TellerX][TellerY][TellerZ] := GLScene1.Objects.AddNewChild(TGLCube);
Temp := Cubes[TellerX][TellerY][TellerZ] as TGLCube;
Temp.CubeWidth := 0.125;
Temp.CubeHeight := 0.125;
Temp.CubeDepth := 0.125;
Temp.Position.X := (TellerX * 0.125);
Temp.Position.Y := (TellerY * 0.125);
Temp.Position.Z := (TellerZ * 0.125);
end;
end;
end;


[edited by - Alimonster on June 1, 2004 6:18:28 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!