x


My grid is getting created on the wonk

I have tried to debug this but I honestly cant see anything wrong with it, I was wondering if anybody can help.

Basically what it does is process a 64x64 pixel texture and deletes sections of a grid based on the luminance of each pixel, I am in the process of revamping my code and all was going well until I reached this bit, I cant see why it would be making my grids come out with a diagonal slant as if each iteration was offsetting by one unit to the right.

heres what it looked like right in the obsolete code

alt text

and here is it in the new code

alt text

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class NoiseProcessor : MonoBehaviour
{
	
	public Texture2D noiseTex;
	public static Color[] pxList = new Color [4096];	
	
	// INIT
	void Start ()
	{
		pxList = noiseTex.GetPixels();
		TextureTranslator();
	}
	
	//CubeGrid.GridArray[i].gridColumn[i].name
	void TextureTranslator(){	
		
		int counter = 0;
		
		for ( int row = 0; row < 63; row++ ){
			for (int col = 0; col < 63; col++ ){
				
				//Debug.Log(row + "_" + col);
				
				
				if(isNotBlack(counter)){
					
					Cube.destroyBlock((GameObject)CubeGrid.GridArray[row].gridColumn[col].gameObject);
				} 
				Debug.Log(counter + " " + pxList[counter].grayscale);
				counter++;			
			}
		}
	}
	
	// is not black fuction ~ returns bool 
	bool isNotBlack(int i){
		if(pxList[i].grayscale 
                
more ▼

asked Aug 10 '11 at 12:18 AM

sacredgeometry gravatar image

sacredgeometry
379 12 17 27

thanks for fixing the formatting

Aug 10 '11 at 01:28 AM sacredgeometry
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

FIXED: The for loop conditional operator should have been <= not < it was the classic off-by-one error....FACEPALM!

more ▼

answered Aug 10 '11 at 01:02 PM

sacredgeometry gravatar image

sacredgeometry
379 12 17 27

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1129
x450
x378
x348

asked: Aug 10 '11 at 12:18 AM

Seen: 708 times

Last Updated: Aug 11 '11 at 12:10 AM