Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Vector Array and Transforms  (Read 2203 times)

0 Members and 1 Guest are viewing this topic.

Banbeano

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Vector Array and Transforms
« on: August 08, 2013, 06:22:53 pm »
In my current project I have been trying to unify my draw calls down to as few as possible. I took all the shapes and spites that I was using and added them to a Vertex Array. Seemed simple enough at the time, so I wrote the entire draw manager class to accommodate that design. Everything went quite smooth, until I started implementing rotate and scale functions. I can't seem to figure out a way to transform only the parts of the Vertex Array that need to be rotated or scaled without transforming everything within the Vertex Array. What I would like to do is to transform individual shapes in the Vertex Array so they can act separately but still be drawn in one draw command.
I looked around on the internet for an answer, came up empty, and the documentation on the .net version of SFML is kind of spotty. I'm really stumped on this one, and it's really starting to bug me.
Any help or pointers would be appreciated.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Vector Array and Transforms
« Reply #1 on: August 08, 2013, 06:28:43 pm »
You can transform the positions of an entity's vertices with a Transform instance and its TransformPoint function.
Laurent Gomila - SFML developer

Banbeano

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Vector Array and Transforms
« Reply #2 on: August 09, 2013, 02:54:47 am »
Could I get and example of use? I already tried to use PrasnformPoint for this and I couldn't get it to work.

What I came up with was:

               
Code: [Select]
if (entityList[i] == name)
                {
                    transform = state.Transform;
                    transform.TransformPoint(vertexArray[(uint)i * 4].Position);
                    transform.TransformPoint(vertexArray[(uint)i * 4 + 1].Position);
                    transform.TransformPoint(vertexArray[(uint)i * 4 + 2].Position);
                    transform.TransformPoint(vertexArray[(uint)i * 4 + 3].Position);
                    state.Transform.Rotate(degrees);
                    state.Transform = transform;
                }

Am I even on the right track here?
« Last Edit: August 10, 2013, 11:22:33 am by Banbeano »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Vector Array and Transforms
« Reply #3 on: August 09, 2013, 07:58:34 am »
Quote
transform.TransformPoint(vertexArray[(uint)i * 4].Position);
transform.TransformPoint returns a new point, it doesn't transform its argument.

Quote
 state.Transform.Rotate(degrees);
state.Transform = transform;
Rotating state.Transform has no effect since the next line of code overwrites it with another Transform instance.
Laurent Gomila - SFML developer

Banbeano

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Vector Array and Transforms
« Reply #4 on: August 10, 2013, 01:54:27 am »
Whoops, sorry that was supposed to be:

Code: [Select]
if (entityList[i] == name)
{
     transform = state.Transform;
     transform.TransformPoint(vertexArray[(uint)i * 4].Position);
     transform.TransformPoint(vertexArray[(uint)i * 4 + 1].Position);
     transform.TransformPoint(vertexArray[(uint)i * 4 + 2].Position);
     transform.TransformPoint(vertexArray[(uint)i * 4 + 3].Position);
     transform.Rotate(degrees);
     state.Transform = transform;
}

Stupid typo.

Thank you Laurent for your help, but I'm still rather confused on how you would use it to select the vertexes. I'm still playing around with it to get it to work, but an example of use would be extremely helpful.
« Last Edit: August 10, 2013, 11:21:57 am by Banbeano »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Vector Array and Transforms
« Reply #5 on: August 10, 2013, 10:40:03 am »
vertex.Position = transform.TransformPoint(vertex.Position);

PS : please use the code tag to format your code blocks ;)
Laurent Gomila - SFML developer

Banbeano

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Vector Array and Transforms
« Reply #6 on: August 11, 2013, 06:55:59 am »
Thank you for the example that was very helpful. I was able to select the point, but I still haven't got it to actually transform anything. The points just snap over to the top left (0,0) and don't do much. I'm guessing it has something to do with not setting the origin, which I have no idea how to do with a vertex array.

Code: [Select]
if (entityList[i] == name)
{
    tempVertex = vertexArray[(uint)i * 4];
    transform.Rotate(degrees, vertexArray[(uint)i * 4].Position);
    tempVertex.Position = transform.TransformPoint(tempVertex.Position);
    vertexArray[(uint)i * 4] = tempVertex;
                   
    tempVertex = vertexArray[(uint)i * 4 + 1];
    transform.Rotate(degrees, vertexArray[(uint)i * 4].Position);
    tempVertex.Position = transform.TransformPoint(tempVertex.Position);
    vertexArray[(uint)i * 4 + 1] = tempVertex;

    tempVertex = vertexArray[(uint)i * 4 + 2];
    transform.Rotate(degrees, vertexArray[(uint)i * 4].Position);
    tempVertex.Position = transform.TransformPoint(tempVertex.Position);
    vertexArray[(uint)i * 4 + 2] = tempVertex;

    tempVertex = vertexArray[(uint)i * 4 + 3];
    transform.Rotate(degrees, vertexArray[(uint)i * 4].Position);
    tempVertex.Position = transform.TransformPoint(tempVertex.Position);
    vertexArray[(uint)i * 4 + 3] = tempVertex;
}

What am I missing here?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Vector Array and Transforms
« Reply #7 on: August 11, 2013, 12:58:20 pm »
Sorry, this is becoming more complex and I don't have the time to understand your code :-\

You should write a new small app from scratch to test the Transform class and understand how it works, instead of trying to make your final algorithm work directly. When something becomes too complicated, breaks it into smaller / simpler parts, and come back to the original code once you understand everything.

PS: you should use the code=csharp tag :P Don't you see the "code" combo box in the WYSIWYG controls above the post editor?
Laurent Gomila - SFML developer

Banbeano

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Vector Array and Transforms
« Reply #8 on: August 12, 2013, 01:14:44 am »
Well the complexity was the general problem for me too. Believe me it really doesn't get much simpler than this. There is a lack of useful information on how vectorarray is used and even less on the .net binds, the forums were kind of my last hope. I appreciate what help you could give, an I'm sorry to have messed up my post as badly as I did.