Jump to content

[Solved] Finding the Terrain Object in a Scene


Shard
 Share

Recommended Posts

How do I get a pointer/reference to the terrain in a scene?

I need it so that I can check terrain normals when doing my AStar scan function.

simpleSigPNG.png

 

Programmer/Engineer/Student

www.reikumar.com

 

2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM

C++ - Visual Studio Express - Dark GDK - Leadwerks SDK

Link to comment
Share on other sites

 

I did exactly that, and at the time of that thread, it worked.

I did it again earlier today and it didn't work; I got a null pointer.

 

I was thinking that something in the code had changed.

My code is below.

 

	int childCount = scene.GetCountChildren();
Entity ent;
string className;
string objectName;
string childClass;
TVec3 objectPos;

for(int i = 1; i < childCount; i++)
{
	ent = scene.GetChild(i);
	className = ent.GetKey("classname");
	objectName = ent.GetKey("name");
	objectPos = ent.GetPosition();
	childClass = ent.GetKey("class");

	if(childClass == "Terrain") aStar.terrain = ent;
	if(objectName == "node_1") nodeOne = objectPos;
	else if(objectName == "node_2") nodeTwo = objectPos;
	else if(objectName == "waterplane_1") aStar.waterHeight = objectPos.Y;
}

simpleSigPNG.png

 

Programmer/Engineer/Student

www.reikumar.com

 

2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM

C++ - Visual Studio Express - Dark GDK - Leadwerks SDK

Link to comment
Share on other sites

You can see how it's done in gamelib.cpp, copy use it or copy it.

 

 

I did take a look at it and looked just like my code.

Yet my code doesn't work.

Any thoughts?

 

			if( (es=="nothing") && (cl=="Terrain") )
		{
			// printf("******** FOUND TERRAIN ********\n");
			terrain = e;
			SetEntityKey(e,"status","handled");
		}

simpleSigPNG.png

 

Programmer/Engineer/Student

www.reikumar.com

 

2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM

C++ - Visual Studio Express - Dark GDK - Leadwerks SDK

Link to comment
Share on other sites

I found the bug and fixed it.

 

From:

 for(int i = 1; i < childCount; i++)

 

To:

 for(int i = 1; i <= childCount; i++)

 

:)

 

Yep, since the terrain is the last object in a sbx, I always missed it because I wasn't checking the last element.

simpleSigPNG.png

 

Programmer/Engineer/Student

www.reikumar.com

 

2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM

C++ - Visual Studio Express - Dark GDK - Leadwerks SDK

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...