SRL Archive - Other Scripts

3D Game v.2


almost

2009-01-10 13:32:44

Edit: New version up (3D Cube.Scar)
Testing out how to make the box non-transparent.
Also changes the color of the box sides as it rotates (Not fully realistic yet, but it does change color)

I'm going to do just like last time when I made my 3D SCAR game.
I'll post the 3D engine that will run the game and get ideas from you guys.
Last time I heard some cool feedback.
This time there aren't really any limits because the 3D drawing is done RIGHT.

This is a 2D representation of a 4D cube (Hyper cube) with fully working x, y, and z axis roatation, just to show an example.
I am learning how to make the objects it draws into a .sbj (SCAR object file) to make it really fast, allowing me to put texture on objects and things like that (Zytex's idea)
So any ideas, post them here.

Freddy if you see this, I think this new version would be much cooler to have in SCAR, so when I'm done I'll let you have a look at it.

ian.

2009-01-10 15:48:33

asdw doesn't work..

it moves but then goes back..

you make the best things ever.

^^

Quickmarch

2009-01-10 15:50:33

Wow i never knew you could build 3d things in SCAR this is amazing :)

almost

2009-01-10 16:20:45

it moves but then goes back..

That is fine it is supposed to for now.
Really your mouse is supposed to be the primary way to move the object.

ian.

2009-01-10 16:27:20

oh ok :P

Naum

2009-01-11 09:11:51

Wow this is something spectacular. Maybe you'll be the one making FPS's in SCAR :). I find it impressive how you managed to rid of divide by zero errors :).

Good Work - you deserve a cup for all your work.

Gu3st...

2009-01-11 09:12:45

You realeased it! :D :p
yay

EDIT: This verision crashed my scar, but the older one works…

almost

2009-01-11 12:26:43

Good Work - you deserve a cup for all your work.

If there were a cup for non RS scripting I might have one, all the scripts I've released before reflection came out have been using forms and non RS related.
But as far as a scripting cup or something, I don't feel I have earned one yet.
That might change soon though because I have started RS scripting again now that reflection is out.
And I'll be releasing my guild miner soon.

Maybe you'll be the one making FPS's in SCAR

What's that?

EDIT: This verision crashed my scar, but the older one works…

Do you know what happened before it crashed?
It never has for me.

ian.

2009-01-11 13:04:54

FPS's are fps games.. (Frames Per Second)

there just games.. kinda..

almost

2009-01-11 13:27:02

Ohh ok.

New version up.
It makes the box have sides to it.
And I'm working on changing the shade of the sides to show where light is hitting it.
But it turned out a lot harder than I thought.
I have to determine angles of objects in 3D space in reference to the viewer…

Naum

2009-01-11 13:43:50

No. FPS - First Person Shooter.

Wizzup?

2009-01-11 13:49:28

From: 99_
FPS's are fps games.. (Frames Per Second)

there just games.. kinda..


FPS Game = First Person Shooter.
FPC of a Game = Frames Per Seconds. :)

ian.

2009-01-11 13:52:24

:o orly?

haha I feel stupid D:

almost

2009-01-11 14:30:03

First person shooters…
That gives me some ideas.
Maybe I should turn this into one?
It would be much harder than the space ship traveling through space thing though.

Dan Cardin

2009-01-11 14:31:27

wow. I am quite surprized at how well, and smoothly it works. I'm kind of disliking the weird perspective view you have…or maybe its the way the mouse controls the cube. Otherwise its spectacular.

What i'd really like to see, are other shapes like spheres, triangular prisms, cones etc. (Though for the round shapes, you'll need some type of shading for them to actually look right.)

Also, /me wonders where you actually learned the math for this. I've been trying to find a tutorial on this kind of math, but i cannot :(.

EDIT: /me thinks that an fps would be mondo cool, compared to the spaceship thing (no offense)

almost

2009-01-11 16:41:06

Learning the math for this was the hard part, because I also looked for tutorials on this.
I read tons of them and not one said anything I needed to know.

There were basically 2 things I needed to know-
How to turn [x, y, z] into [x, y] to display it on a screen.
That was easy.

How to rotate points in 3D space around a given point in the 3 different directions.
That is what took me a long time.
You have to find the center x, y, and z point of the object.
mz:= (_3DArray[1].z + _3DArray[6].z) / 2;
mx:= _3DArray[1].x + (Width / 2);
my:= _3DArray[1].y + (Height / 2);
For x axis rotation you rotate the y and z coords of all points around the middle y and z coords
RotateP(_3DArray[i].y, _3DArray[i].z, my, mz, xRot);

