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 / Game Template (Open Source)

Author
Message
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 22nd Jul 2011 07:29 Edited at: 15th Sep 2012 01:06


What is standard? What are those base classes that you constantly reuse and how can you make them flexible enough to use in everyday projects? The Game Template was a project I worked on to answer this very question. It is a template to start any basic/3D game. I want to mold it into a game editor and fps creator.

This was a long project and I didn't have enough time to complete it. I'm just one person so I finally decided to make Game Template open source and ask the community for there help!

Every game has a standard base code that is used over and over. This template is suppose to be that base code so we don't have to constantly re-write it.

More in-depth into the concepts of the Game Template and place to post non-code related improvements: Game Template: Community Opinion to help improve the project

New Stuff I'm Working on:
- UV Mapping with Editor to control object materials
- Animation with parser for loading FPS Creator files
- Full 2D and 3D Editor for real-time editing
- Terrain editor with Fractals, Thermal Erosion, Perlin Noise, and Diamond Star for generating terrain.
- Built in and real-time editing of evolves shader pack
- AI behavior lib
- Bone Structure for rag dolls and animation translation

My Blog: http://digitalfuryblog.tumblr.com/

Ball Game Example: Included in latest build of the Game Template! (Download for ball game at bottom of this post!)







Editor


The game editor is a older project I have been working on. I'm combining the Game Template project with this project to export source code with the Game Template code to optimize the game.

Here is a quick preview of my Editor for the Game Template:



Tutorials: Everything I was working on upto the Game Template. It started as tutorials and ended up being the Game Template.

Command Help File: View List using Google Docs.

Before you download!:
- You must include the Game Template logo in your game + text made by DigitalFury. (Logo provided at top of page)
- No redistribution of the zip file
- IMPORTANT NOTE: All downloads is more then 1 year old and the newer classes will be posted and new download will be added when I have the time.
- Understand that it is copyrighted so don't claim it as your project :p

Copyrights for your information: The Game Template is copyrighted by MyFreeCopyright:
- Game Template: http://myfreecopyright.com/registered_mcn/CRNP2-GNV3Y-J9N9R
- Game Template Update 1.0: http://myfreecopyright.com/registered_mcn/CPW6Y-1XCDB-KSBQJ



Download: REMOVED!

I was going to sell it but I haven't had the time to keep it going. I hope I could at least get a donation or two for my many of hrs of work. A dollar would make me happy :p



If I get a donation I'll make sure I'll put some extra effort into contributing to the Game Template. It will most likely be in the form of more tutorials, revisions, or code. I have little free-time yet I can put a lot of effort and get a lot done with what time I have. lol

Bug Submission:
- Provide the buggy snippet
- What happened?
- Any fix ideas if not open it up to the community to figure out.

Bug Fixes:


Class Submissions:
- Post a submission request
- Post your class
- The Team will decide if it should be added to the Game Template

Community Feedback:
I would like to get the community plugged in an improving the template. What I need the community opinion for is to improve the Game Template for everyone's benefit.

Game Template Classes:
- Dynamic Resources
- Load Resource
- Load Lua
- Name Item
- File
- Timers
- Performance
- Animation
- Multi-Threading

I'm still working on sorting the functions around so it is easier to manage.

With all the classes I have I'm looking for some new ideas of classes to add to the template. The Game Template is lacking in quite a lot to be enough to develop a complete game.

How to contribute to the project:

I've been working on this project for quite sometime. I decided to make it open source so the community could help in the development of the Game Template. There is a lot of work in progress code that needs work. I don't know everything and most of the works in progress were developed though research.

- Post a bug report/bug fix
- Post an idea, comment, or question
- Post an addition or even a new class. lol
- Share your conceptual knowledge
- Repeat contributors or Join the Team

I've been trying to get together a team or just a few people devoted to the idea. I really some help to pick apart the Game Template classes, make improvements, and to really put there expertise into new classes.

Thanks,

DigitalFury

Attachments

Login to view attachments
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 22nd Jul 2011 07:31 Edited at: 28th Jul 2011 12:02
Documentation

Click Download at bottom of post to download the documentation!


Question: Should I keep documentation posted here or just the downloads and links to google docs? I need your opinion. Does it affect the load time to much? Thanks














Game Template: Standard Game Library of classes. Makes it easy to focus on your game and less on your code.

Attachments

