I'm having a problem where I must typecast an array of a certain class to an array of structs. So:
Class ClassName
{
};
void draw()
{
ClassName Uh;
vertexbuffer.setdata((struct)Uh);//here its wrong
}
How would I turn Uh into a struct?
Any help here would be greatly appreciated.
typecasting in C#
Started by Miguel De La Cruz, Aug 18 2007 01:16 PM
13 replies to this topic
Ad:
#5 Members - Reputation: 122
Posted 18 August 2007 - 02:23 PM
1) setdata only takes in a struct, it is used for vertices. I must have a class of it so I can derive from it.
2) yea, me sure. structs can't be derived in C#.
3) I must derive so I can control the vertices in different ways using a virtual update.
2) yea, me sure. structs can't be derived in C#.
3) I must derive so I can control the vertices in different ways using a virtual update.
#7 Members - Reputation: 144
Posted 18 August 2007 - 02:40 PM
He is trying to use a vertex buffer... I know this because I am sitting next to him. He isn't listening to my advice and should be creating a different type then what he has... (He has a ParticleVertex which holds TONS of data including velocities...) And thats unneeded, so he needs to make a different vertex deffinition to use in the vertex buffer
#9 Members - Reputation: 122
Posted 18 August 2007 - 02:43 PM
Telastyn, great idea! Why didn't I think of that? I blame this food to my left here. But thanks, I will try that. Eh nope, won't work... I must have the array of structs be derivable. You see the structs are verts like this:
struct array of
100 lava verts
200 exploding verts
100 smoke verts
and I must control the lava verts to flow downwards, but the rest to do their own thing. So basicly, they would all have an empty update except lava verts(derived) which would have a virtual update.
struct array of
100 lava verts
200 exploding verts
100 smoke verts
and I must control the lava verts to flow downwards, but the rest to do their own thing. So basicly, they would all have an empty update except lava verts(derived) which would have a virtual update.
#12 Members - Reputation: 1206
Posted 20 August 2007 - 02:00 AM
Quote:
Original post by Miguel De La Cruz
(scratches head)
Compare it to numbers. A number is a number, nothing more. You can use a number to indicate a player's health, and when it reaches to 0 the player dies, but you aren't going to put that logic in number, but in player.
Keep the simple concepts simple. If you need to add logic to them, building a new concept (a new class) around it might be a better solution.
#14 Moderators - Reputation: 2286
Posted 21 August 2007 - 02:48 AM
Stop thinking so low level. Vertices are vertices, they are "dumb" structures that just hold data and have no logic. The logic is in a higher-level object that holds some vertex data -- that object can be derived from, have behavior overridden via dynamic dispatch, et cetera. So you might have a
then you might have TerrainRenderObject and SuperRobotRenderObject and LavaMonsterRenderObject -- whatever. Update the vertices as you need to in the overridden Update() method, and use the Vertices property to access the raw verts for SetData() et al.
(I feel compelled to point out that I do not not like this design, but it addresses your issue.)
class BasicRenderObject
{
private Vertex[] verts;
public Vertex[] Vertices
{
get
{
return verts;
}
}
public BasicRenderObject(int vertexCount)
{
verts = new Vertex[vertexCount];
}
public virtual void Update()
{
// No-op in base class.
}
}
then you might have TerrainRenderObject and SuperRobotRenderObject and LavaMonsterRenderObject -- whatever. Update the vertices as you need to in the overridden Update() method, and use the Vertices property to access the raw verts for SetData() et al.
(I feel compelled to point out that I do not not like this design, but it addresses your issue.)






