Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / - DBPro Coding Challenges -

Author
Message
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 25th Feb 2005 08:10
ah crap, i was about to add a gradient.

"eureka" - Archimedes
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 25th Feb 2005 08:24
Lol - beat you. How about trying to add a glow effect, or shadow effect around the edges? Could be tricky ......


Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 25th Feb 2005 08:34 Edited at: 25th Feb 2005 09:24
hmmmm, shadow could be easy and done from any angle with any depth. Speed would depend on the depth.

here's a simple box with rounded corners. I'm trying to think of a way to adjust the corners, without hard-coding it.


"eureka" - Archimedes
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 25th Feb 2005 09:07
Quote: "I'm trying to think of a way to adjust the corners, without hard-coding it."


Maybe using Chris's Beziers .......


Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 25th Feb 2005 09:21 Edited at: 25th Feb 2005 09:25
that would would be way to complex. Trying to determine exactly where the control points should be so that the bend happens at the correct coordinates.

Fixed the glow. Pick a glow color and thinkness.



and for a simple shadow effect that adds depth to the shape:


"eureka" - Archimedes
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 25th Feb 2005 10:13 Edited at: 25th Feb 2005 10:14
Cool - except is it just me that's getting black lines and dots?




Attachments

Login to view attachments
Chris64
20
Years of Service
User Offline
Joined: 16th Oct 2004
Location: San Diego
Posted: 25th Feb 2005 10:43
Is there no way to tap directly into directDraw for drawing Polygons? Before this challenge, I never looked into 2d graphics with DBP...I must say...they're unbelievabley limited. Heck even in VB you can draw full poly's just using the standard built in features.

I can really appreciate what you guys are doing pixel by pixel...but even if it all works and looks perfect it's still too slow of a method to use in any practical application. Especially when DirectDraw has these features built in that look perfect and run about 10,000 times faster.

I remember while reading the whole manual once that there is a command for calling DirectX functions directly. I looked for it but I couldn't find it. Does such a command exist? I couldn't find my book on DirectX...Am I wrong about DirectDraw handling polygon's easier?
robo cat
20
Years of Service
User Offline
Joined: 23rd Feb 2004
Location: In a cat litter tray, near you...
Posted: 25th Feb 2005 15:25 Edited at: 25th Feb 2005 15:25
Quote: "how do you create the drawing in the first place? It seems like half of a program to me at the moment"


It lets you write the code for drawing the pictures from primitives and then accessing the file from your code. It keeps your code neat and tidy, plus the images can be offset and scaled.

Will make an editor for the files before the deadline.

Simple... yet fun!
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 26th Feb 2005 00:59
@Ric, it doesn't come off as smooth as I had hoped because of the line command. I could make it perfectly smooth by doing it pixel by pixel the same way the polygon is filled, but it'd make things even slower.

"eureka" - Archimedes
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 26th Feb 2005 01:40
Quote: "I can really appreciate what you guys are doing pixel by pixel...but even if it all works and looks perfect it's still too slow of a method to use in any practical application."


I think this can be worked around by drawing the primitives you are going to use during an intro (or whenever) and then copy the images to sprites. Then you can use the sprites or the images. Sure, there are exceptions, like a desire to change the primitive's color, but in general; I would use these - defenitely!

"Droids don't rip your arms off when they lose." -H. Solo

REALITY II
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 26th Feb 2005 09:53
you could still change the color if you initially make it grey and use the sprite diffuse command.

"eureka" - Archimedes
Chris64
20
Years of Service
User Offline
Joined: 16th Oct 2004
Location: San Diego
Posted: 27th Feb 2005 00:29 Edited at: 27th Feb 2005 00:46
Well here's something that has to be considered a Primative...a triangle function. When I started thinking of how the n-gon was made I wanted to think of how to build something similar but faster. I figure every object could be made with a triangle. Unfortunately it still has slight glitch of offsetting by 1 pixel if the angles are very extreme.



Edit: I did want to mention...though it's not quite perfect yet. It is pretty fast so the potential is there. I was doing a full screen triangle and maintaining right around 100 FPS on a P3600.
Coding Fodder
21
Years of Service
User Offline
Joined: 25th Sep 2003
Location: Somewhere in my cerebralcortex
Posted: 27th Feb 2005 02:07 Edited at: 27th Feb 2005 02:15
Alright here is it with gradient capabilities. I did not want to bog down the n_gon function with a bunch of new parameters so I made a universal function that will add one of two types of gradient to any bitmap in the specified area. Other gradient types can easily be added. here I am just using type 2 which is a radial gradient.



this is back to n_gons 1.3 but I think that you will agree that I have more flexability this way. Now to make universal glow and shadow functions???

[edit] try changing the gradient type to 1 and play with the parameters

Something really catchy that makes people stop and think about the meaning of life and say to themselves "My but thats clever"
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 27th Feb 2005 04:27
Nice radial gradient feature, but I don't see how taking it out of the n-gon function gives it more flexibility - as far as I can see, your gradients are now limited to rectangles, aren't they?

Anyway, judging is imminent ......


Coding Fodder
21
Years of Service
User Offline
Joined: 25th Sep 2003
Location: Somewhere in my cerebralcortex
Posted: 27th Feb 2005 05:10 Edited at: 27th Feb 2005 05:17
the gradients act over a rectangle yes, but it does the same thing the yours did, with the addition of any angle.. The increased flexibility come from the functions ability to apply a gradient to any shape at all, not just my n_gons.

[edit] what time is jugding in server time? so I don't have to check back every 20 min

Something really catchy that makes people stop and think about the meaning of life and say to themselves "My but thats clever"
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 27th Feb 2005 05:25
Right, here goes. 6 entrants to this challenge (other than me), which was great to see!

Blueselah - box

Extension of the existing box command to allow variable outline thickness.

Coding Fodder - n-gons/stars, gradient shader

I think the n-gon/star function is going to be very useful - it does exactly what the challenge called for, and the additional star option is nice. The gradient fill, I now realise, can be used to fill any shape by use of it's transparency effect. Very nice indeed.

Phaelax - teapot, cube, n-gons, shadow, glow, rounded box

Teapot and cube are not exactly useful, but they are fun! N-gons are quite similar to CF's n-gons in what they do, but coded in a different way - good work. Shadow and box would be nice if the aliasing effect of the lines could be resolved. Rounded box should be useful, and would be even better with variable roundedness.

Tom_d - 'Contact'

As with the teapot, it looks cool but it's not going to be hugely useful.

Chris 64 - Bezier Curves, Triangles

Bezier curves work well, and I have a feeling they have a greater significance than I'm able to comprehend right now! The triangles function is another, faster way to create n-gons, although it does have an aliasing problem due to the line command.

Robocat - drawings from text file

Without instruction as to how to create the text file, or even better, an editor for creating the text file, I wasn't able to test the code. In principle, though, having a simple drawing tool that could import drawings into your program is a good idea.

So, the result:



Great work all, roll out the next challenge .......


Coding Fodder
21
Years of Service
User Offline
Joined: 25th Sep 2003
Location: Somewhere in my cerebralcortex
Posted: 27th Feb 2005 05:34
Wow I won one, and phalanx had me scared silly

Well I have plenty of ideas for a challenge but I need to set the deadline before midnight monday sever time -6. Most of them would be too difficult in that amount of time. So I will be thinking of something simpler. One moment please.....

Something really catchy that makes people stop and think about the meaning of life and say to themselves "My but thats clever"
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 27th Feb 2005 06:38
Yeah, Phalanges came close ......


Coding Fodder
21
Years of Service
User Offline
Joined: 25th Sep 2003
Location: Somewhere in my cerebralcortex
Posted: 27th Feb 2005 07:19 Edited at: 27th Feb 2005 07:19
Ok here it is. I prefer seeing how people attack the same problem differently so this one will be pretty specific. It is a simple collisions challenge. The challenge is to make realistic billiards collisions. I made some pool balls and a table so the code can be compared apples to apples.

You may alter the look and size of things if you feel so compelled or even make your own set up.





No I am not making my own billiards game this is just for the challenge of it.

dead line monday midnight -6hrs server time

begin!!

Fodder

Something really catchy that makes people stop and think about the meaning of life and say to themselves "My but thats clever"
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 27th Feb 2005 07:31 Edited at: 27th Feb 2005 07:36
Quote: " and phalanx had
Phalanges came close "


It's PHAELAX!!!

I don't suppose we're allowed to use Newton?

"eureka" - Archimedes
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 27th Feb 2005 07:45 Edited at: 27th Feb 2005 08:05
Quote: "So I will be thinking of something simpler....."




Hmmmmm.....(scratches head).......

Good challenge - I love physics coding. But I have a feeling this is going to be tough within the time limit - no chance of having any longer? Nice no-media graphics, btw!


Coding Fodder
21
Years of Service
User Offline
Joined: 25th Sep 2003
Location: Somewhere in my cerebralcortex
Posted: 27th Feb 2005 09:02
I am leaving tuesday morning for over a week. So if Phalanx agrees to evaluate the challenge then I am sure we could extend. I may be able to access the net but won't have DB.

Something really catchy that makes people stop and think about the meaning of life and say to themselves "My but thats clever"
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 27th Feb 2005 09:06 Edited at: 27th Feb 2005 09:08
Perhaps if we called him Phaelax he might agree! Good rule, that number 8! How about Tuesday night - 3 Days?


Coding Fodder
21
Years of Service
User Offline
Joined: 25th Sep 2003
Location: Somewhere in my cerebralcortex
Posted: 27th Feb 2005 09:13
oops. yah forget about that phalanx guy, Maybe Phaelax could Judge them

Something really catchy that makes people stop and think about the meaning of life and say to themselves "My but thats clever"
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 27th Feb 2005 09:22 Edited at: 27th Feb 2005 09:30
Tuesday night, but no longer. I'm moving to a new apartment this coming week, so I'll be quite busy. I'm still at this home for the week, but I'll probably be offline for a long time after this challenge.

Does this mean I can't enter now?

not really a problem now, think i quit this one. can't seem to factor in the other ball's momentum properly.

"eureka" - Archimedes
CPU
21
Years of Service
User Offline
Joined: 4th Jul 2003
Location: Carlsbad, CA
Posted: 27th Feb 2005 09:51
hmm... still wonder bout newton... but that would make it to easy me thinks...

CPU

[center]K-OS Battlefields
IS
///---///---///---UNDER CONSTRUCTION---\\\---\\\---\\\
[center]
Coding Fodder
21
Years of Service
User Offline
Joined: 25th Sep 2003
Location: Somewhere in my cerebralcortex
Posted: 27th Feb 2005 10:54
CPU yah the idea is to use your own techniques. I don't think we can use plugins that everyone does not have anyway.

Oh and does this mean I can enter?

I probably will contribute some code off the record.

Something really catchy that makes people stop and think about the meaning of life and say to themselves "My but thats clever"
that dude
20
Years of Service
User Offline
Joined: 1st Jan 2004
Location: USA
Posted: 27th Feb 2005 11:45
cewl... i just got a book on physics

http://www.nuclearglory.com/?u=fearik = sweet as hell collision system. easy on that leather thing in your back pocket too.
the left side of my head isn't bigger, the right side is just smaller
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 27th Feb 2005 12:26
Challenge 5

Challenge: Billiard Ball Collision

Challenge setter: Coding Fodder

Judge: Phaelax

Time Limit: 3 Days - until Tuesday night (2/3/05)

________________________________________________________________

The following code provided by Coding Fodder may be used:



No wrappers allowed!


NathanF
20
Years of Service
User Offline
Joined: 24th Mar 2004
Location:
Posted: 27th Feb 2005 17:47
About before, sorry everyone for not answering in a timely manner. My internet was completely screwed, and my comp wasnt doing well either. Had two really nasty viruses which forced me to format. Quite sorry...


"Blame yourself, or God." - Delita
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 27th Feb 2005 23:59 Edited at: 28th Feb 2005 00:00
Happens to us all, Nath. Last time my computer went down I was offline for ages - boot sector virus. Aargh!

<edit> damn billiard balls won't move properly!!!


Coding Fodder
21
Years of Service
User Offline
Joined: 25th Sep 2003
Location: Somewhere in my cerebralcortex
Posted: 28th Feb 2005 00:17
NathF Glad you are back up and running!

Ric- if you are refering to trouble rotating the balls. I am trying to write a global rotation function. Who's Idea was it to use Euler angles natively anyway. The conversion is a pain in the... well just about everywhere.

Something really catchy that makes people stop and think about the meaning of life and say to themselves "My but thats clever"
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 28th Feb 2005 01:35
hmm, where's the quaternion support?

"eureka" - Archimedes
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 28th Feb 2005 03:05 Edited at: 28th Feb 2005 03:09
Haven't even started to worry about the rotation yet! I'm still struggling with the collision. On the plus side, I have got some lovely looking lighting and shadow effects! (Always start with the finishing touches, I do! )




Attachments

Login to view attachments
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 28th Feb 2005 06:54
looks nice ric. The collision is the easy part, its the collision response that's tricky.

Gamasutra has a good article on this subject. So is anyone entering besides Ric?

"eureka" - Archimedes
NathanF
20
Years of Service
User Offline
Joined: 24th Mar 2004
Location:
Posted: 28th Feb 2005 07:00
You can see if they collide just by getting the distance, and then get the angle between them using atanfull(ax-bx,az-bz), which would give you the direction in which the ball should move away.


"Blame yourself, or God." - Delita
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 28th Feb 2005 07:21 Edited at: 28th Feb 2005 07:23
@ Phaelax: Reading it now. This is a tricky challenge - I wouldn't be surprised if there aren't many entries for this one!

@ Nath: I don't think it's that simple - but hey, prove me wrong!


Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 28th Feb 2005 07:47
its not quite that simple. atanfull will get you the incident of impact, but the balls won't reflect in those directions unless its a direct collision. Meaning the velocity vectors collide head-on. If the collision turns out to be oblique(collision point is not along the velocity vectors) you would see why it wouldn't work. I'm sure you'll need the tangent of that line though to get the final vector in which you do need.

"eureka" - Archimedes
Coding Fodder
21
Years of Service
User Offline
Joined: 25th Sep 2003
Location: Somewhere in my cerebralcortex
Posted: 28th Feb 2005 08:14 Edited at: 28th Feb 2005 08:18
yah I guess it is trickier that I first thaught. I am going to forget about the rotation for a bit myself, but I was hoping to add the effect of spin to the physics... Leave it to me to bite off a mile more than I can chew. Or for the folks who use a real system of units 1.6 km

[edit] phaelax can't a vector4 be treated as a quaternion? I never studied them so

Something really catchy that makes people stop and think about the meaning of life and say to themselves "My but thats clever"
KimoSabi
19
Years of Service
User Offline
Joined: 18th Jan 2005
Location:
Posted: 28th Feb 2005 09:33
yes this is a very tough challange yes i dont think i could do it lol i would be surprised if more than a couple people pulled it off

I must say I am quite a »»ç¶´¬¬Géñíú§¬¬´¶««
Chris64
20
Years of Service
User Offline
Joined: 16th Oct 2004
Location: San Diego
Posted: 28th Feb 2005 09:52
I'm in.

This is very tricky. Collision is easy, response is the trick. I'm still trying to figure out the true response...not how to do it...how it actually is (luckily I have a pool table ). If a ball with x-speed hits a ball at y-angle...what happens? Now add spin into the factor...how much spin carries over to the next ball...how much spin does the first ball retain?

Now, make the balls spin without ezrotate.

And then you throw a guy like Ric into the mix...so even if I get the physics right I have to add great graphics. Yea this is going to be a tough one.
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 28th Feb 2005 10:22
Okay - I'm off to bed otherwise I won't get to work tomorrow, but here is how I think it's meant to work. I emphasise the word think, because I still haven't actually managed it in code yet.

As pointed out already, you fisrt need to get the bearing between the two balls in contact. This line is important - we'll call it the collision line. Then you need to resolve the velocities of both balls into components parallel and perpendicular to the collision line.

Now, this next bit should be easy - the initial velocity components parallel to the collision line simply interchange between each ball to give their final velocity components. Perpendicular to the line, the velociy componets stay the same.

Then, use Pythag to get the resultant final velocities from the components, and the get the final angles using atanfull.

I'll post my code tomorrow, working or not.


Coding Fodder
21
Years of Service
User Offline
Joined: 25th Sep 2003
Location: Somewhere in my cerebralcortex
Posted: 28th Feb 2005 11:43 Edited at: 28th Feb 2005 11:57
Ok for those of you who need or want a bit of a headstart. Here is what I came up with. It is far from perfect. there is no rotation or friction involved. I also had to rack the balls a little looser so they would not stick together. But the function that handles the result of two balls colliding works.



