Scrolling vertex in a terrainSceneNode

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Revan1985
Posts: 89
Joined: Tue May 08, 2007 4:11 pm
Location: Italy

Scrolling vertex in a terrainSceneNode

Post by Revan1985 »

hi, i need to know how scroll all the vertex in a terrainSceneNode...
i was thinking to something like this

Code: Select all

IMesh* pMesh = terrain->getMesh();

for (b=0; b<pMesh->getMeshBufferCount(); ++b)
{
  IMeshBuffer* pMeshBuffer = pMesh->getMeshBuffer(b);
  // skip mesh buffers that are not the right type
  if (pMeshBuffer->getVertexType() != video::EVT_2TCOORDS) continue;

  video::S3DVertex2TCoords* pVertices = (video::S3DVertex2TCoords*)pMeshBuffer->getVertices();

  for(s32 x = 0; x < terrainWidth; x++)
  {
     for(s32 y = 0; y < terrainHeight; y++)
     {
        pVertices[(x *  y) + y].Color = SColor(255,255,255,255);
      }
   }
}
i'm doing a stupid thing, or what i need to change?
CPU: AMD PHENOMII X6 1090T BE 3,2GHZ
RAM : OCZ 8GB 2*4GB DDR3 LOW VOLTAGE 1333
VGA: GeForce GTX680 2GB
HD : 500GB + 500GB + 2x1TB Raid Edition + 500GB External
Motherboard: ASUS CROSSHAIR FORMULA 4 890FX AM3
PSU: Corsair 750W
CPU Cooling: Katana 2
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I think the correct formula is x*terrainHeight+y, might be also terrainHeight+1
Revan1985
Posts: 89
Joined: Tue May 08, 2007 4:11 pm
Location: Italy

Post by Revan1985 »

i'm using this code to scroll the terrain and chagne the colors...

Code: Select all

void CTerrain::Colorate()
{
	scene::IMesh* mesh = m_pTerrain->getMesh();
	for(u32 i = 0; i < mesh->getMeshBufferCount(); ++i)
	{
		scene::IMeshBuffer* pMeshBuffer = mesh->getMeshBuffer(i);
		if(pMeshBuffer->getVertexType() != video::EVT_2TCOORDS){ continue; }

		video::S3DVertex2TCoords* pVertices = (video::S3DVertex2TCoords*)pMeshBuffer->getVertices();

		for(u32 x = 0; x < m_iDimension; ++x)
		{
			for(u32 y = 0; y < m_iDimension; ++y)
			{
				if(pVertices[(x * m_iDimension) + y].Pos.Y < 64){ pVertices[(x * m_iDimension) + y].Color = video::SColor(255, 0, 255, 0); }
				else if(pVertices[(x * m_iDimension) + y].Pos.Y < 128){ pVertices[(x * m_iDimension) + y].Color = video::SColor(255, 255, 25, 25); }
				else if(pVertices[(x * m_iDimension) + y].Pos.Y < 256){ pVertices[(x * m_iDimension) + y].Color = video::SColor(255, 50, 50, 50); }
			}
		}
	}

	m_pTerrain->setPosition(m_pTerrain->getPosition());
}

but nothing happened...
what i need to do?
CPU: AMD PHENOMII X6 1090T BE 3,2GHZ
RAM : OCZ 8GB 2*4GB DDR3 LOW VOLTAGE 1333
VGA: GeForce GTX680 2GB
HD : 500GB + 500GB + 2x1TB Raid Edition + 500GB External
Motherboard: ASUS CROSSHAIR FORMULA 4 890FX AM3
PSU: Corsair 750W
CPU Cooling: Katana 2
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You should set the hw_mapping to dynamic and invalidate the buffers by calling setDirty() on them. Also I'm not sure if you need to access the renderbuffer instead of the mesh - terrain is a little strange with the internal structure.
Revan1985
Posts: 89
Joined: Tue May 08, 2007 4:11 pm
Location: Italy

Post by Revan1985 »

bohm, resolved...
i've created a texture at runtime...
now, little question...
how i can use multitexturing with gl shaders? :?

i know i'm a "break balls", but i need this last information ^^'
CPU: AMD PHENOMII X6 1090T BE 3,2GHZ
RAM : OCZ 8GB 2*4GB DDR3 LOW VOLTAGE 1333
VGA: GeForce GTX680 2GB
HD : 500GB + 500GB + 2x1TB Raid Edition + 500GB External
Motherboard: ASUS CROSSHAIR FORMULA 4 890FX AM3
PSU: Corsair 750W
CPU Cooling: Katana 2
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You can access all textures set via the texture variables.
Revan1985
Posts: 89
Joined: Tue May 08, 2007 4:11 pm
Location: Italy

Post by Revan1985 »

i need to load all the textures in the shader, and not pass them with setMaterialTexture...

there is a method?

my shader had 4 Texture variables...

and this is the structure of the VertexShader

Code: Select all

struct MTVertexToPixel
{
	float4	Position		: POSITION;
	float4	Color			: COLOR0;
	float LightingFactor		: TEXCOORD0;
	float2	TextureCoords	: TEXCOORD1;
	float4 LightDirection		: TEXCOORD2;
	float4 TextureWeights		: TEXCOORD3;
};
CPU: AMD PHENOMII X6 1090T BE 3,2GHZ
RAM : OCZ 8GB 2*4GB DDR3 LOW VOLTAGE 1333
VGA: GeForce GTX680 2GB
HD : 500GB + 500GB + 2x1TB Raid Edition + 500GB External
Motherboard: ASUS CROSSHAIR FORMULA 4 890FX AM3
PSU: Corsair 750W
CPU Cooling: Katana 2
Post Reply