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 / Tutorials + Code Snippets For All

Author
Message
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 13th Dec 2010 23:49 Edited at: 15th Sep 2012 01:09
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 14th Dec 2010 01:42 Edited at: 15th Sep 2012 01:09
REMOVED!


------

DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 14th Dec 2010 04:43 Edited at: 15th Sep 2012 01:10
REMOVED!
-------

Neco
15
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 14th Dec 2010 06:09 Edited at: 14th Dec 2010 06:10
This is a great thread. Thanks for posting this stuff. I know I will definitely find this info useful down the road.

DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 14th Dec 2010 20:45 Edited at: 14th Dec 2010 21:10
@Neco - np. I plan on posting a lot more tutorials. There are a bunch of things I didn't know when I stared using DBP so I am sharing them with the community.

Hopefully these tutorials help.

DigitalFury
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 14th Dec 2010 21:02 Edited at: 15th Sep 2012 01:10
REMOVED!
_____

DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 14th Dec 2010 23:07 Edited at: 15th Sep 2012 01:10
REMOVED!!!!!

Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 15th Dec 2010 04:34 Edited at: 15th Dec 2010 04:35
Wow, this is an incredible resource, I'm surprised I didn't notice it yesterday. I've seen some of your snippets around the forum but it's great to have them all in one place. I can't wait to delve deeper into some of these ideas when I get the time; some of the examples seem very interesting. Thanks for taking the time to post all of this, and keep up the good work . (Thread bookmarked)


Guns, cinematics, stealth, items and more!
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 15th Dec 2010 04:53 Edited at: 15th Dec 2010 04:56
Sixty Squares -

The concepts aren't to hard to follow. I believe I explained everything in great detail. Shouldn't take much to dive deeper into the code. If you have any questions let me know.

There is still much to come. I didn't know if anyone understood exactly everything that was going on in my snippets or what the applications were. I figured I would cover that first and then several other new ideas I had.

Glad u found the tutorials/code snippets useful.

DigitalFury
BillR
21
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 15th Dec 2010 05:09 Edited at: 15th Dec 2010 05:13
Excellent!
Thanks for the Folder and File scanning example using DBP Media,
I have wanted something like this for my current project.
It works great!

Here is your code with my testing code added for others to see

You need to download his:
Here is an example using DBP Media:
from 3 posts above this.
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 15th Dec 2010 05:42
@BillR - Thanks for the testing code. I am writing something very similar in my next post. It combines resource scanning, loading, and assigning an index.

I am working on the example right now. I am writing a DBP version and a dark data version so it should take a while.

DigitalFury
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 15th Dec 2010 23:21 Edited at: 15th Sep 2012 01:11
REMOVED4589054

DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 16th Dec 2010 02:33 Edited at: 15th Sep 2012 01:11
REMOVED34250924

DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 16th Dec 2010 03:24 Edited at: 17th Dec 2010 21:57
Information/Possible F.A.Q: Part 1


Here is some information to address possible F.A.Q's:

Dynamic Resources:
- Keeps an Index for each resource.
- "Next Resource": Checks if a the Deleted array has any indexes it could use. If it does it will remove on and return it. If not it will increments the Index and returns it.
- Garbage Collector: Using coroutines the Garbage Collector will check an index every step of the main loop. It will add the empty resource indexes to the Deleted arrays.

In the "Dynamic Resources" code snippet. "Wouldn't it be easier to use Free Resource functions?"

Read my Performance tutorials. The tutorial explains how Free resource functions are slow and also don't work with coroutines. The functions would reduce performance. As the object count increases the more objects the "For Loop" has to check reducing performance.

In the "Dynamically Loaded Resources" tutorial. "Why not just use arrays?"

I don't like using to many arrays. Arrays take up memory and to many arrays could reduce performance/memory. Also, when searching it is a lot slower then have a c++ based find function.

In the "Performance: Running the Main Loop at the Same Rate" tutorial.

"Wouldn't setting the sync rate to 0 cause the processor to run full throttle based on what KISTech said here?"

Yes, it would. I can't find an alternative to it. You can assume that the video game would be the only thing running. Not many people run their video games at the same time they do something else. I would have to ask KISTech his opinion on my performance code. You know what I will ask him right now...

@KISTech - Hey, KISTech! Could you check my performance code? Is their an alternative to running sync rate to 0 that doesn't slowly inc to the set LPS? Anything else I could add to it? Thanks

