grid problem

Blitz3D Forums/Blitz3D Programming/grid problem

Amanda Dearheart(Posted 2012) [#1]
I'm having two problems with this bit of code!

1. It is displaying a mysterious mesh that I don't want displayed, but I cannot find the instruction that is displaying it!

2. Basically, I want to display a 10 x 10 grid of cells using the same mesh loaded into an array. Of course, if an array is the wrong construct, let me know?




Midimaster(Posted 2012) [#2]
I would say, the additional mesh you see is the first one you use in LOADMESH. It is placed on coordinates 0/0. If you want to solve this problem use:

Function LoadGraphics()
	Cells(0) = LoadMesh("C:\Documents.....
.....

Function Game()
	For x = 1 to 122
		Cells(x) = CopyMesh(Cell(0))
.....




Your array:

If it works for you.. it is OK. What you could change is using TYPES where you could combine Array with Meshes:

Type PositionTyp
     Field Mesh%
     Field Flag%
End Type

Dim Cells.PositionTyp(11,11)

For x=0 to 10
     For y=0 to 10
          Cells(x,y)\Mesh= New PositionTyp
.....

Function Game()
     For x = 0 to 10
           For y=0 to 10
		Cells(x,y)\Mesh = CopyMesh( Cell(0,0)\Mesh )
.....


Last edited 2012

Last edited 2012


Amanda Dearheart(Posted 2012) [#3]
So how does using Cell(0) instead of Cell solve the problem?
In other words, what is Cell(0) doing that makes it not display on screen when Cell does.


Floyd(Posted 2012) [#4]
	For x = 0 To 122
		Cells(x) = CopyMesh(cell)
	Next
	
	PositionEntity cam, 0, 0, -10
	
	; this is a test function to display the meshes in a grid 10 x 10
	For x = 1 To 11
		For y = 1 To 11
		
			f = ((10 * (x - 1)) + y)  ;  convert x,y 1 - 11 to array 1 - 100
			PlaceMesh(Cells(f), 100, 100)


This starts with one original cell mesh. The first loop makes 123 copies, for a total of 124 meshes. Then the nested x,y loops position 121 of them, placing them far offscreen where they can't be seen. This all needs a serious rethink.

Looking ahead, you almost certainly should be making the copies with CopyEntity(cell) rather than CopyMesh. A mesh is a collection vertex data which the graphics card must deal with. An entity is a Blitz construct. Among other things it can refer to a mesh which will be drawn.

The usual Blitz3D method for this is to load one mesh and hide it so it will not be seen. Then make many copies using CopyEntity. These can be separately moved, scaled, textured, hidden, shown etc. But they all use the same underlying mesh.

The idea is that the graphics card is a special purpose computer. It takes mesh data and does a zillion calculations, transforming that data in various ways and ultimately putting pixels on the screen. Blitz3D does the dirty work for you, setting up the transformations. Let's say the entity position has been changed from the original (0,0,0) to (10,0,0). The relevant transformation will be set up so the graphics card will read the mesh data and then add 10 to all x-coordinates before continuing its calculations.

Last edited 2012


Midimaster(Posted 2012) [#5]
My idea was, that the entity CELLS(0) is later still used in your code, but never the entity CELL, which you created only for loading. but of course also this CELL remains in your world.

Sorry for the typo: I wrote CELL(0) but it has to be CELLS(0)....


Amanda Dearheart(Posted 2012) [#6]
OK, Thanks!


Amanda Dearheart(Posted 2012) [#7]
@ midimaster

your suggestion (Cells(0)) does not solve the problem. The extra entity still appears even though I have used commands such as HideEntity and FreeEntity.

In other devs, I am going to need music and audio creation software. (pretty much the only thing missing from my suite of software) I don't have the money to purchase anything now, but maybe at the beginning of the year, or after taxes.

After checking out your site there, I see that you have things on your site. Perhaps you can recommend something, or send a demo of what you have!

@Floyd

I like your idea of using Entities to control my game, but after I've done what you suggested, I'm getting a blank screen instead of my grid. Perhaps I'm doing something wrong. I've searched trough the online manual for a CreateEntity instruction but cannot find anything!


Amanda Dearheart(Posted 2012) [#8]
@Floyd

Nevermind, I solved the problem. It looks like in my PlaceMesh function I didn't change the PositionMesh call to PositionEntity.