Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (749)
Games in Android Showcase (226)
games submitted by our members
Games in WIP (838)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: 1 ... 196 197 [198]
  ignore  |  Print  
  What I did today  (Read 2356857 times)
0 Members and 8 Guests are viewing this topic.
Offline abcdef
« Reply #5910 - Posted 2018-03-13 13:44:17 »

Got distracted building my ui interface, in my quest to get a rounded rectangle I ended up building a new vector graphics engine which has a nice triangulation routine to triangulate any shape (convex, concave, single hole, many holes). Also allowed me to do some nice gradient shading / texturing on any shape.

I'd be very interested if you'd like to share that code! Smiley

It's hard to give you access to all the code but I can tell you the general principals

1) The triangulation for the filling of the shapes was based on "Sweep-line algorithm for constrained Delaunay triangulation" by V. Domiter and and B. Zalik
2) The stroke drawing was just basic LINE_LOOP of the various contours provided
3) The drawing of shapes was done using a similar api that we go uses but adapted to be easier to use in my opinion. you have a shape which can have many closed contours, you can line to somewhere, beside to somewhere, create circles, ovals, rectangles, rounded rectangles etc.
4) This data feeds the algorithm and you get a list of triangles finding out which uses all your point (nomore are created).
5) when you get the triangles I find a bounding box then calculate texture coordinates for all points and then use this for filling with either a texture, a single colour or a gradient colour.
6) I don't have anti aliasing yet but will add later one I have built all my ui components
7) my ui components can be drawn with the vector api

That's basically it, it looks pretty cool and you have lots of holes in a shape and it textures perfectly around it
Offline Longarmx
« Reply #5911 - Posted 2018-03-15 17:21:24 »