For y axis rotation you rotate the x and y coords of all points around the middle x and y coords
RotateP(_3DArray[i].x, _3DArray[i].y, mx, my, yRot);

For z axis rotation you rotate the x and z coords of all points around the middle x and z coords
RotateP(_3DArray[i].x, _3DArray[i].z, mx, mz, zRot);

So you could make your character's view turn (look to the left or the right)
by rotating all the points of objects that are being drawn around the point your character is at (using z axis rotation)
[vx, vy, vz] is the point of the viewer.
So using this will turn the direction you are looking-
RotateP(_3DArray[i].x, _3DArray[i].z, vx, vz, TurnDegrees);
Putting in 180 where TurnDegrees is will make the object in front of you behind you (off screen) and what was behind you will now be on screen.

Dan Cardin

2009-01-11 17:30:18

the problem is that i still don't really get it :p. Didst thou eventually find a tutorial that did the 3d to 2dOnScrean type thing, because i look through your script and am lost :p.

almost

2009-01-11 18:16:42

I can understand being lost, because I look at the script and am somewhat lost myself.
But making a point from 3 points into 2 is done with this-
function Turn3DTo2D(x, y, z, vx, vy, vz: integer) : TPoint;
begin
if (z - vz) < 1 then
begin
Result.x:= 0;
Result.y:= 0;
Exit;
end;
Result.x:= (x - vx) * 256 / (z - vz);
Result.y:= (y - vy) * 256 / (z - vz);
end;
Just like before-
Object [x, y, z]
You [vx, vy, vz]
Place on screen [Result.x, Result.y]

Unfortunately I never found any tutorials on how to do this though.
I even asked Dr. Math on the Dr. Math website and they tried to explain some random stuff but pretty much they didn't give me any answer.

lordsaturn

2009-01-11 20:22:02

Maybe you could develop this into a tutorial? Then perhaps you wouldn't be the only one making 3d games in scar.. :)

almost

2009-01-11 20:32:17

Hey I was just considering that, I think I will.
Especially since I couldn't find one out there for myself.
Maybe we can actually have a tutorial in the super advanced tut section?

ian.

2009-01-11 20:41:35

that would be epic :D

DO IT

Gu3st...

2009-01-12 09:07:16

I tried to make a TextureToTPA-converter, but I really got lost..
function TextureToTPA(SourceBmp : Integer): TPointArray;
var
TextureToTPA_Canvas : TCanvas;
TextureToTPA_BMP : Integer;
Ix, Iy, Tx, Ty : Integer;
begin
TextureToTPA_BMP := SourceBitmap;
SafeDrawBitmap(TextureToTPA_BMP, TextureToTPA_Canvas, 0, 0);
GetBitmapSize(TextureToTPA_BMP, Tx, Ty);
for Ix := 0 to Tx do
for Iy := 0 to Ty do
Result[] := TextureToTPA_Canvas.Pixels[Tx, Ty];
end;
I wanted it to output the colors that was in the bmp, so that you could paint the colors on a box.

1st index in the TPA (Result[0]) is the color that is at coords "0, 0", the 2nd is the color that is at coord "0, 1", and so on…

almost

2009-01-12 14:59:24

This could work, but is there a difference between this and just using SafeDrawBitmap?

Gu3st...

2009-01-14 10:18:52

From: almost
This could work, but is there a difference between this and just using SafeDrawBitmap?

I do not think you can draw a bitmap that is rotated/scewed without making an bitmap-rotater/scew function.. :p

almost

2009-01-14 18:34:09

True.
Well you can rotate but not skew.
But that procedure didn't rotate or skew anything.

Gu3st...

2009-01-15 08:06:11

Thats where I got lost :P

Dan Cardin

2009-01-15 12:53:46

it wouldnt be the same as just making the image thinner and then rotating to the correct rotation? Probably not, but that could always work until you can figure out something a bit more mathmatical.

almost

2009-01-15 18:56:59

That just gave me a crazy idea.
I could make bitmaps 3D.
They already have an x and a y, just throw in a z.

//an array of pixels, their location, and the color of the pixel
T3DBmpPixel = record
x, y, z, color: integer;
end;

//the array of pixels that go to a bitmap and the rotation of the bitmap
T3DBmp = record
Pixels: array of T3DBmpPixel;
xRot, yRot, zRot: integer;
end;

