Moving vertices. ManualObject or Buffer? How to?

Blackbeard

24-04-2007 15:48:21

Hi, i want to figure out how to move vertices.

I think its easier with ManualObject but i couldnt find a way to load i.e Ninja.mesh as ManualObject.
So i started to mess with buffers.

Given that this code isnt plain wrong (realy not sure), i should be able to use "element" to read vertex position, normal etc.
But i realy dont know how to use "element" then to get the values
("element" is a pointer which points to a pointer?....:shock:).


Into the buffer we ride:

ent2 = mgr.CreateEntity("ninja2", "ninja.mesh");
//test=ent2.GetMesh().Name;
vxdata = ent2.GetMesh().GetSubMesh(1).vertexData;
VertexElement ve = vxdata.vertexDeclaration.GetElement(1);

HardwareVertexBufferSharedPtr hvb = vxdata.vertexBufferBinding.GetBuffer(ve.Source);
void** element;
void* buffer=hvb.Lock(HardwareBuffer.LockOptions.HBL_READ_ONLY);
ve.BaseVertexPointerToElement(buffer, element);

//What to do with "element"??

hvb.Unlock();


Anyone could help?

Blackbeard

25-04-2007 18:23:19

First i have to get rid of "CS0165" (Use of unassigned local Variable).

Any ideas why "void** element" causes that error?

******************
ent2 = mgr.CreateEntity("ninja2", "ninja.mesh");

vxdata = ent2.GetMesh().GetSubMesh(1).vertexData;
VertexElement vee = vxdata.vertexDeclaration.FindElementBySemantic(VertexElementSemantic.VES_POSITION);
HardwareVertexBufferSharedPtr hvb = vxdata.vertexBufferBinding.GetBuffer(vee.Source);

void** element;
void* buffer=hvb.Lock(HardwareBuffer.LockOptions.HBL_READ_ONLY);
vee.BaseVertexPointerToElement(buffer, element);
hvb.Unlock();
*****************

Bekas

25-04-2007 19:42:26

What is the C++ snippet that you are trying to convert ?
In case you're not using a C++ snippet as reference, I'd suggest looking in the wiki, there are code samples on how to get vertices etc.

Blackbeard

25-04-2007 21:11:22

Hi, i try to convert:

http://www.ogre3d.org/wiki/index.php/RetrieveVertexData
(second example).

Tried to make the problem as small as possible and ended with the code
i posted. But then i get that error.


My second problem is to understand what "void** pElem" will be.

The manual doesnt help me:
void Ogre::VertexElement::baseVertexPointerToElement ( void * pBase,
void ** pElem
) const

"Adjusts a pointer to the base of a vertex to point at this element."

Whats ment with "Base of a Vertex" and "element"?
I dont know that terms but i realy want to open that nut :lol:

Bekas

25-04-2007 22:30:39

You need to do something like
float* element;
byte* buffer=(byte*)hvb.Lock(HardwareBuffer.LockOptions.HBL_READ_ONLY);
vee.BaseVertexPointerToElement(buffer, &element); // get the address of the element
hvb.Unlock();

float elementValue = *element; // get the value from the address

You pass the address of a pointer (it's used like a kind of an 'out' parameter) and BaseVertexPointerToElement passes the address of the specific vertex element (like position) that you want.

Blackbeard

25-04-2007 22:51:11

Me not want Bekas go away, we need hero here in town :wink:
Perfect!

Bekas

26-04-2007 09:48:17

Oh, now that I look at it again, Unlock should come after you are finished with the data of course:
float elementValue = *element; // get the value from the address
hvb.Unlock();

Blackbeard

26-04-2007 12:17:30

I tried both and it seems to not make a difference?
If its important (for writing to buffer it is i think) please tell :wink:


......
By the way, if someone read that and is is a noob like me.
You can get other elements by increasing *element like:

float elementValue = *element++;
or
float elementValue = *element+1;


And a how to play with pointer pointers:

int i = 25;
void* a = (void*)&i;
void** b = (void**)&a;
void* c = (void*)&b;
int number = (int)&c;

Bekas

26-04-2007 12:27:32

I'm not sure if it's important for reading too, better be on the safe side IMO..