Math Is Fun Forum
  Discussion about math, puzzles, games and fun.   Useful symbols: √ ∞ ≠ ≤ ≥ ≈ ⇒ ∈ Δ θ ∴ ∑ ∫ π -

Login

Username

Password

Not registered yet?

#1 2006-08-21 21:12:51

luca-deltodesco
Super Member
Award: Wink Alive

Offline

C++ software rendering

ive started looking into scan line rendering for proper 3d graphics, and i made a navigatable room in AS3 in flash 9 with a little table with near plane cliping, but it ran so slowly, i thought id try it in C++

anyone that doesnt know, software rendering general refers to the rendering of 3d graphics, by a piece of software, rather than the graphics card, being hardware rendering, so that all the rendering has to be done manually, without the help of openGL or directX or any other graphics api

i havnt added near plane clipping yet, but i have made a little sample with a model of a cube spinning around, and duplicated 8 times into a little 3x3 grid of differently rotating cubes. So far you can input in the source code, model data via creating a new model, and inputting its triangle data and texture data for the triangles, and then you can move the models around and rotate them, duplicate them, and it has a camera,  in terms of rendering, obviously texturing, which is perspective correct, with a zbuffer and back face culling of triangles

it does have a virtual camera in it, but theres no interface for moving or rotating it yet:p

http://delta-luca.110mb.com/AS3.zip

you need windows to run the program, counting the triangles, there are 108 triangles in total, 2 per each face of a cube, 12 triangles a cube, 9 cubes

----------------edit

ive now added per pixel lighting with a single light placed below and towards camera a bit


Uploaded Images
View Image: newgroundcubes.jpg      

Last edited by luca-deltodesco (2006-08-21 21:54:58)


The Beginning Of All Things To End.
The End Of All Things To Come.
 

#2 2006-08-21 22:56:38

MathsIsFun
Administrator

Offline

Re: C++ software rendering

Sorry for the question from the side, but I was hoping flash 9 would be faster than 8 (I have Sudoku, Chess and several other projects that are stalled because flash is so slow).

What you say implies it aint so good, what have you discovered so far?

And how is it programming in AS3 ... is it well written?

(AS3.exe didn't work for me - just bombed out)


"The physicists defer only to mathematicians, and the mathematicians defer only to God ..."  - Leon M. Lederman
 

#3 2006-08-21 23:36:52

luca-deltodesco
Super Member
Award: Wink Alive

Offline

Re: C++ software rendering

oh no, flash 9 is MUCH faster than 8, trust me on that, its just not fast enough for what i do with it :p

AS3 isnt really any different from AS2, although it was rebuilt form ground up, its just certain things you have to get used to

movieclip properties for a first

_x is not just x, _y = y, _ymouse = mouseY, _xmouse = mouseX _xscale = scaleX _yscale = scaleY

one of the biggest changes is in clip handlers like onEnterFrame and stuff, they are now events.

import flash.events.*;
function main(event:Event):void
{
}
addEventListener(Event.ENTER_FRAME,main);

but you get used it to it pretty easily.

one of the most annoying changes, is in the Key class, well, there isnt one for a start, with the ui package you have Keyboard, but the functionallity of Key.isDown has been removed

however in AS2, onKeyDown and onKeyUp events, werent very good, handling them, if you held down one key, onKeyDown would be triggered with it, then you keep that held down, then press another onKeyDown is triggered, but onKeyUp was only triggered for the second key, they are working perfectly now, and so you can create youre own isDown functions without any loss of functionality

for example, i made my own little class for isDown and isUp functionality

package delta.ui
{
  import flash.events.KeyboardEvent;
  public class Key
  {
     private var keys:Array;
     private function downhandle(obj:KeyboardEvent):void
     {
         keys[obj.keyCode] = true;
     }
     private function uphandle(obj:KeyboardEvent):void
     {
         keys[obj.keyCode] = false;
     }
     public function isDown(keyCode:uint, ...keyCodes):Boolean
     {
         if(keyCodes.length==0)
           return keys[keyCode];
         else
         {
             if(!keys[keyCode]) return false;
             for(var i:uint = 0; i<keyCodes.length; ++i)
             {
                 if(!keys[keyCodes[i]]) return false;
             }
             return true;
         }
     }
     public function isUp(keyCode:uint, ...keyCodes):Boolean
     {
         if(keyCodes.length==0)
           return !keys[keyCode];
         else
         {
             if(keys[keyCode]) return false;
             for(var i:uint = 0; i<keyCodes.length; ++i)
             {
                 if(keys[keyCodes[i]]) return false;
             }
             return true;
         }
     }
     public function Key(stage:Object):void
     {//its imperative that 'stage' is passed to the constructor for the class to work
         keys = new Array(222);
         stage.addEventListener(KeyboardEvent.KEY_DOWN,downhandle,false,0,true);
         stage.addEventListener(KeyboardEvent.KEY_UP,uphandle,false,0,true);
     }
  }
}

and its just the same to use, if not better in a way

import delta.ui.Key;
import flash.ui.Keyboard;
var keyhand:Key = new Key(stage);

if(keyhand.isDown(Keyboard.UP,Keyboard.DOWN,Keyboard.LEFT,Keyboard.RIGHT)) {}

and that will only trigger, if UP,DOWN,LEFT and RIGHT are all pressed down.



there are certain things like the new int datatype which is very nice, however, if you start using AS3 anytime soon, DO NOT use the uint data type, (unsigned int) for some strange reason, it is incredibly slow, dont use it unless you absolutely have to

in terms of speed, if you run a simple iteration loop from 0 to 100000000, just like var i∫; for(i=0;i<100000000;i+=1) {}

you get execution times of around int  = 512ms, Number = 2136ms, and uint = 3245ms

uint is for some reason icnredibly slow, and there are many other speed things ive tried
for some reason, i+=1 and i-=1 is alot faster than doing ++i, i++ or --i, i--;

you can see most of them here : http://newgrounds.com/bbs/topic.php?id=535196
alot of these do not apply to AS2 though, but these do apply to AS3





im not sure about my program crashing though, i dont know why that might be, unless you absolutely cannot use openGL, although i havnt used it in the 3d rendering, i am using openGL to display the rendering as a texture on a single quad since its alot faster than using win32 and SetPixel


The Beginning Of All Things To End.
The End Of All Things To Come.
 

#4 2006-08-22 07:45:12

MathsIsFun
Administrator

Offline

Re: C++ software rendering

Thanks for the great info, luca. I am looking forward to Flash 9 even more now. It may be a year before I do, though, because I have to keep my website available to the majority (for example schools).

I will try to find out why AS3.exe didn't work for me.


"The physicists defer only to mathematicians, and the mathematicians defer only to God ..."  - Leon M. Lederman
 

#5 2006-08-22 17:12:08

luca-deltodesco
Super Member
Award: Wink Alive

Offline

Re: C++ software rendering

you could always just download the public alpha like i did to play with, its free, and you can use it as long as you have flash 8 pro


The Beginning Of All Things To End.
The End Of All Things To Come.
 

Board footer

Powered by FluxBB