Play around with it a bit and see what you can come up with.

[edit] ric that is about the method I used. I found the projection of the colliding balls velocity on the collision line then subtracted the resulting vector from the velocity vector and added it to the other balls velocity vector and vice versa. No need for pythagoras or arctan I think.

[edit 2] Chris64 I like the questions that you are asking of the physics. It sounds like all the right ones. We all know Ric has quite a power of presentation, but this is intended to be judged on physics. I do appreciate attention to detail so maybe ric could just post his beautiful setup for others to use in order even up the playing field.

I am guessing he just likes everything to be as good as he can make it.

Something really catchy that makes people stop and think about the meaning of life and say to themselves "My but thats clever"
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 28th Feb 2005 16:32
it might hold the values of a quaternion, but the math functions don't exist in DB. If they did, noone would need EZ rotate.

"eureka" - Archimedes
Coding Fodder
21
Years of Service
User Offline
Joined: 25th Sep 2003
Location: Somewhere in my cerebralcortex
Posted: 28th Feb 2005 21:04
Yes, I guess you are right. Ok I know that you are right.. I am too cheap to get ez-rotate though, so I am going to bang my head agianst that wall a bit more..

Something really catchy that makes people stop and think about the meaning of life and say to themselves "My but thats clever"
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 1st Mar 2005 00:18
I'd like to enter, but I would need just a bit more time. Busy schedule right now. Any chance of extending the deadline?

"Droids don't rip your arms off when they lose." -H. Solo

REALITY II
Chris64
20
Years of Service
User Offline
Joined: 16th Oct 2004
Location: San Diego
Posted: 1st Mar 2005 00:24 Edited at: 1st Mar 2005 00:30
I'm going to go ahead and help out with the rotation...

If one of you can come up with a Euler to Matrix conversion...all the better...but since most of you won't:

Just y rotate the object to the direction your ball is rolling...then x rotate the object the speed of the ball. It looks perfect except when you hit an object the ball re-orients itself to the new direction (most noticable on the striped balls). I have a whole table of balls doing this and the compromise seems fine.

Now, how about having 16 camera's projected (One off of each ball) and sphere mapping each image to each ball? How cool would that look? You would be able to see all the other balls reflecting off of each ball. I wonder how fast that would run...

Edit: I'm x-rotating the ball the distance the ball has traveled * 5.8 [because: 360/(sphere size(20)*PI)=5.8]
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 1st Mar 2005 01:08
About quaternions, BUILD ROTATION AXIS MATRIX4 let us build a rotation matrix with a vector3 and an angle ( = Quaternion).

Lets say that we have to rotate a vector3 a certain number of degrees around x, y and z axis. We can calculate this rotation using this:


Now, I don't know if this is useful to you, but maybe it could bring out a couple of practical ideas, if you know how to apply this to an object rotation.

Also, working with quaternions for rotations avoids Gimball locks.

This is all about this: "any rotation around x,y,z can be expressed as a single rotation around some other single axis".

So the code above, can give us a single rotation axis (knowing the desired rotation around x,y,z) that would substitute the three rotations around x,y,z. That single axis plus the rotation angle value will conform the quaternion (= vector3 and an associated angle).

I hope to have expressed myself clearly.
You are doing great code here, and I thought this could interest you. Maybe we all get benefit, just in case, one never knows...
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 1st Mar 2005 01:34
Quote: "It looks perfect except when you hit an object the ball re-orients itself to the new direction "


if a collision happens, fix object pivot. then the new rotations will be based on its current orientation.

"eureka" - Archimedes
Chris64
20
Years of Service
User Offline
Joined: 16th Oct 2004
Location: San Diego
Posted: 1st Mar 2005 02:24
Quote: "if a collision happens, fix object pivot. then the new rotations will be based on its current orientation."


I never even knew this command existed...geeze! So there you have it, perfect rotation. Now in order for this to work, since the Y-rot needs to be pointed in the the new travel direction, what you need to do is rotate the opposite direction first, fix the object pivot, then point toward the new direction. I'm just thinking out loud but I'm guessing that'll be required.

I'll try it out in a couple hours and report any probs.

Login to post a reply

Server time is: 2024-11-21 17:24:05
Your offset time is: 2024-11-21 17:24:05