The part of the game that typically takes the longest is the display loop portion. Manipulating bitmaps and images, 2D drawing, getting those bitmaps and pasting them over the main screen. (something you might do to put together a HUD) All of those things take up a lot of processing time.

It's cool to be able to show that a game can run 1,000 FPS, but it's just not necessary, and is a waste of processing power. Movies shown in the theater run at 24 FPS. (at least the ones still shown on film do..) Many games look fine at 30 FPS, most people seem to aim for 60 FPS. Which is fine, as long as performance doesn't suffer for the extra effort to draw everything that fast. (60 FPS = Drawing the screen every 16.667 milliseconds)

So what I'm doing here isn't the Display Loop running at 1/4 the speed of the Game Loop. The Display Loop is running at the desired speed, and the Game Loop is free to run faster if it can. That's where you get the performance improvement, adjusting the speed of the Game Loop so the Display Loop can maintain the desired speed. You just have to make sure the Game Loop always updates as fast as the Display Loop, never slower.

In the end this seems to make movement smoother, allows networking in multiplayer games more processing time, catches keyboard input more reliably, and if done properly it adjusts dynamically to allow the Display Loop to remain at a consistent speed.

Those interested in KISTech's responce:
Quote: "This really showed it's power when I modified my server app to run at 5 FPS, but let the Game Loop run flat out so it could handle a lot more networking traffic. The server only displays the number of currently logged in players, the game date/time, and status updates. It's all plain text, there's no 3D involved at all, so 5 FPS is a perfectly acceptable framerate for that. The Game Loop, when no one is on the server runs at just under 20,000 loops per second. That drops 100 or so when 2-3 people log in.

This is how I plan to use DBPro to run a game server that can handle 500 players simultaneously, maybe more. We'll have to see how it goes when we get closer to that number."


There happy, person who asked this question? "Yes"

Haha. lol Arguing with myself is a sign on insanity.

Anyways, if you have any questions let me know. I would be happy to explain anything in greater detail. If anyone has an additions to the snippets then post them. I try to make my code snippets run as fast as possible and to function very well. If there is anything to make them better then I am interested.

Edit: I might eventually take requests after finishing the Dynamic Resources example.

Thanks,

DigitalFury
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 17th Dec 2010 03:32 Edited at: 15th Sep 2012 01:12
REMOVED90

___________

DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 17th Dec 2010 05:17 Edited at: 15th Sep 2012 01:12
REMOVED


____________

DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 18th Dec 2010 00:18 Edited at: 31st Dec 2010 03:12
Game Template



What you will need:
Dark Data
Matrix1Util

I combined every code snippet, tutorial, and example into one game template. I will add on to the game template as I post more tutorials.

What is included:

Setup:
- Sets up each lib.
- Declares the Hi-Resolution Timer variables
- Loads the name script
- Scans the media folder if it hasn't been scanned yet
- Loads the Animation

File:
ScanFolder(Dir$, DatabaseName$): Scans for files/folders and adds them to the folders and files array. The files are also added to a database and the names are added to the Lua Array.

Dynamic Resources:
GarbageCollection: Automatically runs checking for empty resource indexes and adds them to the deleted arrays.
Delete Resource Functions: Adds the index to the deleted resource array and deletes that resource.
Next Resource Functions: If there is a deleted resource then it will use that index. If not it will inc the global index and return it.

Input:
Using Multi-Threading the input function searches for keys pressed. UpdateInput will update the mouse and keyboard down/released events. The input system is event based making it easy to organize the key event functions.

Multi-Threading:
I would advise against using these functions unless you understand how unstable Multi-Threading is and how to use multi-threading safely.
CreateThread: Creates a new thread from a function FunctionName$ and returns the FunctionThread with the UDT Thread.
CloseThread: Closes the given UDT Thread.

Animation:
Load_Animation: Will load the extracted animation databases and anim files.
Extract_Animation: Will extract all the animation from the character shop character and all the zombies of the Zombie Apocalypse pack.

I included all the anim files I extracted from the Zombie Apocalypse pack and the Character Shop character.

What I am working on now:
I am working on performance ideas/tutorials right now so the template will change after I am done.

You can expect there will be a lot of changes to the game template.

Edit: This is older version of the game template. A new version will be uploaded soon.

Check back often. Any comments, questions, or bugs let me know.

DigitalFury
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 18th Dec 2010 02:13
I haven't looked through all the snippets, but this type of loop caught my attention for a couple of reasons.