Login to view attachments
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 22nd Jul 2011 07:32 Edited at: 28th Jul 2011 12:02
Introduction

Tutorials + Examples


Here are some tutorials and examples showing a few features of the Game Template. I will post new examples here whenever I finish them.

Dynamically Loaded Resources: Part 1
Beginner - Intermediate Tutorial


What you will need: Optional
Dark Data

Tutorial:

Mission:
My Multi-Level File and Folder Finder can be used to find resources. I can use my Dynamic Resources for finding indexes. All the files can be stored in a database and loaded with a few commands.
- Naming resources.
- Grouping resources.
- Naming resources and finding indexes based on a name
- Possible automatic loading of resources

First I have to find all the files and store them in a database.

This can be done two ways:
- Using Dark Data to store the data for easy and quick access
- Save/Load Array Commands. Edit: I included those functions in Part 2.

Dark Data Example:


DBP Example:


Next is to load files using my Dynamic Resources lib. Until next time.

Dynamically Loaded Resources: Part 2

Intermediate Tutorial


What you will need:
Dark Data (Optional)
Dynamic Resources

Tutorial:
In the first part I showed an example of how to scan for media. This example I am storing the data in a database or file and load the resource based on the resources name.

DBP Example:


DBP Load Resource Functions:
Place in the Dynamic Resources lib.


Dark Data Example:


Dark Data Load Resource Functions:
I have found errors in the code. Some of the errors required a complete rewrite of the framework. I added all the updates and class rewrites into the Game Template.

How it works:
Using the scan function I wrote it will scan for the files and write all of them to an array. The files that DBP doesn't recognize are not added to the array. The file array is written to a database or an array file. The load resource functions will search for a resource based on the name given. If it is found it will load it and return the resource index. If it isn't found then it will report an error.

Dynamically Loaded Resources: Part 3

Naming Resources: Part 1

Intermediate Tutorial


What you will need:
Dark Data
Dynamic Resources

You will need Dark Data!

Tutorial:
I noticed that DBP's "GetIndex" function would be very slow so it would be un-needed. A good alternative would be to use lua. I will give an example using lua in the next tutorial.

Dark Data has a Find function making it easier and faster then searching manually though an array.

In order to make things easier for me I am posting the full source code here. Just download the example from the previous post or create your own media folder to test this example.

Here is the example:


Dynamic Resources Function Additions:
Copy and paste Dynamic Resources and this snippet.


How it works:
I created a separate database containing the names of the objects that are loaded. Every time a Load resource function is called it will add that name to the database. To quickly get the index of a resource just use the "GetIndex" function providing a name.

Side Note: I don't search for redundant names yet. Every time the example runs it will add piano2 to the name database. I will add a redundancy check in future examples.

Dynamically Loaded Resources: Part 3

Naming Resources: Part 2

Beginner - Intermediate Tutorial


What you will need:
Dark Data
Dynamic Resources

Tutorial:
I said I would give a tutorial on using Lua as an alternative to a Dark Data database. Well, here it is:

I think Lua might be faster then using Dark Data to store names. Using Lua the names are temporarily stored.

"Why not just use an array for naming resources?"
You would have to search though each index of the array. This would reduce the performance. Just read what I wrote about performance.

Lua Script:


How it works:
It will create an array called Items. The name is used instead of an index in the arrays parentheses. AddNamedItem will add a new item to the Items array. GetIndex will return that item. Very simple yet effective script!

An addition to the Load resource functions:


How it works:
When the load resource function is called it will create a named item using lua. The name just like the name database is
and the index is the index of the newly created resource.

Lua Naming Functions:


How it works:
- Lua_LoadNameScript: Loads the script
- Lua_GetIndex: calls lua the function GetIndex and returns the index.
- Lua_NameItem: Calls the lua function AddNamedItem and passes the name as a parameter.

Dynamically Loaded Resources: Part 3

Naming Groups

Beginner - Intermediate Tutorial


What you will need:
Dark Data
Dynamic Resources
Matrix1Util
Download from previous post!

Tutorial:

Using these functions if you are using the database method:
- GetIndex
- Database_NameGroup:


By assigning a group with a name it makes it easy to keep track of. No more variables to remember the indexes.

Just call Database_NameGroup and enter your GroupIndex and Name$ for a group.

In Matrix1Util it is #19 - "List and group objects". Learn how to use groups and assign objects to groups. Use Database_NameGroup to name the group and GetIndex to get the index of group Name$.