The last couple days, I added global variable support and while loops to a compiler I've been working on. It compiles a "miniC" language to mips32. So, this code:
// Declare and assign variables
my_var = 2;
counter = 10;
// Perform some operations
while(counter = counter - 1) {
    my_var = 2 * my_var;
// Print it out
print my_var;

compiles to this:
counter: .word 0
my_var: .word 0
li $t1 2
la $s1 my_var
sw $t1 0($s1)
li $t2 10
la $s2 counter
sw $t2 0($s2)
lw $t3 0($s2)
li $t4 1
sub $t3 $t3 $t4
sw $t3 0($s2)
beq $t3 $zero while_end_1
addi $sp $sp -4
sw $t4 0($sp)
li $t4 2
lw $t5 0($s1)
mul $t4 $t4 $t5
sw $t4 0($s1)
j while_top_1
addi $sp $sp -4
sw $t5 0($sp)
lw $t5 0($s1)
li $v0 1
add $a0 $zero $t5
li $v0 11
li $a0 10

and prints

This has been a really exciting project so far. If you want to view the code, here is the github.

Offline theagentd
« Reply #5912 - Posted 2018-03-18 01:05:15 »

Had my last uni exam today. Now I only have one more left this summer and I'm done with uni.

Decided to have some fun and coded a super simple ok, maybe not that simple Falcon 9 FT rocket launch simulator in 2D. I've inputted the following data in SI units:

 - Earth's radius and mass
 - Earth's rotation and the "bonus" horizontal velocity gotten by launching from Cape Canaveral
 - Earth's atmospheric density approximated with an exponential function of height over ground

 - Target orbit altitude (400 000m Low Earth Orbit, just under the ISS) and the exact velocity needed to maintain that orbit

 - Rocket drag area (circle of radius 2.6315m) and approximated drag coefficient (0.25)

 - The following parameters for the two Falcon 9 FT stages:
    - Weight without fuel (22 tons, 4 tons)
    - Weight of fuel (410.9 tons, 107.5 tons)
    - Thrust (~8 000 000 N (actually 7 607 000 to 8 227 000 depending on altitude), 934 000 N
    - Burn time (162 sec, 397 sec)

The rocket is then assumed to rotate from 0 to 90 degrees over the course of the flight (you never want to point a rocket downwards or you will not go to space today), and this rotation is controlled using a Taylor series controlling the rotation. This allows the rocket to rotate at different rates at different parts of the flight. Basically, this allows the first stage to go more straight up to quickly get out of the thickest part of the atmosphere, and then quickly rotate over to the side to gain orbital speed as efficiently as possible. The Taylor constants are decided using a simple learning algorithm that tries to get rid of the error in altitude and orbital speed/direction. However, if the thrust is simply too high, the rocket will get a too high orbital velocity, so I also added the payload weight as a parameter, so if the rocket overshoots, I just add more weight to it. Also, the rotation of the Earth is taken into consideration, and the drag is calculated (approximately) based on the idea that the atmosphere rotates with the planet (so the rocket starts out travelling at around 408m/s together with the surface, but has zero drag since the air is rotating too).

The learning algorithm just tries random modifications to the taylor constants and the payload weight and checks if the result is a better end orbit than before (= lower error in altitude and orbital speed/direction), and given time it converges on the perfect settings for launching the rocket. After running the program for around 10 minutes and changing the learning rate as it went, I got the calculated error down:
 - -9.909272E-7 meter error in altitude
 - 6.1378614E-8 m/s error in velocity away from the Earth
 - -1.3683348E-8 m/s error in orbital velocity

In other words, the resulting orbit is off by less than a micrometer, and the velocity is off by even less than that. The maximum payload was determined to be 21843.23 kg, which is a bit lower than the payload the Falcon 9 FT is rated for, 22 800kg payload (possibly plus 1 700 kg, not sure if those 1.7 tons are included in the 22 800 number), but at least close enough to be in the same ballpark. Considering it's a 2D simulation I made with information I could Google in a couple of minutes, it's pretty cool.

Image of the trajectory:

The curve at the start comes from the fact that the planet is rotating, so the rocket starts with a high speed to the left but accelerates upwards. The color of the trajectory shows the two stages and how they deplete their fuel (which of course causes the rocket to get MUCH lighter over the course of the flight). Once the first stage is depleted, it instantly switches to stage 2 at which point stage 1 is jettisoned and no longer adding weight to the rocket. It would be possible to add a zero-thrust stage inbetween to add some time for the stage separation. No, the first stage doesn't fly back and land. =P

Some people go out drinking to celebrate, I write rocket simulations...

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Longarmx
« Reply #5913 - Posted 2018-03-18 01:18:34 »

No, the first stage doesn't fly back and land. =P

Ah, but that would be quite fun to watch the simulation calculate the first stage's trajectory!

Also, how many terms are in your Taylor expansion? And do you just evaluate it with a time since launch or some other variable?

Offline theagentd
« Reply #5914 - Posted 2018-03-18 01:50:25 »

Also, how many terms are in your Taylor expansion? And do you just evaluate it with a time since launch or some other variable?
I used 8 coefficients there, but even 3 can sometimes suffice; it depends on the parameters of the simulation. Yeah, I calculate x = (1 - currentTime/totalTime), use x, x^2, x^3, etc with the taylor coefficients and finally do angle = (1.0 - sum) * Math.PI/2 to get the thrust angle. Since my only real requirement is that the sum is 0 at the start and 1 at the end, I just make sure that the coefficients sum up to 1.0 and that handles it.

Pages: 1 ... 196 197 [198]
  ignore  |  Print  

Solater (10 views)
2018-03-17 05:04:08

nelsongames (30 views)
2018-03-05 17:56:34

Gornova (31 views)
2018-03-02 22:15:33

buddyBro (78 views)
2018-02-28 16:59:18

buddyBro (54 views)
2018-02-28 16:45:17

xxMrPHDxx (466 views)
2017-12-31 17:17:51

xxMrPHDxx (138 views)
2017-12-31 17:15:51

xxMrPHDxx (216 views)
2017-12-28 18:11:33

Ecumene (485 views)
2017-09-30 02:57:34

theagentd (593 views)
2017-09-26 18:23:31
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!