Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: Doesnt render in 3D with Bitwise Operator '&'

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    6
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Doesnt render in 3D with Bitwise Operator '&'

    Ive bin making a small game engine and right now im working on the 3Drender portion of it is giving me alot of trouble.

    Ive re wrote it twice and for the most part its working but when i try to put them together the screen turns black. My fps counter still counts though so im not sure whats wrong.

    public class Render3D extends Render {
    	public Render3D(int WIDTH, int LENGTH) {
    		super(WIDTH, LENGTH);
    	}
     
    	public void floor() {
    		for (int y = 0; y < LENGTH; y++) {
    			double yDepth = y - LENGTH / 2;
    			double z = 100.0 / yDepth;
     
    			for (int x = 0; x < WIDTH; x++) {
    				double xDepth = x - WIDTH / 2;
    				xDepth *= z;
    				[B]int xx = (int) (xDepth) & 5;[/B]
    				PIXELS[x + y * WIDTH] = xx * 135;
     
    			}
    		}
    	}
    }

    if you look near the bottom theres a portion with the bold tags, thats where im getting the issue I think
    Last edited by Edin; July 14th, 2012 at 11:12 PM.


  2. #2
    Member
    Join Date
    Jul 2012
    Posts
    119
    Thanks
    0
    Thanked 19 Times in 19 Posts

    Default Re: Doesnt render in 3D with Bitwise Operator '&'

    Edin....5 in binary is 101. Your operation int xx = (int) (xDepth) & 5; delivers only 4 values: 101 or 5, 100 or 4, 1 and 0. Is that what you want?

  3. #3
    Junior Member
    Join Date
    Jul 2012
    Posts
    6
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Doesnt render in 3D with Bitwise Operator '&'

    so since like its not a consistent value I cant use the & operator?

  4. #4
    Member
    Join Date
    Jul 2012
    Posts
    119
    Thanks
    0
    Thanked 19 Times in 19 Posts

    Default Re: Doesnt render in 3D with Bitwise Operator '&'

    Quote Originally Posted by Edin View Post
    so since like its not a consistent value I cant use the & operator?
    frankly, I don't understand what you mean. You got whatever xDepth is one of the 4 above mentioned values.

  5. #5
    Junior Member
    Join Date
    Jul 2012
    Posts
    6
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Doesnt render in 3D with Bitwise Operator '&'

    Quote Originally Posted by Voodoo View Post
    frankly, I don't understand what you mean. You got whatever xDepth is one of the 4 above mentioned values.
    do you have skype or something where you can show me what im doing wrong?

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Doesnt render in 3D with Bitwise Operator '&'

    thats where im getting the issue I think
    How do you know? Your posted code demonstrates nothing of the problem for us because it lacks context, let alone comments on what the methods are actually trying to do, and you've mentioned nothing as far as the calculations - what you expect and what you get. This leaves us with nothing but to guess, sometimes correctly, more often than not incorrectly. Here's my advice: add some println's in there to inspect the values, or throw the code through a debugger. How do the values of these variables differ from what you expect? And finally, if you wish to put your problem into context, then I recommend that you post an SSCCE

  7. #7
    Junior Member
    Join Date
    Jul 2012
    Posts
    6
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Doesnt render in 3D with Bitwise Operator '&'

    Quote Originally Posted by copeg View Post
    How do you know? Your posted code demonstrates nothing of the problem for us because it lacks context, let alone comments on what the methods are actually trying to do, and you've mentioned nothing as far as the calculations - what you expect and what you get. This leaves us with nothing but to guess, sometimes correctly, more often than not incorrectly. Here's my advice: add some println's in there to inspect the values, or throw the code through a debugger. How do the values of these variables differ from what you expect? And finally, if you wish to put your problem into context, then I recommend that you post an SSCCE
    its not an error per say because I've ran it through me debugger and everything was fine no error codes or anything. its just I was to merge the screens together ill post a pic:

    Shifting:

    548437728f6737f31dfae2be3d65a622.jpg

    Using AND to put the images together:

    8cc8156157702df0deb32d8759701f01.jpg
    Last edited by Edin; July 16th, 2012 at 03:02 PM.

  8. #8
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Doesnt render in 3D with Bitwise Operator '&'

    I still don't understand how that code relates to your problem: you have yet to provide an explanation as to what the code is supposed to do - either through an SSCCE, comments, or a description. Why do you want to bitwise and operate against the value 5? What is the method floor supposed to accomplish? As written, how does it try to accomplish that?

  9. #9
    Junior Member
    Join Date
    Jul 2012
    Posts
    6
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Doesnt render in 3D with Bitwise Operator '&'

    as written it is suppose to give me the basic floor and roof 3D model for my game. I used a demonstration of how Notch created his 3Dmodel for early minecraft using the same model as his cave demo. The value of 5 is the definition of the floor and roof, as I increase or lower the number the definitions change, Im using 5 as that was the definition used in his demonstration and is what he used in a later step of adding on textures.

  10. #10
    Member
    Join Date
    Jul 2012
    Posts
    119
    Thanks
    0
    Thanked 19 Times in 19 Posts

    Default Re: Doesnt render in 3D with Bitwise Operator '&'

    Edin,
    I assume that you misunderstand the & and the shifting operation << or >>
    Shift left 5 positions: int xx = (int) (xDepth) << 5 (or multiply by 32)
    Shift right 5 positions: int xx = (int) (xDepth) >> 5 (or divide by 32)

  11. #11
    Junior Member
    Join Date
    Jul 2012
    Posts
    6
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Doesnt render in 3D with Bitwise Operator '&'

    ohhh :S ima dumbass -.-'

Similar Threads

  1. JDialog Failing to Render...
    By snowguy13 in forum AWT / Java Swing
    Replies: 2
    Last Post: April 7th, 2012, 11:55 AM
  2. confused on what this problem is asking for (bitwise operators)
    By mmholdford in forum Java Theory & Questions
    Replies: 3
    Last Post: February 9th, 2012, 06:52 AM
  3. Render data on next page
    By Rajat in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: March 25th, 2011, 09:46 AM
  4. BITWISE
    By bitwise11 in forum The Cafe
    Replies: 0
    Last Post: January 25th, 2011, 01:09 PM
  5. Unable to render printing the complete JPanel
    By Stephen Douglas in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 13th, 2010, 11:48 AM

Tags for this Thread