If you are using the Lua method then:

Just enter in the group index and group name in:


Use:
to get the group index.

That's it for the "Dynamic Resources" tutorials for now. I plan on giving a tutorial on something more practical. It most likely will be a 3D demo.

Coroutines

Beginner - Tutorial


Google Doc: Click Here To View

Example:


Example 2:


Multi-Threading

Intermediate - Advanced Tutorial


Google Docs: Click Here To View

Example:


Performance: Loops Per Second

Beginner Tutorial


I was doing some research in performance and I needed to determine a way to measure performance. FPS isn't a good way to measure for performance. What really matters is how many commands are being executed and the time it takes to execute those commands.

The best way to determine performance is loops per second. An accurate timer is needed.

Here is an accurate timer example:


Here is an example to calculate loops per second:


With that you should be able to approx. performance in loops per second.

Performance: Running the Main Loop at the Same Rate

Beginner Tutorial


I did some experimentation with the sync command and that sync doesn't always run at a constant loops per second.

Here is an example illustrating that fact:


Hold the space key to return time back to the system for 1 second. Notice how the loops per second decreases and than slowly increases.

This slowly trys to correct, but stays around 26-27 for a while.

What does this mean?
It is not running at a constant rate!! If this was on a server then there would be lagging or a delay! Constant speed between clients is essential when you play multi-player games.

This example corrects the flaws with Sync:


No matter how fast your computer is it will run a constant 30 Loops per Second.

I did notice that KISTech wrote a tutorial on "Decouple the Display Loop for Better Performance.". I need to look into how it works.

What I have figured out so far from KISTech's tutorial: The display loop should need to be run in the main loop. The display loop can be run 1/4 the amount of times the main loop is running.

Performance: Part 2

Control the LPS of the Display Loop and Main Loop

Beginner Tutorial


Performance Example:


How it works:
The display loop runs at a constant LPS. Instead of running the main loop as fast as possible taking up CPU time I am just going to run it 4x the the GlobalLPS.

This will calculate the Loops Per Second for both loops:


The display loop is capped at GlobalLPS using this line:


The main loop is capped at GlobalLPS x 4 using this line:


Next Tutorial:
Performance: When the main loop and the display loop isn't running then return the CPU time back to the CPU.

Timers

Count-Downs

Beginner Tutorial


Here is the example:


How it works:

Variables handled by the functions

GetFreq() - For better accuracy then the DBP commands.
OldTime# - Stores PerfTimer
PerfTimer - Gets the time since the computer was turned on. This is the raw time.
between the time now and the start time you get the current time.
StartTime# - The start time of the count down.

Time


Will reset the timer by setting old time to PerfTimer(). This means the difference will be 0. PerfTimer() - PerfTimer() = 0


By getting the difference it will calculate the raw time.


To get the time in seconds divide by the Freq.


Functions