Quote: "
Function LoadObject(Name$)
For Index = 0 To Array Count(Files())
If GetExtentionType(GetFileExtension$(Files(Index).Path$)) = "Object"
If Files(Index).Name$ =Name$
Load Object Files(Index).Path$,NextObject()
EndIf
EndIf
Next Index
EndFunction ObjectIndex

"


Those being,

* For/Next end expression is evaluated each iteration of the loop, rather than cached prior to the loop executing.

so,
For Index = 0 To Array Count(Files())

is better expressed as,

size=Array Count(Files())
For Index = 0 To size

So the end condition evaluates once, not every iteration.


* Another other issue is the routine is string thrashing for no real benefit. Each iteration there's a number of cumulative string op's ending with a string comparison. Dbpro's string engine is rather slow, even if it wasn't, this is still far from an ideal inner loop if you're after speed in brute force search.

So rather than do the compares at string level, it'd make more sense to convert the String ID, into an numerical ID. Removing the majority of the string handling and replacing it with integer comparisons.


You can see the same type of problem here, string length is being resolved each iteration and the loop has cumulative string addition, which isn't really necessary.

Quote: "
Function GetFileName$(FilePath$)
For Index = 1 To Len(FilePath$)
If Mid$(FilePath$, Index) = "." Then Exit
FileName$ = FileName$ + Mid$(FilePath$, Index)
Next Index
EndFunction FileName$
"






Depending upon the Mid$() implementation in DBpro, which i'm pretty sure has brute force string length comparison in it also. To counter this, you could add an early out clause and check if the character 3rd from the end is if stop chr. If so, avoid falling through a few loops.

Anyway, you get the idea.

DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 18th Dec 2010 03:17 Edited at: 18th Dec 2010 03:22
@Kevin Picone -

Quote: "is better expressed as,

size=Array Count(Files())
For Index = 0 To size"


I didn't know that. Thanks.

Quote: "Function GetFileName$(FilePath$)
size=Len(FilePath$)
For Index = size To 1 step -1
If Mid$(FilePath$, Index) = "."
FilePath$=left$(FilePath$,Index-1)
exit
endif
Next Index
EndFunction FilePath$"


Hmmm must have missed adding an exit. lol Well, when I am cranking out lots of code I make more mistakes. Thanks.

Using mid$ and adding up the chars is slower then left. I think they might be my older functions. I re-wrote them at one point to figure the start index and end index and just use mid$ once.

I know that there are a lot of string functions in matrix1utils. I believe they are c++ commands therefore faster. I'll look into speeding up a few of my parsing functions.

Thanks for the corrections. I should probably look over everything.

Thanks Again,

DigitalFury
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 18th Dec 2010 19:29 Edited at: 15th Sep 2012 01:13
@Kevin Picone - Here are the corrections to the two functions:
REMOVED
I will post the rest of the corrections to the Game Template 2.0 today.

DigitalFury

Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 19th Dec 2010 00:51
Yeah better, but if all you want is the extension or to remove the extension from the filename$, then starting at the end and working backwards seems like the most likely way to get the least number of iterations for a brute force scan.

If the filename$ contains "BuildingTexture1.png" say, and we move left to right when scanning it, then we're calling the MID$() function and performing a comparison 16 times.

But if we move from right to left, then we're only calling mid$() and doing the string compare 4 times. I realize most people will think this is splitting hairs (given the assumption todays machines are so fast, they aren't), but some string operations can eat through time like nothing.


Quote: "I know that there are a lot of string functions in matrix1utils. I believe they are c++ commands therefore faster. I'll look into speeding up a few of my parsing functions."


Never looked at it, but I suspect it's more about the methods being used, than purely the language when put under pressure. Sure building the routines at lower level will gain some performance, but at the end of the day, dbpro seems to use Null terminated strings, which are flawed by design.

DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 19th Dec 2010 01:58 Edited at: 19th Dec 2010 03:08
@Kevin Picone -

Quote: "If the filename$ contains "BuildingTexture1.png" say, and we move left to right when scanning it, then we're calling the MID$() function and performing a comparison 16 times. "


Yeah, ur right. I don't normally concern myself with a 16 vs a 4 interations. I'll optimise everything. I just needed to get the template finished first. Every little bit helps. With so many wasted interations per milli-second it adds up.

Thanks for your help. I will make the nessesary changes you suggested in the future releases of the game template.

