[Fixed] object update

All about the core api and animation, input, sound, effect, collision and physics engines.
You can also post here your feature requests.

Moderator: Brume Dev Team

[Fixed] object update

Postby bct on Sun Jan 07, 2007 5:00 pm

I am creating object in GameInit procedure and it works but when i create another object but after GameInit, it is invisible (but PickObject() returns this object from location at the screen)

So i tried to create all objects in GameInit and hide them - it works but i rather dont want to do that. And then i changed texture UV mapping and it is not working also.
I mean, when i change UV for my object in GameInit procedure, then it works but after that, changes i made have no effect at all, it stays like i set them when initialising. Is there any method to update texture so engine knows there are new UV coords?

With new UV coords i am changing texture too, and it iworks good but with old UV.
And this is my procedure
Code: Select all

private  BrumeSquareTextured[,] gameGrid;
private void resize()
{
            for (int i = 0; i < boardWidth; i++)
            {
                float posx = i * 20 - boardWidth * 9 + 0.5f;
                for (int j = 0; j < boardHeight; j++)
                {
                    float posy = j * 20 - boardHeight * 16 + 0.0f;
                    this.gameGrid[j, i].RenderStates.Texture[0] = game.GetTexture(number+".jpg");
                    BrumeSquareMeshTextured b = (BrumeSquareMeshTextured)this.gameGrid[j, i].Mesh;
                    float yy = boardHeight - j - 1;
                    float vu = 1 / (float)boardWidth;
                    float vv = 1 / (float)boardHeight;

                    b.vertices[0].Tu = i * vu;
                    b.vertices[0].Tv = yy * vv;
                    b.vertices[1].Tu = i * vu + vu;
                    b.vertices[1].Tv = yy * vv;
                    b.vertices[2].Tu = i * vu;
                    b.vertices[2].Tv = yy * vv + vv;
                    b.vertices[3].Tu = i * vu + vu;
                    b.vertices[3].Tv = yy * vv + vv;
                    this.gameGrid[j, i].Mesh = b;
                    this.gameGrid[j, i].Pos.X = posx;
                    this.gameGrid[j, i].Pos.Y = posy;
                    this.gameGrid[j, i].Pos.Z = 1.0f;
                    this.gameGrid[j, i].Size = 19.98f;
                }
            }
}


And this is supposed to be puzzle game, so i created few planes with different coordinates of the same texture (dunno better solution for now) - they have to be different mesh because they are animated.
resize() is called always when user change board size, it works when i call resize() from overrided GameInit() but after that it is not working. Do i miss something?
bct
Brume Rookie
 
Posts: 5
Joined: Sun Jan 07, 2007 3:26 pm

Postby Silmaryls on Mon Jan 08, 2007 6:44 am

Hi bct !

Try to call the "brume.InitObject(obj);" method when adding objects dynamically. I really had to do something about it...this all comes from the GameInit method that is a "well known" game engine pattern...but really bad practice to me...


When modifing UV texture mappings, you should declare your mesh as dynamic and use the GetVertexBuffer method that is :

Code: Select all
...
// InitGame
square = new BrumeSquareTextured(this, "mySquare");
square.Mesh.VbDynamic = true;
...
...
// MoveScene
BrumeVertex_PosNormTex1[] vertices = (BrumeVertex_PosNormTex1[])this.square.Mesh.GetVertexBuffer();
if (vertices != null)
{
    vertices[0].Tu = textureDelta;
    vertices[1].Tu = 1.0f + textureDelta;
    vertices[2].Tu = textureDelta;
    vertices[3].Tu = 1.0f + textureDelta;
    this.square.Mesh.SetVertexBuffer(vertices);
}




This way it should work.
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France

Postby bct on Mon Jan 08, 2007 7:57 am

I was trying to use GetVertexBuffer() but i didnt know what to use as an array, now it looks good and works. Thank you very much! :)
bct
Brume Rookie
 
Posts: 5
Joined: Sun Jan 07, 2007 3:26 pm


Return to Technical discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron