|
Post by DJLinux on Nov 11, 2008 20:28:04 GMT -5
Very nice djinux, How do you get the subs to share information in the SDK? Do you mean how callbacks from any plugin works? Joshy
|
|
|
Post by Darkjester on Nov 11, 2008 21:20:46 GMT -5
Im guessing, im trying to make a particle engine api plugin, i have the framework, but im trying to add paramters kinda like the gl_param sorta thing as well as having my subroutines shareing data to compute positions and then make calls to show them to screen.
|
|
|
Post by DJLinux on Nov 15, 2008 18:12:16 GMT -5
i got many types of callback's working
let me know if any will take a look to the plugin C++ source code
Joshy
(by the way i found out that when you use VisualStudio or Codeblocks with MinGW a empty B4GL plugin will be 40~KB but now i use Netbeams IDE with CygWin and the same plugin are only 20~KB)
|
|
|
Post by DJLinux on Nov 15, 2008 18:26:48 GMT -5
use the link from first post (C++ Source Code and a NewtonPlugin.dll is included)
Joshy
|
|
|
Post by Darkjester on Nov 15, 2008 18:28:41 GMT -5
thnx im sure it will be helpful edit: I just did a fps test between this physics engine compared to the other one you ported, This one is about 20 fps FASter!!!!!
|
|
|
Post by Nicky Peter Hollyoake on Nov 17, 2008 20:19:19 GMT -5
This is good. ;D I probaly won't use many plugins because I believe in learning the background of something before using it. Using plugins would make me feel dumb. - Nicky
|
|
|
Post by Adam on Dec 11, 2008 21:12:24 GMT -5
here.. i got bored and was messing around with the test2 and thins is what i got.. enjoy..' prototypes declare sub InitGL(x#,y#,z#) declare sub DrawBox(x#,y#,z#,m#()())
' globals const MAX_BOXES=101 dim Boxes(MAX_BOXES-1) dim M#(3,3)
' callbacks sub AutoactiveCallback() dim Body=NewtonGetCallbackBody() dim State=NewtonGetCallbackState() ' do what ever end sub sub TransformCallback() dim Body=NewtonGetCallbackBody() dim TM#(3)(3)=NewtonGetCallbackMatrix() ' do what ever end sub
' called for all bodys from NewtonUpdate() sub ForceAndTorqueCallBack() dim Body=NewtonGetCallbackBody() NewtonBodySetForce(body,vec3(0,NewtonBodyGetMass(body)*-9.81,0)) end sub ' called if a body dies sub DestructorCallBack() ' mark it as unused Boxes(NewtonBodyGetUserData(NewtonGetCallbackBody()))=-1 end sub ' called for any body outside the WorldSpace sub LeaveWorldEvent() dim Body = NewtonGetCallbackBody() ' let it die (newton will call the DestructorCallback) NewtonDestroyBody(NewtonBodyGetWorld(Body),Body) end sub
' setup OpenGL mode and observer InitGL(0,5,25)
' create a newton world dim World=NewtonCreate() ' [optional] define a smal world space NewtonSetWorldSize(World,vec3(-500,-1,-100),vec3(500,500,100)) ' set an Event (for all bodys outside our world space) NewtonSetBodyLeaveWorldEvent(World,"LeaveWorldEvent()")
' create a none moveable ground box dim cGround = NewtonCreateBox(World,10,1,10) dim bGround = NewtonCreateBody(World,cGround) ' release the collision box object '(decrement OOP object referenc) NewtonReleaseCollision(World, cGround)
' create a collision 1x1x1 unit box dim cBox=NewtonCreateBox(World,1,1,1)
dim x#,y#,i for i=0 to MAX_BOXES-1 ' create rigid body Boxes(i)=NewtonCreateBody(World,cBox) ' disable auto freezing NewtonBodySetAutoFreeze(Boxes(i),0) ' save array index as user data NewtonBodySetUserData(Boxes(i),i) ' set mass NewtonBodySetMass(Boxes(i),1) ' set callback's NewtonBodySetAutoactiveCallback(Boxes(i),"AutoactiveCallback()") NewtonBodySetTransformCallback(Boxes(i),"TransformCallBack()") NewtonBodySetForceAndTorqueCallBack(Boxes(i),"ForceAndTorqueCallBack()") NewtonBodySetDestructorCallBack(Boxes(i),"DestructorCallBack()") ' set position NewtonBodyGetMatrix(Boxes(i),m#) ' x,y,z position y#=int(i / 10) x#=int(i - (y#*10)) x#=(x#-2.5)*1. if int(y#) and 1 then x#=x#+0.75:end if y#=1.001+y#*1.001 m#(3,0)= x#-2 m#(3,1)= y# 'm#(3,2)= z# NewtonBodySetMatrix(Boxes(i),m#) next ' release the collision box object '(decrement OOP object referenc) NewtonReleaseCollision(World,cBox)
' ' main loop ' dim zrot#, Angle#(1) while TRUE ' one step in our simulation (60 FPS) NewtonUpdate(World,1.0/60.0) glClear(GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT) GLRotateF(Angle#(0),0,1,0) GLRotateF(Angle#(1),0,0,1) ' draw the ground box DrawBox(10,1,10,NewtonBodyGetMatrix2(bGround) ) ' draw the moveable rigid boxes for i=0 to MAX_BOXES-1 ' draw only active bodys if Boxes(i)<>-1 then DrawBox(1,1,1,NewtonBodyGetMatrix2(Boxes(i)) ) end if next
NewtonBodyGetMatrix(bGround,m#) m#(0,1)=Angle#(1) M#(0,2)=Angle#(0) NewtonBodySetMatrix(bGround,m#) IF Mouse_Button(Mouse_LButton) Then 'For I = 0 To Max_Boxes-1 Step 10 I = 100 IF Boxes(I) <> -1 Then m#(3,0)= (Mouse_X()-.5)*10 m#(3,1)= (1-Mouse_Y())*10 m#(3,2)= 10 NewtonBodySetMass(Boxes(i),10) NewtonBodySetMatrix(Boxes(i),m#) NewtonBodySetVelocityxyz(Boxes(I),0,0,500) Endif 'Next Endif IF ScanKeyDown(VK_Left) Then Angle#(0) = Angle#(0) - .01 Endif IF ScanKeyDown(VK_Right)Then Angle#(0) = Angle#(0) + .01 Endif IF ScanKeyDown(Asc("A")) Then Angle#(1) = Angle#(1) - .01 Endif IF ScanKeyDown(Asc("D")) Then Angle#(1) = Angle#(1) + .01 Endif SwapBuffers() WaitTimer(1000/60) wend
' free all newton resources NewtonDestroy(World)
sub InitGL(x#,y#,z#) glViewport(0, 0, WindowWidth(),WindowHeight()) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45.0, WindowWidth()/WindowHeight(), 1, 1000) glMatrixMode(GL_MODELVIEW)
glClearColor(0.25, 0.25, 0.5, 1) glShadeModel(GL_SMOOTH) glLightfv(GL_LIGHT0, GL_POSITION,vec4(0,10,5, 0)) glLightfv(GL_LIGHT0, GL_AMBIENT ,vec4(0.2,0.2,0.2, 0)) glLightfv(GL_LIGHT0, GL_DIFFUSE ,vec4(0.7,0.7,0.7, 0)) glLightfv(GL_LIGHT0, GL_SPECULAR,vec4(0.7,0.7,0.7, 0))
glEnable(GL_LIGHTING) glEnable(GL_LIGHT0)
glEnable(GL_DEPTH_TEST) glEnable(GL_CULL_FACE) glFrontFace(GL_CCW)
glMaterialfv(GL_FRONT, GL_SPECULAR , vec4(0,0,1, 1)) glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, vec4(0.5,0.75,0, 1)) glMaterialf (GL_FRONT, GL_SHININESS , 15.0)
glTranslatef(-x#,-y#,-z#) end sub
sub DrawBox(x#,y#,z#,m#()()) glPushMatrix() glMultMatrixf(m#) glScalef(x#,y#,z#) glBegin(GL_QUADS) ' front glNormal3f(0.0, 0.0, 1.0) glVertex3f(-0.5, -0.5, 0.5) glVertex3f( 0.5, -0.5, 0.5) glVertex3f( 0.5, 0.5, 0.5) glVertex3f(-0.5, 0.5, 0.5) ' back glNormal3f(0.0, 0.0, -1.0) glVertex3f( 0.5, -0.5, -0.5) glVertex3f(-0.5, -0.5, -0.5) glVertex3f(-0.5, 0.5, -0.5) glVertex3f( 0.5, 0.5, -0.5) ' top glNormal3f(0.0, 1.0, 0.0) glVertex3f(-0.5, 0.5, 0.5) glVertex3f( 0.5, 0.5, 0.5) glVertex3f( 0.5, 0.5, -0.5) glVertex3f(-0.5, 0.5, -0.5) ' bottom glNormal3f(0.0, -1.0, 0.0) glVertex3f(-0.5, -0.5, -0.5) glVertex3f( 0.5, -0.5, -0.5) glVertex3f( 0.5, -0.5, 0.5) glVertex3f(-0.5, -0.5, 0.5) ' left glNormal3f(-1.0, 0.0, 0.0) glVertex3f(-0.5, -0.5, -0.5) glVertex3f(-0.5, -0.5, 0.5) glVertex3f(-0.5, 0.5, 0.5) glVertex3f(-0.5, 0.5, -0.5) ' right glNormal3f(1.0, 0.0, 0.0) glVertex3f(0.5, -0.5, 0.5) glVertex3f(0.5, -0.5, -0.5) glVertex3f(0.5, 0.5, -0.5) glVertex3f(0.5, 0.5, 0.5) glEnd() glPopMatrix() end sub
i did this in about 10 minutes.. i was bored lol.. so there is no special declarations or anything.. happy shooting =].. i am soo happy i actually understand this physics plugin(for the most part)
|
|
|
Post by DJLinux on Jan 8, 2009 18:57:20 GMT -5
Hey Djlinux can you upload the missing headers for this plugin? what for missing headers? Joshy
|
|