DigitalFury
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 19th Dec 2010 03:04 Edited at: 15th Sep 2012 01:14
REMOVED
___________________

Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 19th Dec 2010 05:45
Quote: "I don't normally concern myself with a 16 vs a 4 interations."


I understand, but that's really not the point i'm making. We're not optimizing the underlying functions here to improve the odd usage of the function (Which isn't worth worrying about), but rather as these functions are foundation that other higher level functions. As such, this can magnify the overhead dramatically.


ie,



So running higher level functions such as this, which calls the get extension at it's core. The cost of searching is magnified the more files in the list and the longer the file names are. So if this loop runs through 100 files (15 character filenames) before finding a match, then that's an awful lot of Mid$() and string comparing overhead.


Note: The native string functions in DBpro, such as mid$(), internally search the string every time for it's length (since they're null terminated strings) before doing anything. They need to do this, in order to validate the user inputs. So the longer the string, the slower that functions gets.

DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 19th Dec 2010 06:11 Edited at: 19th Dec 2010 06:22
Quote: "I understand, but that's really not the point i'm making. We're not optimizing the underlying functions here to improve the odd usage of the function (Which isn't worth worrying about), but rather as these functions are foundation that other higher level functions. As such, this can magnify the overhead dramatically."


Meaning functions called many times should be optimized?

Quote: "As such, this can magnify the overhead dramatically"


Which I learned to be very true when I made a game very ineffciently. I was wondering what was wrong with DBP instead of looking at my code.

Thanks Again,

DigitalFury
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 19th Dec 2010 13:23
Quote: "Meaning functions called many times should be optimized?"


Yep.. Clearly this depends upon the situation though, as what gain is possible through merely rearranging the logic of the lower level functions is somewhat debatable. Often you'll get a far better result by changing the method at the higher level.

For example, you could do away with lots of string overhead from those free media scanning routines above, but changing from a string ID's to a numerical IDs. So the brute force search can screen for potential matches on two or more levels. So if the ID don't at least match, there's no string string thrashing.

The ID could be made by simply adding some or all of the characters together. Then rather than store the file type as a string we use the numerical ID.

This sorta thing.



DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 26th Dec 2010 03:24 Edited at: 26th Dec 2010 03:44
@Kevin Picone - Took your advise and here are the new functions:



I didn't exactly get how your method works. It seems like ThisID is an integer. Still a bit rusty since I have taken my c++ classes.

Quote: "
"


These should be a lot faster.

DigitalFury
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 26th Dec 2010 03:38 Edited at: 31st Dec 2010 03:10
Game Template



I was a bit busy with Christmas and the chaos of Christmas shopping. I did manage to at least make some changes to the Game Template. I hoped to finish the Performance section of the template, but I am having problems with the Wait timer.

Updates:
- Event System: Added/Removed Function Tags: "Setup_", "Coroutine_", "Thread_"
- ShuttingDown flag for multi-threading
- Setup Function: Initial Setup.
- Updated Performance

Future Updates:
- Performance: "Nice Wait" to give processor time back to the CPU. (Right now it is running at about 50% of the CPU. I can reduce it to like 2%ish)
- Enhanced Performance in functions
- Other Classes
- Possible tutorial showing how to use the template

Haven't heard much about the tutorials/template/code snippets. Any comments, questions, or bugs let me know.

Check back often!

DigitalFury
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 28th Dec 2010 22:56 Edited at: 15th Sep 2012 01:13
REMOVED!

______________

The Slayer
Forum Vice President
14
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 28th Dec 2010 23:20
These are some really good tutorials, DigitalFury! Nice work indeed! This thread should be stickyed, so that people can find it more easily.

SLAYER RULES! YEAH, MAN!!
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 28th Dec 2010 23:35
@The Slayer - Thanks. I will post more tutorials so it is bound to be stickied eventually. lol

The tutorials I posted so far are for the game template which should be used for the underlying code of any game. I might eventually give some tutorials on how to make a full video game. Haven't decided yet.

DigitalFury
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 29th Dec 2010 02:49 Edited at: 15th Sep 2012 01:14
REMOVED
___________

thenerd
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 29th Dec 2010 02:53 Edited at: 29th Dec 2010 02:55
You've written some awesome tutorials here, every time I come back you seem to have something new I can learn from! Keep up the good work, and don't get discouraged by the small amount of responses...
One suggestion, you should try writing a bigger tutorial on a specific topic. I have a request, could you write a tutorial on particle systems?

DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 29th Dec 2010 02:55 Edited at: 29th Dec 2010 03:08
@thenerd - Thanks. "you should try writing a bigger tutorial" I thought mine were already. lol A game template to maximize game performance, resource system, input system, timer system, event system, coroutines, multi-threading, file system, and an animation lib. lolz Well I guess I might try something bigger later. Need to get the basics..or I should say the hard stuff out of the way first.

Quote: "One suggestion, you should try writing a bigger tutorial on a specific topic, maybe particle systems or something like that."


I won't be writing any tutorials on big concepts because I am writing an editor to do all that for you. A lot of my big concepts are going into my first commercial project. Right now it is all hush hush. Will release details sometime soon though.

Quote: "I have a request, could you write a tutorial on particle systems?"


Evolved wrote one of those here. I don't think I need to write another one. lol Might be cool to look into it though.

I am learning like everyone else. Everything I have posted is completely new code. I learn about the concept, write the code, and release a tutorial.

DigitalFury
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 29th Dec 2010 04:58 Edited at: 15th Sep 2012 01:15
43-592wjlgfr

DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 29th Dec 2010 21:30 Edited at: 29th Jan 2011 01:15
The Timers with events class has been removed.
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 30th Dec 2010 01:25 Edited at: 29th Jan 2011 01:17
Performance 3.0 class has been removed. The new class has be optimized to handle thread performance!
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 30th Dec 2010 22:13 Edited at: 30th Dec 2010 22:29
Mini-Tutorials


Here is how this works:
Post your own Mini-Tutorials! For every mini-tutorial posted I will post a mini-tutorial. I might even take requests if a mini-tutorial is posted! Anything to help out the community!

Post some tutorials and hopefully we can make this a great resource for the community!

In order to get things started here is my first mini-tutorial:
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Shoot Object Tutorial


Requirements:
- Dark Physics
- Trig.

Example:


Shoot Object Function:


How it works:

Use these formulas:


Post your mini-tutorials and I will post some more mini-tutorials!

DigitalFury
thenerd
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 31st Dec 2010 03:25 Edited at: 31st Dec 2010 03:29
---------------------------------------- Mini Tutorial: Resource Management ----------------------------------------


In this mini-tutorial, I'm going to show you what I have found is a great way to keep track of resources in your code. It can be very confusing and inefficient to manually assign and keep track of hundreds of object numbers, and other media. Using this system, you can name your objects using variables, and cleanly assign resources.

Requirements:
- ResourceTracker.dba must be included into the project as a module for this system to work.

How it works:
The module keeps arrays for all the types of resources available, and allocates resources based on that list. This way, it becomes easy to modify your code without having to change around object and other resources' numbers.

To use this module, simply call RES_init() at the start of your program. Then, you can get a resource by calling the function RES_grab(Type). The type parameter is the type of resource you want. The types are as follows:


To make sure you can access the value returned, assign it to a global variable like so:


You can then use it in any situation, without worrying about remembering a pesky number.

Example:


Module:


The module is also attached to this post.

----------------------------------------

Note: This code is based on a module that I found somewhere on the forums, but I can't remember where... thanks to the original author!

Attachments

Login to view attachments
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 31st Dec 2010 04:22 Edited at: 31st Dec 2010 04:27
@thenerd - I already posted a similar tutorial on resource management. Nicee example though. Need to dig though it to understand it. The tutorial is below as promised.

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Mini Tutorial: Eyes Follow Cursor


What you need:
- The image attached to this post

How it works:
ATanFull will return an angle by using distances. The distance from the eye to the mouse is used to get an angle. From that angle you can get the center position of the circle or eye.

Using this formula:


The distance is the distance from the center point of the circle. In this case being the distance from (Eye1_X, Eye1_Y) or (Eye2_X, Eye2_Y). This explains the circle or orbit of the center point movement.

Example:


Post your mini-tutorials and I will post some more mini-tutorials!

If you have any comments, questions, or bugs let me know.

DigitalFury

Attachments

Login to view attachments
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 2nd Jan 2011 22:47 Edited at: 4th Jan 2011 19:59
@Everyone: I know the community is more resourceful then this! I want to make a resource of this thread. Any tutorials, code snippets, or ideas for the community would be greatly appreciated!

Edit: For every code snippet or tutorial posted I will post an equally awesome code snippet/tutorial.

