[SOLVED] Mesh Orientation Author Message
Pixel Perfect
Member

 Post: #1 [SOLVED] Mesh Orientation I was wondering how I go about orientating a mesh plane created in code so its aligned facing the camera, like a billboard. I've tried using the mesh.transform() function and the Camera.matrix.orn() but don't seem to be able to get this working correctly. Its always producing movement of the plane. Any pointers greatly appreciated (This post was last modified: 11-14-2013 08:49 PM by Pixel Perfect.)
11-12-2013 08:04 PM
Rubeus
Member

 Post: #2 RE: Mesh Orientation It seems to me that you should be just drawing the mesh using the Cam.matrix.orn(). If you keep transforming it, it seems to me that you would keep adding the same rotations over and over and over... Something like: mesh->draw(Matrix(meshPos, Cam.matrix.orn()); in the draw function, maybe? Actually, that seems like it would draw it backwards(facing away from the camera). Maybe rotate by Pi first. I could be way off, I'm a little rusty on my matrix maths.
11-13-2013 05:52 AM
Pixel Perfect
Member

 Post: #3 RE: Mesh Orientation Thanks for your advice Rubeus, I'll try that out. Likewise my matrix maths is not up to much being lucky in my last engine to have high level functions to do all this. Maybe having the complexity hidden is not so good as these functions can always be created once you understand the fundamentals I got the basic axis rotations working last night by using using the transform function with rotational matrices so I'm guessing one way is to simply calc the angles (basic trig) and then apply the three rotational transformations. That should leave it facing the right way because copying the camera rotation will as you point out leave the mesh facing the opposite direction. This is for my animated quads which are fully working apart from the option to rotate to face the camera as opposed to a static placement.
11-13-2013 09:29 AM
Rubeus
Member

 Post: #4 RE: Mesh Orientation What about just adding a Pi(180 degrees) rotation around Y to the cam matrix and drawing with that?
11-13-2013 06:13 PM
Pixel Perfect
Member

 Post: #5 RE: Mesh Orientation Still getting nowhere with this. I can position the mesh successfully using mesh.move(). I can rotate the mesh in any axis whilst maintaining its position using mesh.transform and applying a rotation matrix. Using your suggestion Rubeus always seems to result in a positional movement, no rotation appears to take place. I'd prefer not to get into lots of trig and rotation on three axis if there is an easier way, that I am simply missing, to align the mesh to the camera. Greg, any chance of some help here. I though this was going to be easy but its proving anything but! No doubt due to my lack of experience of 3D maths and use of matrices.
11-14-2013 12:04 AM
Rofar
Member

 Post: #6 RE: Mesh Orientation I'll take a shot here. Maybe something like this will work? In update Code: ```Vec cam_pos = Cam.matrix.pos; cam_pos.y = meshPos.y;    Vec dir = cam_pos - meshPos; dir.normalize(); Matrix mat;// actually defined as a class member so it is available in draw mat.setPosDir(meshPos, dir, Vec(0, 1, 0));``` In draw Code: `mesh->draw(mat);`
11-14-2013 12:39 AM
Pixel Perfect
Member

 Post: #7 RE: Mesh Orientation Thanks for the code Rofar. I tried this last night and I'm still getting the same issue of it seemingly translating into positional movement. However, having had a break overnight it's occurred to me this morning that possibly what I'm seeing is rotation but in global space, as my test mesh position is a good way from the origin and that would look like positional movement at that distance as the radius is so large. I'll check my code again tonight (at work currently).
11-14-2013 10:24 AM
Pixel Perfect
Member

 Post: #8 RE: [SOLVED] Mesh Orientation Many thanks guys, problems solved. Turns out I'd left a mesh move statement in my code which had already placed it prior to the call to mesh->draw(Matrix(meshPos, Cam.matrix.orn()); This was the source of the problem. Many thanks Rubeus, your solution worked a treat!
11-14-2013 08:53 PM
 « Next Oldest | Next Newest »