Author Topic: X_SPRITE replacement - (faster) 3D sprite with rotation (billboards)  (Read 10813 times)

Offline djtoon

  • Dr. Type
  • ****
  • Posts: 290
    • View Profile
yes
dosent work...
cant figure it out.

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1577
  • Particle Hawk
    • View Profile
    • Silver Volumetric Software
@djtoon: sorry man, i wish i knew about it more.

@kanonet:

Yoo hoooo Kano, Draw2() here


Code: GLBasic [Select]
        // Cylindrical Billboards
        // This billboard will only be rotated on Y axes, when the camera moves(not when camera rotates).
        // This billboard is rigid on the Y axes, it only rotates facing the camera position.
        // When the camera looks around(rotates), the billboard won't move.
        // Is this method faster? I dont know. Its good for trees and lightning =D
        // This billboard is mid handled.
        // X,Y,Z are the billboard xyz coords
        // CameraX, CameraY, CameraZ are the camera position
        // Scale is absolute, in metric opengl coordinates 1:1, it will increase billboard size.
        // rotation shouldnt need to be used, but you can use it to spin the billboard.
        // use X_SETTEXTURE #,-1 to set the billboard image after you call type.start()
        // -Neil Silver, aka Hemlos on GLBasic forums, hemlos@ymail.com
        FUNCTION Draw2%: X#,Y#,Z#, CameraX#, CameraY#, CameraZ#, scale#=1.0, rotation#=360.0

                LOCAL CMX#, CMY#, CMZ#, pwidth#, nscale#, pscale#, angx#, angy#
                LOCAL vx1#, vy1#, vz1#, vx2#, vy2#, vz2#, vx3#, vy3#, vz3#, vx4#, vy4#, vz4#
                rotation=rotation-45.0
                angy=angy-(qATAN2((X-CameraX)*-1.0,(Z-CameraZ)*-1.0)-90.0)
                width=scale*0.5; nscale=-width; pscale=width
                vx1=qSIN(rotation)*qSIN(angy)*pscale; vy1=qCOS(rotation)*pscale; vz1=qSIN(rotation)*qCOS(angy)*nscale
                vx2=qCOS(rotation)*qSIN(angy)*pscale; vy2=qSIN(rotation)*nscale; vz2=qCOS(rotation)*qCOS(angy)*nscale
                vx3=-vx2; vy3=-vy2; vz3=-vz2; vx4=-vx1; vy4=-vy1; vz4=-vz1

                self.vertices[0] = vx1 + X; self.vertices[1] = vy1 + Y; self.vertices[2] = vz1 + Z
                self.vertices[3] = vx2 + X; self.vertices[4] = vy2 + Y; self.vertices[5] = vz2 + Z
                self.vertices[6] = vx3 + X; self.vertices[7] = vy3 + Y; self.vertices[8] = vz3 + Z
                self.vertices[9] = vx4 + X; self.vertices[10]= vy4 + Y; self.vertices[11]= vz4 + Z

                ?IF DEFINED( gl_gbas )
                        glVertexPointer( 3, GL_FLOAT, 0, self.vertices[] )
                        glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 )
                ?ELSE
                        INLINE
                                glVertexPointer( 3, GL_DOUBLE, 0, &this->vertices(0) );
                                glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
                        ENDINLINE
                ?ENDIF
        ENDFUNCTION


 
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

http://silver.binhoster.com/

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1577
  • Particle Hawk
    • View Profile
    • Silver Volumetric Software
Just a recap on that function i added to the libSPRITE:

It is a cylindrical billboard, meaning it only rotates on Y axes for Trees, grass, and stuff like that.

It is 3-4 times slower than Draw().
It is still twice as fast as using a quad.

Kano you can rewrite that function and add it to your lib if you want, that function will work immediately if you stick it underneath draw()
However, you might want to rewrite it for better speed considering variables, i tried myself and didnt see any difference in speed.



Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

http://silver.binhoster.com/

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Im almost done with rewriting it, since i was always thinking about adding cylindrical billboards, but was to lazy. :P
Btw. feel free to join me in IRC.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Ok, new version is online (1st post+website), now there are two drawing functions:
draw()   -> spherical billboard, same like x_sprite, but with rotation
draw2() -> cylindrical billboard, use it for trees etc., can rotate too
I also did rewrite parts of older code, so there is a slight change for a tiny speed improvement, but dont quote me on that.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
(sorry for triple post)

I finally updated the lib, its working on mobile devices now. I tested it on Android, but it should also work on iOS, also Windows and Linux are tested, Mac should work too. Also I did rewrite and encapsulated it better, so that it will never make any problems, if you decide to use it together with some other native OpenGL calls/libs, code looks a bit ugly now, but its all running fine and was definitely worth it. Please note, that the Stop() function is back.
And the 1st Post got updated, cause the informations there became a bit outdated since the initial release of this lib. You find all you need in 1st Post. ;)
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1577
  • Particle Hawk
    • View Profile
    • Silver Volumetric Software
APE goes faster now Ooo Ooo Ooo
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

http://silver.binhoster.com/

Offline UBERmonkeybot

  • Mr. Polyvector
  • ***
  • Posts: 243
    • View Profile
The download link is dead. :'(

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1577
  • Particle Hawk
    • View Profile
    • Silver Volumetric Software
The source code in the first message looks legit.
I think i have the latest files here, i put them in a .rar

edit: removed file from message, too old
« Last Edit: 2016-Feb-20 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

http://silver.binhoster.com/

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Yes sorry my side is still down. But the code is also in 1st post, this should be the latest version.
« Last Edit: 2016-Feb-18 by kanonet »
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64