Thanks,

DigitalFury
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 4th Jan 2011 23:59 Edited at: 5th Jan 2011 00:02
Tutorial Requests


@Everyone - Well, the mini-tutorial idea I guess is a bust.

I will take tutorial requests now!

Here are a few rules though:
- Has to be mini-tutorial
- Has to be do-able (nothing like a particle system, full video game, or anything to big)
- Something that doesn't require a lot of math
- I can't for-fill everyone's request. This is just to get some ideas of tutorials to write.
- I would like to challenge the community to try to take on one of the requests posted.

Post your requests or for-fill a request!

DigitalFury
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 5th Jan 2011 00:08 Edited at: 5th Jan 2011 19:57
How To Submit a Tutorial Requests


Someone will post a request and any user on the forum can respond to the request!

User01's Post:

----------------------------------------------------------------------------------------------------------------------------------------------------------------


Request:
Could you explain how to get one object to orbit another?

----------------------------------------------------------------------------------------------------------------------------------------------------------------


User02's Post:

Response:
@User01: Here is how to orbit one object around another:

Mini-Tutorial: Orbit Object


How it works:

Equation:


When orbitting on a certain axis the only thing to remember is that one axis will have Sin() and the other Cos().

The distance is the distance from the X, Y, Z which is the center point it is orbiting around.

Example:


Enjoy!

DigitalFury
Dar13
15
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 5th Jan 2011 03:16
These are great tutorials about literally everything! Should definitely be a sticky. Would have helped me out tons when I was a beginner.

Keep up the good work!(Perhaps email a mod about stickying this topic?)


DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 5th Jan 2011 03:45
@Dar13 - Could email the mod when the thread is almost dead. More to come so check back often!

Working on a new Secret Project right now that ties everything together. It would be worth checking out once I make a new thread.

Good luck with your projects and hopefully my tutorials helped.

DigitalFury
Dar13
15
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 5th Jan 2011 04:23
Mini Tutorial: 3D GUI Controls


What it is: This tutorial details how to make a GUI slider control using 3D boxes.

How it works: This works by using the distance from the player to a specified object to activate the control, and then using the pick object and mouse position commands to move the slider along a rail until it reaches a limit.

The GDK function(has some project specific code in it)


This is a older,DBPro version of the DarkGDK function above, but it still does the same things->


Hope this helps someone out, sorry for the lack of descriptive comments.


BillR
21
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 5th Jan 2011 06:33 Edited at: 5th Jan 2011 07:03
@DigitalFury - your idea is not a bust, it is a great idea!
We are just slower than you are, I am very busy but I will come up with a small tutorial soon.

PS. your orbiting example is cool, but from the cameras view, the x and z orbit seem wrong, the z key orbits the x axis from the cameras view, and the z orbits the x axis, am I wrong?
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 5th Jan 2011 19:58
@BillR - Figured everyone is still partyin after new years...or recovering.

You were right about the orbit object example. Fixed it.

Thanks,

DigitialFury
BillR
21
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 8th Jan 2011 12:10 Edited at: 8th Jan 2011 12:11
Mini-Tutorial: Dark Physics - Bullet Time


What is Needed:
DarkPhysics

This shows way to have Bullet Time camera motions during a DarkPhysics simulation

Usually DarkPhysics exists in its own world, managing all the objects
within its Physics world getting updated just before the DBPro sync command.

Use the arrow keys to move the camera, pausing the DarkPhysics simulation
While the camera move around

Kinda Cool!

How it Works:
By managing WHEN we call Phy Update, we can have more influence when
DarkPhysics updates its physics world

If a key is pressed, pause Physx updates, and move camera with arrow keys by
Setting the phyflag=0 variable to not update the Physics simulation
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 8th Jan 2011 22:09 Edited at: 14th Jan 2011 05:33
Pulse Gun: Part 1


Click to create a pulse to push the objects around the camera.

How it works:
This code snippet is fairly basic. To create a pulse I go though each object and if it is within a certain range then it will shoot the object.

Example:


Future Updates:
- Distance should return a negative distance. (For behind the camera pulsing backwards instead of forwards)
- Directional or Ranged Weapon (Only pulse within certain area in front of camera)
- Take Y axis into account
- The For/Loop in the main loop can be optimized using co-routines

Enjoy!

DigitalFury

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-04-25 15:03:11
Your offset time is: 2024-04-25 15:03:11