scaling and coordinates headache:
Blitz3D Forums/Blitz3D Programming/scaling and coordinates headache:
| ||
Haylp! The theory is quite simple. I want a large 3D grid area which is encased in a primitive cube with a grid textre on the outsidev(Alphad and with backfaces not culled to give it a see-through appearance). Another primitive, alphad a bit acts as a cursor which shouldmove around the grid. My problem: After scaling to fit the cube to the grid texture,( i want a large play area too) Im finding that my coordinates just aren't making sense... can anyoine have a look and possibly modify it so it all fits? PWEEEASE! Sorry to ask this, but Ive been beaten by this all day, no matter how many times I come back to it... All code is self-contained (i.e textures etc) |
| ||
Hi Malice :) I just tried the code and the first thing is this movement with the cursor keys and [A] and [Q]. The cube moves way to fast, so i changed the 40 to 0.1 And i have a question, are you trying to make the cube (cursor) move inside the cube freely or do you want it to follow the surfaces inside the large grid cube? |
| ||
Hi! Sorry, Im writing it on my laptop which is dead slow hehe - Anyway, yeah the cube needs to move freely but in steps equal to the 8x8 grid squares. Hnce the 40 step size (maybe a 100ms delay in the while/wend might help) The main problem I have - the grid just seems to be placed at a weird location - Im sure its something to do with using ScaleMesh/ScaleEntity - but I am unable to understand the re-positioning of the Grid cube's handle... ___________________________________ edit - sorry, ya mighrt as well increase the camera viewport to fill the screen too (Its just like that where I lifted the code out) |
| ||
Yup, we're both stupid. I can't get it to work properly either. ;) Edit, ... nevermind. This works: ; graphics Graphics3D 640, 480, 0, 2 SetBuffer BackBuffer( ) ; camera Local camera = CreateCamera( ) PositionEntity camera, 0, 0, -16 ; grid Local grid = CreateCube( ) ScaleEntity grid, 4, 4, 4 EntityAlpha grid, 0.5 ; cursor Local cursor = CreateCube( ) ScaleEntity cursor, 0.5, 0.5, 0.5 PositionEntity cursor, 0.5, 0.5, 0.5 EntityColor cursor, 255, 0, 255 ; main program While KeyHit( 1 ) = False ; move cursor TranslateEntity cursor, KeyHit(205)-KeyHit(203), KeyHit(200)-KeyHit(208), KeyHit(16)-KeyHit(30) ; program end RenderWorld Flip Wend FreeEntity camera FreeEntity grid FreeEntity cursor End |
| ||
thanks for the real quick response, though and thanks for looking, Cermit! |
| ||
CooL! Thanks again! :) The use of TranslateEntity instead of MoveEntity for the cursor is a real godsend, I will need that in the future! Also, the KeyHit means the objects dont just zoom off into the distance on fast PC's. Oh well, Im gonna carry on looking at the differences between ScaleMesh/ScaleEntity and see if I can find where the handle is... |
| ||
Haha, sorry.. just didn't know that a cube is created with the size of 2 units. Just looked at the command reference. No problem :) |
| ||
Hmm, though neat and tidy, unfortunately that code doesn't help as I need to scale the cursor and it's movement to the Grid, which all needs to be suitably large as a play area. |
| ||
Hate to bump this, but I'm still stuck....... |
| ||
Sorry, could you explain the problem again? Your looking for a cube, textured with a grid? With a cube as a selector? |
| ||
I think your trying to achieve something like this?Graphics3D 800,600 SetBuffer BackBuffer() Global camera = CreateCamera() Global grid = CreateCube() Global gridtext=CreateTexture(256,256,2) SetBuffer TextureBuffer(gridtext) Color 180,180,180 Rect 0,0,256,256,0 Rect 1,1,254,254,0 Rect 2,2,252,252,0 SetBuffer BackBuffer() EntityTexture grid, gridtext EntityFX grid,16 Global scale# = 5 PositionEntity camera,0,0,-scale*3.2 ScaleEntity grid, scale, scale, scale ScaleTexture gridtext,1.0/scale,1.0/scale EntityAlpha grid,0.3 Global selector = CreateCube() EntityAlpha selector,0.7 PositionEntity selector,(scale*2)/-2 + 1,(scale*2)/-2 + 1,(scale*2)/-2 + 1 Global x% = 1,y% = 1,z% = 1 While Not KeyHit(1) If KeyHit(203) Then x = x - 2: If x < 1 Then x = 1 If KeyHit(205) Then x = x + 2: If x > (scale*2) Then x = x - 2 If KeyHit(200) Then y = y + 2: If y > (scale*2) Then y = y - 2 If KeyHit(208) Then y = y - 2: If y < 1 Then y = 1 If KeyHit(30) Then z = z + 2: If z > (scale*2) Then z = z - 2 If KeyHit(44) Then z = z - 2: If z < 1 Then z = 1 PositionEntity selector,(scale*2)/-2 + x,(scale*2)/-2 + y,(scale*2)/-2 + z UpdateWorld RenderWorld Flip Wend End The main thing to remember here, is that even though a cube is 1 unit, it's actually 2 wide, 2 high and 2 deep. So, to move a cube like that, you need to move it, twice it's scale. All the stuff for that grid is based on the scale variable. The texture is just a single square. It is scaled: scaletexture texture,1/scale,1/scale So it fits the cube properly and doesn't scale along with it. I position the cube using x,y and z co-ords according to the grid scale. 1,1,1 is the bottom left, closest corner. To position the cube: PositionEntity selector,(scale*2)/-2 + x,(scale*2)/-2 + y,(scale*2)/-2 + z (scale*2)/-2 + x scale*2 <<< because a normal unscaled blitz cube, is 2 wide/high/deep. /2 <<< divide all that by 2, because you taking the positioning from the middle of the cube. IN theory, the *2 and /2 cancel each other out, but it's good to see whats happening. +x <<< add on the co-ords to offset the cube to it's place inside the grid. I hope that helps and i hope it's what your after :o) |
| ||
Sorry Ross, I'll explain again - My texture is an 8x8 grid which will of course appear on all faces of the GRID cube. CURSOR is a smaller cube, of which I want the faces to be EXACTLY the same size as the squares of GRID's texture. The whole lot needs to be scaled up so that GRID is around 160 'units' along each vertex. (that's vertex of the cube, not the tri's!) Hope that's clearer. Sorted!!! Thanks a million! So - what you did there, is pretty much what I'm after! Il just try to incorporate it now, Thanks! |