The z attribute will be set to the z of the "wall" that it will be put on.
When the Bmp is drawn the pixels will be rotated by their x, y, and z rot.'s that are set by the "wall" too, and the pixels will match up perfect with the drawn object (if the Bitmap and the object were the same size)
The only down side is that would be amazingly slow.
I might make a plugin and see how that goes.

The bitmap will actually still only have 2 dimensions though, because it started out with only 2.
It is like a piece of paper in the 3D world.
But it will be able to be drawn at different angles and distances from the viewer.

ian.

2009-01-15 21:16:03

o.o wow.

your so smart.

D:

make an SAT ^^

almost

2009-01-15 21:25:43

Hah :)
I just made a script for this and it's working.
I'll post here when it is finished.
The only problem is if you change the pixels in a bitmap (especially making the bitmap bigger) there will be dead space between the pixels where you see the background.
I have a way to solve this but it will take a long time to script it.

ian.

2009-01-15 21:29:02

I think, you should help me with scripting some :D

<3

Dan Cardin

2009-01-15 21:51:19

actually now that i think of it, im surprized that that does indeed work with your script. You are using a perspective view. I only expected something as simple as that to work with an orthographic projection. Then it would at least keep the same shape. With yours wont it hang off the edges, since the engles and whatnot arent always the same, or are you doing it differently?

almost

2009-01-15 21:58:15

Are you talking about my box drawers or the 3D Bitmap thing?
And really I'm not sure what you mean at all.
What edges?

I think, you should help me with scripting some

I will make an SAT for this type of thing soon.

ian.

2009-01-15 22:09:44

:D

your pretty much amazing ^^

Dan Cardin

2009-01-15 22:39:20

From: almost
Are you talking about my box drawers or the 3D Bitmap thing?
And really I'm not sure what you mean at all.
What edges?


I will make an SAT for this type of thing soon.


the 3d bitmap. Since you're drawing the box using perspective projection, it wont keep the accurate angles (at x rotation, its not going to be a parallelogram like an orthographic projection would) so it wouldnt draw the bitmap on right…..I do hope im making sense.

almost

2009-01-15 23:28:35

I'm not so sure I'm getting it still.
It rotates each individual pixel in the bitmap around the central point of the bitmap.
It keeps it's shape as it rotates, just really deforms the bitmap because of all the pixels separating from each other and nothing is set to fill in the empty spaces as of right now.

It looks like the box drawer I posted but if you made it draw one side to the box instead of all 6. (and it is a picture)

Dan Cardin

2009-01-16 08:50:56

It keeps it's shape as it rotates

Thats my point. Your box wont have that shape because of the way its drawn afaik. But if you dont get it, then i might be wrong and there could be no problem :).

Gu3st...

2009-01-16 08:57:32

From: almost
That just gave me a crazy idea.
I could make bitmaps 3D.
They already have an x and a y, just throw in a z.
ScarScript:By Drunkenoldma [LEFT]//an array of pixels, their location, and the color of the pixel T3DBmpPixel = record x, y, z, color: integer; end; //the array of pixels that go to a bitmap and the rotation of the bitmap T3DBmp = record Pixels: array of T3DBmpPixel; xRot, yRot, zRot: integer; end; [/LEFT]

The z attribute will be set to the z of the "wall" that it will be put on.
When the Bmp is drawn the pixels will be rotated by their x, y, and z rot.'s that are set by the "wall" too, and the pixels will match up perfect with the drawn object (if the Bitmap and the object were the same size)
The only down side is that would be amazingly slow.
I might make a plugin and see how that goes.

The bitmap will actually still only have 2 dimensions though, because it started out with only 2.
It is like a piece of paper in the 3D world.
But it will be able to be drawn at different angles and distances from the viewer.

That is exactly what i ment… >.<

botmaster

2009-01-16 09:29:58

Pure genious. This is absolutely brilliant!!! A 3D engine made from a simple script engine…. wow. Just demostrates how flexible and powerful SCAR really is. Definetly worthy of further modification and experimentation!!! This is some good stuff!

Oh and also: This could have practical applications, such as better solvers for randoms (i.e. you get the RS object file, draw it in memory, then compare it with the image in RS). Would take a lot of resources though.. hmm..

Gu3st...

2009-01-22 07:54:05

I just started on a 3D model editor :)

almost

2009-01-22 16:56:46

Zytex did you ever see my 3D model editor from a long time ago?
It was very basic and sucked really, but you might get ideas from it.

Gu3st...

2009-01-22 17:51:56

Hey, I remember that one! Thanks :)
*searches*