I'm Really Lazy
and forget to post my blog.

❣ Chile in a Photography ❣

titsay

Love Begins
No title available
Show & Tell

if i look back, i am lost
sheepfilms
taylor price
Cosimo Galluzzi

@theartofmadeline
★
No title available
Cosmic Funnies
YOU ARE THE REASON
occasionally subtle

Kiana Khansmith

Product Placement
let's talk about Bridgerton tea, my ask is open
Not today Justin
macklin celebrini has autism
seen from Palestinian Territories
seen from Thailand
seen from Czechia
seen from Singapore
seen from Vietnam
seen from Türkiye
seen from United States

seen from Canada
seen from Australia

seen from United States

seen from United States
seen from United States
seen from T1
seen from India

seen from Singapore

seen from Singapore
seen from United Kingdom
seen from Türkiye
seen from France
seen from United Kingdom
@ryangoodwin565-blog
I'm Really Lazy
and forget to post my blog.
My shadows. They look weird, I'm going to redo them.
Adding lights and shadows.
Using vectors. Fun stuff!
This is just a video of my updated editor, without the annoying flashing, and also with a way to paint blocks which I implemented using the MouseDragged() method of the MouseMotionListener interface. The numbers are the Z coordinates for each cube, which I'm using for testing.
Testing to the point where you no longer know what you're testing.
Fix flashing graphics with double buffering
Yesterday I posted a video of my map editor, which was almost unwatchable because of all the flashing in it. I decided that since I didn't know what was wrong, other people are also having the same problem, and because I am so cool and amazing I will tell you how to fix it.
The flashing occurs when you draw the graphics in steps, for me it was because I was clearing the screen and then drawing the shapes. Which, when the graphics were updated a lot, caused a white flicker when the screen was being cleared.
A solution to the problem is to draw all graphics to a temporary off screen image, and when this is finished draw the image to the screen. This way each time the graphics are drawn, only one image is being drawn and so there will be no flickering.
To accomplish this in Java, I created a temporary Graphics object called tempGraphics and an Image object called offscreenImage. I then assigned the Graphics from the image to the temporary graphics using
tempGraphics = offscreenImage.getGraphics();
This means that whenever anything is drawn to tempGraphics, it is actually drawn to the image, since tempGraphics now points to the images Graphics object.
Now, in the paint method where you would usually draw to the Graphics object passed as a parameter, you instead draw to tempGraphics, so that all graphics are drawn to the offscreen image.
When you are done drawing to the image you draw the image to the screen using the drawImage() method of the Graphics in the paint method.
In case I didn't explain this well, here is some code as an example...
private Graphics tempGraphics; private Image offscreenImage;
public constructor() { ... offscreenImage = createImage(width,height); tempGraphics = offscreenImage.getGraphics(); ... }
public void paint(Graphics g) { tempGraphics.clearRect(0,0,width,height); tempGraphics.drawSomethingElse();
g.drawImage(offscreenImage,0,0,this); }
HURRAY! I finally got my map editor to so something! :D It's not amazing and it flashes a lot (I don't know why it does this) but I'm happy because I've been trying to get this to work for AGES! Next step - sort out the mysterious flashing, and add more features such as..
More colours/ types of cube.
A way to 'paint' instead of just clicking everywhere.
File reading/ writing.
THIS IS GETTING WORSE D:
Get something wrong with rotation, map editor breaks completely! I have no idea what's going on here.
Working on a map editor.
I know I haven't posted much in a while, I've been busy on a speech recognition software for my AI coursework which I have now completely given up on.
So now I'm just going to start work on a map editor, at the moment just a simple one to place blocks so I can create a few landscapes to play around with.
I'm still wondering about the best way to store the map data in a file though.
Thoughts on time travel in the game.
I know I want to incorporate some kind of time travel into the game since the main story involves fixing time paradoxes which you accidentally create, but I'm not sure how deep I want to go with this. One way would be to just allow time travel at specific times and places, only to accomplish a single goal. This would be easier to create, but not as fun as if you could travel to any time and place, and just explore and interact with things, altering time with each move so that you could return to a completely different future.
I'm not sure how complicated the second idea would be, I would need to keep track of every interaction that happens from the start, so that if something prevents one of those interactions or even creates a new one, then the whole chain of events would be updated altering the different time periods.
I'll think about this some more and let you know, I just thought I needed a break from coding cubes to think about the actual game for a bit.
All this talk of time also reminded me that Doctor Who starts again on Saturday! :D
Almost there!
Well all the cubes are now drawn in a correct order and it wasn't as hard as I thought it would be, I just store the cubes in an array and loop through in different ways depending on rotation. So if the angle around the z axis is between 0 and 180 then loop through the x values in ascending order, otherwise loop through in descending, if the angle is between 90 and 270 loop through y in descending order, otherwise in ascending order.
The result is this spinning 3D object thing, which I saved until last because it was making me feel dizzy!
Faces showing when they shouldn't be
I decided to test whether I was ready to create groups of cubes necessary for creating the game worlds. It was easy to create a group of cubes using a 3D array, and then to render the group to the screen I just looped through the array and drew each cube individually.
Then I ran into a problem! Because each cube had 3 faces drawn, sometimes the faces were overlapping the cubes in front of them, making the mess you see before you in the first image! To fix this, I added a few more methods to my Cube class, so that each cube now holds references to each of the other adjacent cubes and if there is a cube next to a face to be drawn, then it simply does not draw that face! The result is in the second image..
Obviously though, this does not fix everything, for if there are no adjacent cubes the sides will still be drawn anyway and could overlap front cubes. To fix this I could either, only draw visible cubes, or draw the cubes from furthest to closest. It sounds like this could get very complicated!
Also I just noticed this but some of the lines in the second image seem a bit wonky. I think this is just a case of casting doubles to ints instead of using Math.round() and should just be a small fix.
Annoying mistakes!
An hour of confusion and rewriting code because I forgot to initialize an array! D:
Detecting visible faces without perspective
Now only visible faces are drawn to the screen, the only problem is that I had to turn off perspective to get this working! Aaarrgh!
Anyway, after trying many methods I decided to just compare the Z coordinate of the centers of opposite faces, and display the face that was closer. So in the above image, the blue and red faces are opposite, and when rotated the correct face is shown.
This is just a simple method for use with cubes, I don't think it would work with other shapes. But if you want to use more complicated shapes you could try and figure out how this works.. http://gpwiki.org/index.php/Backface_culling. I thought I understood it. But then it didn't work!
A quick note on finding visible faces.
So what I wanted to do was only render visible faces of each cube to the screen, as otherwise I would have trouble with them overlapping and also there's no point drawing what can't be seen. One idea from greysequences in the comments was to use Shape.intersects() to see whether one face was hiding another, this would probably be useful at some point, however I think it would be too tricky to use at the moment as a back face may be hidden half behind one face and half behind another and it sounds complicated. The idea I came up with was to pair opposite sides of the cube together, then compare the Z coordinates of each pair and only draw the side further forward. This would probably work since you can always see at most 3 sides of a cube, and never opposite sides. I'm still trying to figure it out myself, But if I get it working with this method I will explain it properly!
I figured out how to use colours! I was getting bored of just black lines. Use the java.awt.Color class to create a colour ( For now I just used random RGB values ). I used the setColor() method of the Graphics object, and fillPolygon() instead of drawPolygon() to fill the sides of the cube with that solid colour. I got angry having to spell colour wrong loads of times! Because I'm English and we spell it right! Nahhh I don't know who spells it right anymore, coding the colours has broken my brain. D:
Oh yeah and with the use of colours I discovered a new problem, you can probably tell by the picture but the faces of the cubes are drawn weird. Some back faces are being rendered after front faces which is wrong. I'm going to think of a way to only show visible faces on the screen anyway, so that shouldn't be a problem later on. I feel like I've used the word colour too many times now, so I will leave you! :)