FitMesh or ScaleMesh?

Blitz3D Forums/Blitz3D Beginners Area/FitMesh or ScaleMesh?

ervin(Posted 2007) [#1]
Hi everyone.

I'm trying to fit a mesh to the viewport after the mesh has been created.

Does anyone know how to make a mesh fit within the bounds of a viewport?
I've been playing with ScaleMesh and FitMesh, but I've had no luck, as I don't know how to relate their use to things like GraphicsWidth and GraphicsHeight.

Thanks for any help.


Stevie G(Posted 2007) [#2]
Put a plane directly in front of the camera just beyond the near camera range, make it pickable and pick top left and bottom right.

Note GW / GH = graphicswidth / height

Plane = createplane()
positionentity Plane, 0,0,2
entitypickmode PLane, 2
CameraPick Camera, 0,0
ScaleX# = pickedx() : ScaleY# = pickedy()
CameraPick Camera, GW-1, GH-1
freeentity Plane

ScaleX = Pickedx() - ScaleX
ScaleY = Pickedy() - ScaleY

fitmesh Mesh, -ScaleX*.5, -ScaleY*.5, Meshdepth( mesh ) * .5 , ScaleX , ScaleY , Meshdepth( mesh )



** Note that if the mesh is a quad with no depth then replace that part with something like ...

fitmesh Mesh, -ScaleX*.5, -ScaleY*.5, -.5 , ScaleX , ScaleY , 1


Stevie


ervin(Posted 2007) [#3]
Thank you so much for your help.
You've been very helpful to me on my little project, both with direct answers to my questions, and with older forum threads where you've helped other people.
This really is a great community.

Okay, onto your solution...

That's a great idea - and really quite obvious now that it's been suggested to me.
I had trouble using a plane for picking the corners of the screen, but I used a flipped cube (like a skybox) and that worked!

Unfortunately the FlipMesh command still defeats me.
My mesh disappears if I use the FlipMesh command, and I just can't get my head around how FlipMesh works.
If I comment out the FlipMesh command, my mesh is visible.

Here's what I've got at the moment.
(buildMesh is just a routine that creates a mesh and adds some surfaces to it via AddVertex and AddTriangle).


Stevie G(Posted 2007) [#4]
To use a plane you must rotate it -90 on the pitch axis. Forgot to mention this.

Also, remember and place it at least camNear + 1 so that it's not culled by the near view clip plane ..

Local plane = CreatePlane()
RotateEntity plane, -90,0,0
PositionEntity plane, 0,0, camNear + 1
EntityPickMode plane,2


A better method would to probably adjust the camerazoom. What is the mesh you create using buildmesh? Do you have a screenshot or can you post code? Can you explain in more detail what you need this for and I'll have a better think about it?

Stevie


ervin(Posted 2007) [#5]
The mesh is just a bunch of quads stuck together with the intention of texturing each quad separately.
The ultimate aim will be to load an image, break it into textures, and apply each texture to the appropriate surface.

I've got your plane idea working now - excellent idea. Many thanks.

With FitMesh commented out, everything is fine.
Use the arrow keys to move around, and + or - to zoom in or out.
Note that the camera range is very small so it won't take much zooming for the image to go out of camera range.

With FitMesh I want to centre the mesh on the screen, and have it fill the screen vertically. I've used some hardcoded values in FitMesh to try and figure out what is going on, but it continues to defeat me.




Ross C(Posted 2007) [#6]
Just watch your surface count, if your doing what i think you are. Too many surfaces can really put the brakes on the speed.


ervin(Posted 2007) [#7]
Hi Ross.

Yeah that's something I've yet to consider if I want to display a large image... I'm sure I'll run into it later on though.
Thanks.


ervin(Posted 2007) [#8]
I think I've had a breakthrough with understanding the FitMesh command!
It looks as though the x,y,z parameters are relative to the mesh's current position.
Is this right?

Replacing the FitMesh line in my code above with the following makes all the difference:
FitMesh mesh,-1,-0.5,0,2,1,MeshDepth(mesh),1
Looks like using 0 as the z parameter keeps it in the same spot as opposed to putting it into a bounding box?
Also, it wasn't showing up until I changed the Uniform parameter to 1.

Another weird thing is that changing the width parameter to 1 hides the mesh!
It's as if the width parameter is affecting the position instead of the bounding box width?

Despite this (slightly) better understanding of FitMesh, I'm still very confused!

[*** EDIT ***] I've solved it!!! Yippee!!!
Thanks for your help Stevie G.

It's actually very simple, and I feel a bit silly now.
Ah well.

Here's the correct FitMesh command for my requirements.
FitMesh mesh,boundLeft,boundBottom,0,boundRight-boundLeft,boundTop-boundBottom,MeshDepth(mesh),1