Drawing Quads?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Jookia
Posts: 170
Joined: Wed Nov 19, 2008 1:11 am

Drawing Quads?

Post by Jookia »

My quad comes out as a triangle. What's wrong?

Code: Select all

CVoxelSceneNode::CVoxelSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id)
	: ISceneNode(parent, mgr, id)
{
	material.Wireframe = false;
	material.Lighting = false;
	
	SColor voxelColor = SColor(255, 255, 0, 0);
	
	vertices[0] = S3DVertex(-10, 10, 0,
		0, 0, 0,
		voxelColor,
		0, 0);
	
	vertices[1] = S3DVertex(10, 10, 0,
		0, 0, 0,
		voxelColor,
		0, 0);
	
	vertices[2] = S3DVertex(10, -10, 0,
		0, 0, 0,
		voxelColor,
		0, 0);
	
	vertices[3] = S3DVertex(-10, -10, 0,
		0, 0, 0,
		voxelColor,
		0, 0);
	
	bounds.reset(vertices[0].Pos);
	
	for(s32 i = 1; i < 4; i++)
		bounds.addInternalPoint(vertices[i].Pos);
}

void CVoxelSceneNode::OnRegisterSceneNode()
{
	if(IsVisible)
		SceneManager->registerNodeForRendering(this);
	
	ISceneNode::OnRegisterSceneNode();
}

void CVoxelSceneNode::render()
{
	u16 indices[] = {
		0, 2, 3,
		2, 1, 3,
		1, 0, 3,
		2, 0, 1};
	
	IVideoDriver* driver = SceneManager->getVideoDriver();
	
	driver->setMaterial(material);
	driver->setTransform(ETS_WORLD, AbsoluteTransformation);
	driver->drawVertexPrimitiveList(&vertices[0], 4, &indices[0], 1, EVT_STANDARD, EPT_QUADS, EIT_16BIT);
}
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

The indices are wrong, try {0, 1, 2, 3}.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Bob Finnie
Posts: 49
Joined: Tue Jan 23, 2007 12:36 pm
Location: Bedford, UK

Post by Bob Finnie »

I think your loop is stopping too soon

Code: Select all

 for(s32 i = 1; i < 4; i++)
      bounds.addInternalPoint(vertices[i].Pos); 
The above code is only adding 3 points
Jookia
Posts: 170
Joined: Wed Nov 19, 2008 1:11 am

Post by Jookia »

Thanks, that all fixed it.
Jookia
Posts: 170
Joined: Wed Nov 19, 2008 1:11 am

Post by Jookia »

Also, why are my values ALWAYS zero?

Code: Select all

							screenSize.Width = xml->getAttributeValueAsInt("width");
							screenSize.Height = xml->getAttributeValueAsInt("height");
							screenBits = xml->getAttributeValueAsInt("bits");
when my file is

Code: Select all

<?xml version="1.0"?>
<config>

<screen
	width="1280"
	height="720"
	bits="16"
	fullscreen="0"
>

</config>
Also, in my custom node constructer, how can I find the device from there?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Are you in the screen node when you're reading those xml attributes? you have to traverse the xml until you find the screen node, if you just try and read out the width and height straight away it will be looking for them in the config node which doesn't have those attribues ;)

To get the device in your custom node... pass it in as a parameter ;)
Image Image Image
Jookia
Posts: 170
Joined: Wed Nov 19, 2008 1:11 am

Post by Jookia »

I fixed it AFTER I posted. That ALWAYS happens to me. Although, like JavaScript can you do printf("loading model" + modelName); or do you have to make a string?

Also, how would I go about a 3D array of stringcs? :roll:
FuzzYspo0N
Posts: 914
Joined: Fri Aug 03, 2007 12:43 pm
Location: South Africa
Contact:

Post by FuzzYspo0N »

The documentation has a lot of information about this stuff. dont forget to read it first,

for an array of strings, irr::core::array<core::stringc> myarray;

also 3d arrays? did you mean 2d arrays?

You should get a grasp of data structures if you plan to write 3d arrays, using a struct, or using core::map, or using core::array, with core::arrays as the types. (typedef ing it to be easier to read)

Plus, for a string :

core::stringc is an in place constructor, so you can do :

Code: Select all

printf("Loaded : %s" , core::stringc(modelName).c_str());
But if modelName IS a core::stringc already just :

Code: Select all

printf("Loaded : %s" , modelName.c_str());

Code: Select all

or, core::stringc("loaded :).append(modelName).c_str()
also note that irrlicht has a logger..
device->getLogger->log (read the docs)
Jookia
Posts: 170
Joined: Wed Nov 19, 2008 1:11 am

Post by Jookia »

I know about the logger, but I need a non-limited 3D array for storing both positive and negative non-floating 3d positions.
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

What do you mean by "3d array" ?

Code: Select all

float array[x][x][x]
or what ?
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Jookia
Posts: 170
Joined: Wed Nov 19, 2008 1:11 am

Post by Jookia »

Sylence wrote:What do you mean by "3d array" ?

Code: Select all

float array[x][x][x]
or what ?
Yeah, like I need to check if..

I have a box at 0 0 0.
I need to see if there's a box on top of it, at 0 0 1.
Now, I could loop through them all and check the positions, but that'd sacrifice some performance when I have large models.

So, if there's a box above me, I'd read that box's stringc data.
Jookia
Posts: 170
Joined: Wed Nov 19, 2008 1:11 am

Post by Jookia »

Okay, it crashes when I assign it to the 3d array.

Code: Select all

		array<voxel*> seeds;
		array< array< array<voxel*> > > tree;

Code: Select all

					voxel voxel;
					voxel.pos = vector3di(0, 0, 1);
					voxel.color = SColor(255, 255, 0, 0);
					
					seeds.push_back(&voxel);
					tree[voxel.pos.X][voxel.pos.Y][voxel.pos.Z] = &voxel;
					
					printf(stringc(voxel.pos.Z).c_str());
					
					return true;
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Try to set_used() the dimensions of the tree arrays. Otherwise the data space is not allocated and available for use. However, this isn't giving a sparse matrix. Are you sure you want that?
Post Reply