Setup_CountDown(Start#):
- Start#: Sets the Start Time of the count down

Update_CountDown(Units$):
- This function you feed in the units: ("Hours", "Minutes", "Seconds", "MiliSeconds")
- It will subtract the time from the start time and return the current time left.

Reset_CountDown()
- It will reset the timer

Timers: Part 2

Multiple Count-Down Timers

Beginner Tutorial


Here is the example:


How it works:

I have an array of count-down timer. I use the same variables as the previous tutorial "StartTime#" + "OldTime#".

Count-Down Type:
StartTime# - The start time of the count down.
OldTime# - Stores perftimer() (The raw time since the computer was turned on)
Units$ - The units of the timer. ("Hours", "Minutes", "Seconds", "MiliSeconds")
CurrentTime# - Is the current time set by the Update_CountDown function.

Functions


Create_CountDown:
- Sets the StartTime
- Sets the OldTime# to pertimer()
- Sets the Units of the timer

Update_CountDown:
- Checks the units
- Sets current time to the time minus the start time
- If the current time equal 0 then reset the timer

The rest of the functions are explained in the previous tutorial. They don't need to be called because everything is handled automatically!

Timers: Part 3

Multiple Count-Down Timers with Events

Beginner Tutorial


Example:


How it works:

- Added event to the type CountDown. This will store the function pointer.

- If the function pointer is valid then call the function.

Set_Event(Index, Event As Event):
- Sets the Event of the CountDown at Index

Shoot Object Tutorial


Requirements:
- Dark Physics
- Trig.

Example:


Shoot Object Function:


How it works:

Use these formulas:


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:


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:


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:


Game Template: Standard Game Library of classes. Makes it easy to focus on your game and less on your code.
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 22nd Jul 2011 07:46 Edited at: 2nd Aug 2011 20:59
Classes

Download for classes is at the bottom of this post


Dynamic Resources: (Updated)


Indexes are hard to keep track of and you sometimes end up with a lot of empty indexes that you could recycle. The template assigns indexes, recycles indexes, and searches for indexes by name with ease. When the template starts a File Database is created for looking up resources and where they are located. You can load a resource just with a name and the index is returned. You can also lookup loaded resources to find that index.

Highlights:
- Store Resource names you loaded in Lua Arrays
- Plug into the File class to search for resources
- Load a Resource by name
- Manage Resources indexes and recycle unused ones
- The alternative to loading by name is by full path which can be hard when you have to manage many resources by Index
- Name your own resource indexes with NameResource and GetResource

Dynamic Resources:


Load Resource


Load By Database (Dark Data): Requires Name Item.dba


Load By File: Requires Name Item.dba and File.dba


Load By Lua: Requires Name Item.dba


Game Template: Standard Game Library of classes. Makes it easy to focus on your game and less on your code.

Attachments

Login to view attachments
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 22nd Jul 2011 07:53 Edited at: 28th Jul 2011 12:02
Classes


Load Lua


Unity:


Barnski:


Name Item

Unity:


Barnski:


Lua Script:


File


The ScanFolder function will scan all the folders and sub folders and add all the files/folders to the array. The array can be saved via Dark Data database or .dat File.

Highlights:
- Stores every file in a database for easy access
- Load the database rather then searching.

Load Via Database:


Load Via File:


Timers


You have two different types of timers: Normal game timers and event timers. Game timers just keep the games time. You can reset the timer at any time using ResetTimer(). An event timer is a countdown timer that calls a function when it reaches 0. It can run once or reset when it reaches 0.

Highlights:
- Create Game Timers
- Create Count-Down Timers
- Create Count-Down Timers with Events
- Reset any timer using ResetTimer(Index)
- Get Milli-Seconds, Seconds, Minutes, Hours from a Timer

Timers.dba Source:


Performance


Performance is also another major feature of the Game Template. The Performance code will run the loops at a constant rate of Loops Per Second. Threads are also run just like loops. You can set the rate of any performance loop or thread giving you control of how fast or slow you want everything to update. Whenever a loop isn't running it will use "Nice Wait" to return the unused time back to the processor. This means the CPU usage will be very small. As you use more CPU power the CPU usage will go up. This technique insures that the CPU usage will be minimal.

Highlights:
- Create a performance loop using "Loop_" function tag
- Run at an specific rate. (Loops Per Second)
- The Loops Per Second rate will reflect as the Frames Per Second rate because sync is being called the Loops Per Second Rate. Ex. A Loops Per Second Rate of 30 will yield 30 Frames Per Second.
- CPU usage is minimal because wasted time is calculated and returned back to the processor.

Performance.dba:


Main.dba: Set Shutting down to 1 when u want to end the game. Set GamePaused to 1 when you want to pause the game.


Game Template: Standard Game Library of classes. Makes it easy to focus on your game and less on your code.
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 22nd Jul 2011 08:00 Edited at: 28th Jul 2011 12:03
Classes


Animation


I cataloged all the animation for: Character Shop, The Apocalyptic Pack, and Model Pack 10. It will automatically extract and write an animation list for every animation. You can also load an animation using the LoadAnimation() function. Any animations you load can be looked up the index using GetAnimation() function. You can provide the Objects Name and the Animations name to get the index. I formatted the File Name of the .anim file to be easy to parse. This makes searching and loading easier.

Highlights:
- Automatically searches for objects and if they exist then extract the animation files and an animation list.
- The File Class can handle the files and be loaded by name.

I created a quick and easy way of extracting all the animation (.anim) files from the Apocalypse Pack.

Functions:

Create_AnimationDatabase(AnimationName$, Dir$)
This function will scan the folder Dir$ and write all .anim file names to the database assigning an index to each.
- AnimationName$ = The animation file name.
- Dir$ = The directory to create the new files

Load_AnimationDatabase(AnimationName$, Dir$, DFS, KFS)
This function will load the database created under the database indexes of DFS and KFS. Refer to the DFS index for "GetAnimationIndex" later. The function will also load every .anim file it find in directory Dir$.
- AnimationName$ = The animation file name.
- Dir$ = The directory to create the new files
- DFS/KFS = Database Indexes (Dark Data)

GetAnimationIndex(DFS, Name$)
By giving a name you get the index of the anim file loaded.
- DFS = Database Index
- Name$ - Animation Name

GoTo Statements:

Extract_Animation:
Since the anim is the same for ever mod zombie and slow zombie I use a for loop to reduce the amount of code. The base animation is extracted first and then the extra animations for that object are extracted.

Extract_BaseAnimation:
The anim from 1 - 91 are the same so this goto statement is called instead of having a lot of redundant code.



Character Shop:


Download the Folders from this post.
Download the .Anim files from MegaUpload here.

Multi-Threading

I finally figured out how to get multi-threading to work! You need Matrix1Utils for this to work.

Important Notice: Multi-Threading is not Thread safe! You must protect EACH and EVERY variable you access. If you access a variable from the main thread and the new thread u get a collision (read/write at the same time) and the application crashes. You can't have to threads accessing the same variable! Just wait for my new multi-threading lib with mutexes to be released!


Full Example:


Load Kernel32:


Thread Type:


CreateThread:
This function will create a new thread from function: FunctionName$.
- FunctionName$ = The function's name to for the new thread.


CloseThread:
- FunctionThread: The Thread containing all the information about the thread created using CreateThread.


Game Template: Standard Game Library of classes. Makes it easy to focus on your game and less on your code.
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 22nd Jul 2011 10:34 Edited at: 28th Jul 2011 12:03
Classes (WIP)


Advanced Animation: Object Bone Structure Data


I combined Advanced Animations with a bone structure I'm working on.

What I can use this data for:
- Extracting Animation from one object and playing it on another no matter what bone structure by matching similar bones.
- Ragdolls
- Transitions between ragdolls and animation

Screen Shots







Final Bone Structure:

I've completed generating the default bone structure data. The final result is posted. Now I just need to work on processing the data and adapting it with new bone data structures.



Default Bone Structure:


GUI


I've been working on creating a basic GUI class with intractable controls. The GUI is drag and drop and can be docked onto any other controls. The class I wrote ages ago. I am re-writing it using GUI Studio images which I have to still get permission to distribute.

New File Formats: Packages


I had the idea of making a new file format called a package. Media can be added to the package and encrypted using a key. Only the developer has access of the media and knows how to properly access the contents. It is a basic class I was working on. It is still in it's early stages but I will release something when I have something useful.

I will post more as I get time. If I could have some help from the TGC Community I could get more done.

Thanks,

DigitalFury

Game Template: Standard Game Library of classes. Makes it easy to focus on your game and less on your code.
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 22nd Jul 2011 13:32
To be honest, I'm a little... Well, overwhelmed. I've lost my words, this just blew my cap off at 1337 km/h.

I don't know what else to say You've obviously put a lot of work into this, I do hope you find some help for this. The forum has some good guys.

TheComet

DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 26th Jul 2011 10:10 Edited at: 28th Jul 2011 10:14
Problems to Solve: Asking Community for help!


Problem:
I have a polygon (X, Y, Z) that I flatten out into a triangle (X, Y). I need to convert the points of the polygon (X, Y, Z) to points of the triangle (X, Y, Z).

I have all the code for everything else. The only part I need is the conversion. It is just like the pulling off a triangle from a 3d paper geosphere and tracing it on a piece of paper.



Any help would be appreciated. If the math is all right and the rest of the algorithm I came up with works then I'll post a demo showing what it does.

I have like a billion dead ends in my classes. It is just to late to post them all lol. The more help I get the more I'll post :p

Thanks,

DigitalFury

Game Template: Standard Game Library of classes. Makes it easy to focus on your game and less on your code.

Attachments

Login to view attachments
crazy kitty
14
Years of Service
User Offline
Joined: 1st Nov 2009
Location: MARS , eos
Posted: 26th Jul 2011 22:05
This should be in the "program announcements" or "Work in Progress" Boards.

But,

overall it seems that you have put a lot of work into this and a lot of people will find this usefull.

Keep up the good work with your team!

I inhabit a nice forum
[href]uh what ?[/href]
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 26th Jul 2011 23:06
As to your problem... Get your thickest maths book, place it on the floor with 4 lit candles at each corner of the book, and say "fuzzy... fuzzy. FUZZY. FUZZY!! FUUUZZYYYYY!!!", each one louder and more desperate than the last. If done correctly, someone will appear and your question will be answered!

TheComet

Indicium
15
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 27th Jul 2011 01:11
Quote: " say "fuzzy... fuzzy. FUZZY. FUZZY!! FUUUZZYYYYY!!!""


I've done this on one or two occasions.

GIDustin
15
Years of Service
User Offline
Joined: 30th May 2008
Location:
Posted: 27th Jul 2011 03:22
I have tried downloading your "Classes.zip" and "Documentation.zip" twice now and it has been corrupt both times. Any chance you could re-upload those ones? The "Ball Game.zip" seems to be ok.

DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 27th Jul 2011 08:33 Edited at: 28th Jul 2011 12:03
@TheComet - Ok. I tried that and I got nothing but a floating portal. I walked though the portal and GLaDOS tried to kill me. Tried to clog the portal with a bunch of companion cubes but that still hasn't solved my problem.

JK! Lol Na it would be good to get some help though. Some of these problems I would spend hours looking on google for. Although google has a billion results none of them will help me. Therefore I ask. lol

@GIDustin - Will do. Sorry about that.

Game Template: Standard Game Library of classes. Makes it easy to focus on your game and less on your code.
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 27th Jul 2011 09:27
Well the calculation isn't really that hard, I've done something like that before. But it only works if the camera is rotated 0,0,0. If you start rotating the camera, you may as well resign yourself to GLaDOS... Or try that ritual again and make sure the candles are symetrical

PX,PY,PZ <-- Coordinates of triangle corners in 3D space
CX,CY,CZ <-- Coordinates of camera in 3D space
RX,RY <-- screen resolution
DX,DY <-- coordinates of triangle corners in 2D space (what we're looking for)

OK, so we know that if PX,PY,PZ = -320,-240,400 and RX,RY = 640,480 and CX,CY,CZ = 0,0,0 then DX,DY = 0,0

We also know that if PX,PY,PZ = 320,240,400 and RX,RY = 640,480 and CX,CY,CZ = 0,0,0 then DX,DY = 640,480

So it's "simply" a proportional calculation, this considers RX,RY = 640,480

DX = (PX-CX)*(PZ-CZ)/400
DY = (PY-CY)*(PZ-CZ)/400

So what happens if you have a resolution that's 800x600? We have to multiply everything by a factor. So again, a simple proportional calculation:

factorx = 800/640
factory = 600/480

So plug that into the calculation:

DX = (PX-CX)*(PZ-CZ)/400 * RX/640
DY = (PY-CY)*(PZ-CZ)/400 * RY/480

If you shorten it a bit, you end up with:

DX = (PX-CX)*(PZ-CZ)*RX/307200
DY = (PY-CY)*(PZ-CZ)*RY/192000

But as mentioned before, if you start rotating that camera, you will need to go into 3D transformations, and I'm not all too good at that. There is only one person here that is able to do it, so get a thicker math book

TheComet

DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 27th Jul 2011 21:26 Edited at: 28th Jul 2011 10:14
@TheComet - Should have explain it a bit more. The camera and screen doesn't factor into this equation. That is a texture not the screen. I know the equations should be only like 2 lines long. lol

I have all the code for everything else. The only part I need is the conversion. It is just like the pulling off a triangle from a 3d paper geosphere and tracing it on a piece of paper.

Appreciate the help! Ooo and btw I tried symmetrical candles that and I still have the same problem. A portal shows up but this time glados is dead then was re-awoken and now has a taste for blood. I'd like to give the plot away to portal 2 but I haven't finished the game myself. Instead I tried to fill the portal with watever I could find to cover it up so when I'm ready for glados to try to kill me again I'll clear away what is blocking the portal.

Thanks,

DigitalFury

Game Template: Standard Game Library of classes. Makes it easy to focus on your game and less on your code.
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 2nd Aug 2011 21:15 Edited at: 3rd Aug 2011 12:49
Examples


Dynamic Resources


Dynamic Resources (Updated): Posted under classes


Using Next Resource Function: It is easier to just use an OOP approach to getting a new index.


Deleting a resource: When you delete a resource you can recycle the index.


Garbage Collection: When an object is deleted the garbage collector will find the index and recycle it when a new resource is created.


I will completely explain how each feature works as I get the time

Next Tutorial is performance!

I will update daily with tutorials. I'm starting out basic until I get more advanced.

Thanks,

DigitalFury

Game Template: Standard Game Library of classes. Makes it easy to focus on your game and less on your code.
GIDustin
15
Years of Service
User Offline
Joined: 30th May 2008
Location:
Posted: 3rd Aug 2011 03:01
DigitalFury,

Your Classes.zip file works now, but Documentation.zip is still corrupt.

One thing I was wondering, and perhaps you could add it to your examples, is how to make a separate thread that points to a function, such as "LoadMedia()", and once that function is complete, it closes itself. That way you can create a separate thread to "Load all your game assets" while you display your main menu, instead of having a separate loading screen later.
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 3rd Aug 2011 07:39
@GIDustin - Threads can't load media. Even if you load media into another thread it is not on the main thread therefore it can't be handled by dbp. It would crash if you try to load an object on another thread.

I know what your asking for and the Game Template already does that. lol It scans the media folder, automatically loads it, adds names for lookup, and you can get the index by name. lol I'll provide an example.

Game Template: Standard Game Library of classes. Makes it easy to focus on your game and less on your code.
GIDustin
15
Years of Service
User Offline
Joined: 30th May 2008
Location:
Posted: 3rd Aug 2011 07:45
DigitalFury,

What I am trying to avoid is the "Loading Screen" that you get to display while all your media loads. I want it to load in the background while you are looking at the main menu and therefore not really making full use of each CPU cycle. If threads cannot do it, then I think co-routines are going to be the best option.

Anywho, I didn't mean to threadjack. You have alot of potentially useful code up there. Great work.
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 3rd Aug 2011 07:52
@GIDustin - It does that to. lol Don't worry about posting. I'll answer any questions. Hell I might even code an example.

What the Game Template does:
- Scan for media
- Store in Database (After stored no need to rescan)
- Anything you need to load just use the load by name functions

I might make an example. There are multiple ways to have code run while resources are loading.

DigitalFury

Game Template: Standard Game Library of classes. Makes it easy to focus on your game and less on your code.
Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 3rd Aug 2011 11:17


MATRIX MATH AND BARYCENTRIC COORDINATES!

The basic idea is that, because of [insert magic here], a point P that lies on plane A1, A2, A3, satisfies the equation:

(a+b+c)P=a*A1+b*A2+c*A3

usually this equation is simplified by saying a+b+c=1, and thus:

P=a*A1+b*A2+(1-a-b)*A3

So, the idea is that you take a point on one triangle, find that point's barycentric coordinates for that triangle, and then use those coordinates to find a corresponding point on a different triangle. In other words, you have two triangles, A and B, each consisting of three points (the vertices of the triangles: A1, A2, A3, B1, B2, B3), and each point consisting of three values (the x, y, and z coordinates of each vertex: a1x, a1y, a1z, a2x, a2y, ... b3z). P1 is the point on triangle A, and P2 is on triangle B. With the above definitions, we can realize the equations:

P1=a*A1+b*A2+(1-a-b)*A3
P2=a*B1+b*B2+(1-a-b)*B3
the only unknowns are a, b, and either P1 or P2 (the goal is that given one point we can find the other).

The above two vector equations are equivalent to these six equations:

p1x=a*a1x+b*a2x+(1-a-b)*a3x
p1y=a*a1y+b*a2y+(1-a-b)*a3y
p1z=a*a1z+b*a2z+(1-a-b)*a3z
p2x=a*b1x+b*b2x+(1-a-b)*b3x
p2y=a*b1y+b*b2y+(1-a-b)*b3y
p2z=a*b1z+b*b2z+(1-a-b)*b3z

That's more concisely defined by the following matrix equations:


So now lets make that even more concise by saying BAR (short for barycentric) is the column matrix (a, b, 1-a-b), MAT_A is the rightmost square matrix in the first equation, and MAT_B is the rightmost square matrix in the second equation. Now we have:

P1=BAR*MAT_A
P2=BAR*MAT_B

We can solve for bar in each of those matrix equations to get us:

P1*MAT_A^(-1)=BAR=P2*MAT_B^(-1)


therefore:
P1*MAT_B=P2*MAT_A

and so, given P1, we can find P2, and vice versa:

P1=P2*MAT_A*MAT_B^(-1)
P2=P1*MAT_B*MAT_A^(-1)



So, in summation:


So... it becomes a problem of multiplying matrices and inverting matrices. Uhh, you can use the built-in dbpro commands for that, or you can bite the bullet and calculate it out by hand (eww).

I believe IanM's matrixutils has a command to set a matrix4's values, so our equations can easily change to:


and solved in the same manner. (that matrix equation multiplies out to eight equations, two of which are "1=1*1", so everything remains valid)

in practice, one triangle would be a polygon of an object, and the other triangle would lie on the XY plane, meaning its Z value is zero.


Why does blue text appear every time you are near?
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 3rd Aug 2011 12:07
@Neuro Fuzzy - Haha. Its been said u know everything. Let me get out my white board and I'll try to completely understand it. I've looked into that concept but it didn't seem to completely explain it. I appreciate it and hopefully it will work with my algorithms. lol

Thanks again,

DigitalFury

Game Template: Standard Game Library of classes. Makes it easy to focus on your game and less on your code.
Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 3rd Aug 2011 12:36
that [insert magic here] part is the confusing step... I'm actually not really sure how to go about deriving it...

But the results have always worked for me, so I figure I'll get to it when I take a linear algebra class xD


Why does blue text appear every time you are near?
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 3rd Aug 2011 13:03
I see you finally got the ritual right!

TheComet

DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 7th Aug 2011 05:31 Edited at: 7th Aug 2011 06:19
Resource Sorter


I was working on sorting a ton of mixed media I had. I made an addition to the file class and hopefully someone will find it useful.

How it works: It sorts resources into folders (objects, images, music, sounds, effect) by scanning for media then based on the files type it will move it into the correct folder.

Place the media in the unsorted folder and it will be moved in the correct folder under the sorted folder.

Enjoy,

DigitalFury

File Attached

Game Template: Standard Game Library of classes. Makes it easy to focus on your game and less on your code.

Attachments

Login to view attachments
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 9th Aug 2011 08:02 Edited at: 16th Aug 2011 09:24
Example

Name Resource and get/set index by name


Code Snippet:


Classes Need


Dynamic Resources


Dynamic Resources:


Name Lua


Load Lua


Unity:


Barnski:


Name Item

Unity:


Barnski:


Lua Script:


Thanks,

DigitalFury

Game Template: Standard Game Library of classes. Makes it easy to focus on your game and less on your code.

Attachments

Login to view attachments
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 9th Aug 2011 08:41 Edited at: 9th Aug 2011 12:16
Downloads

I figured I'd just add a download section for any downloads I post. That way they are all in one place so it is easy to find.


Game Template

Game Template: It is copyrighted, please give me credit with logo and by DigitalFury in your game, and donate by clicking on link on first post if you can.
Game Template Update 1.0 Patch 2.0

Documentation:
http://www.box.net/shared/zkgcooc0q8
https://forumfiles.thegamecreators.com/download/2231056

Classes:
https://forumfiles.thegamecreators.com/download/2231065

Ball Game:
https://forumfiles.thegamecreators.com/download/2231053

Resource Sorter: It sorts resources into folders (objects, images, music, sounds, effect) by scanning for media then based on the files type it will move it into the correct folder. Place the media in the unsorted folder and it will be moved in the correct folder under the sorted folder.
https://forumfiles.thegamecreators.com/download/2239532

Tutorials


ATanFull Example:
http://www.box.net/shared/5dugm7zp3fo57v0sy3og

Constant FPS:
http://www.box.net/shared/8vl8ix3czdcz3pgfomhy

Constant LPS:
http://www.box.net/shared/xocbqmp17lytge8hv1eu

Coroutine:
http://www.box.net/shared/rdpqclanjkr5fzptfomk

CountDown Timers:
http://www.box.net/shared/xj9meizg011z3vn9tjuo

Dynamically Loaded Resources Part 1:
http://www.box.net/shared/xary7x10bk4734yu6m5v

Tutorial section has more downloads. Working on turning code snippets into examples to download. The examples section will be posted here soon as well.

Enjoy,

DigitalFury

Game Template: Standard Game Library of classes. Makes it easy to focus on your game and less on your code.

Login to post a reply

Server time is: 2024-05-03 04:14:15
Your offset time is: 2024-05-03 04:14:15