Jump to content

Aily

Members
  • Posts

    465
  • Joined

  • Last visited

Posts posted by Aily

  1. :)

     

    My NPC have controller,head pivot and mesh

     

    Each UpdatePhysics i have one current NPC target, and i do this:

     

    1. set head pivot to controller position

    2. point head smooth to current target waypoint

    3. move controller forward using head.Y as controller turn

     

    Something like that. Movement is smooth enough.

     

    On NPC creation

    function create_bot(obj)
    
    obj.body=CreateController(obj.height,obj.width,obj.step_height,obj.max_slope)
    
    SetBodyMass(obj.body,1)
    EntityType(obj.body,COLLISION_CHARACTER)
    
    obj.head=CreatePivot()
    
    refresh_mesh(obj,GetEntityKey(obj.model,"mesh"))
    if obj.mesh==nil then
    	obj.mesh=CreatePivot()
    end
    PositionEntity(obj.body,EntityPosition(obj.model))
    PositionEntity(obj.head,EntityPosition(obj.model))
    RotateEntity(obj.head,Vec3(0,EntityRotation(obj.model).y,0))
    end
    

     

    and on PhysicsUpdate

    if obj.target~=nil then
    	if EntityDistance(obj.body,obj.target)<.5 then
    		get_next_point(obj)
    		return
    	end
    	PositionEntity(obj.head,EntityPosition(obj.body))
    	obj.head:Point(obj.target,3,obj.turn_smooth,0)
    
    	obj.body:Update(EntityRotation(obj.head).y,obj.walk_speed,0,0,40,1,0)
    end
    
    PositionEntity(obj.mesh,EntityPosition(obj.body))
    RotateEntity(obj.mesh,Vec3(0,EntityRotation(obj.head).y-180,0))
    

  2. Aily... i believe klepto did it and posted it in his blog... but he did it without using the LE inherent commands but rather raw opengl...

    http://www.leadwerks.com/werkspace/blog/16/entry-654-cubemaps-realtime-here-we-go/

    which to me indicates there is something wrong with LE's implementation... :)

    Yeah, i saw thais, but im making this by LUA, and such method is impossible there, you know it yourself :P That's why ask Josh to fix this.

  3. I'm on my Mac right now and don't have an easy way of checking your texture, but if it doesn't have mipmaps, NVidia cards will render it pure black.

     

    Thanks for turbo reply

     

    Even if i use?

    textureCubeLod(LW_CUBEMAP,cubecoord,0)
    

     

    So then any way to build mipmaps after buffer render? (let it be so, let it be so....... :) )

  4. Hi Josh.

     

    Here have strange things. That's code to render to simple 2D texture, it works great

    Framework leadwerks.engine
    
    registerabstractpath AppDir
    
    Graphics 800,600
    
    createworld
    
    cp=createpivot()
    cam=createcamera()
    cameraclearcolor cam,vec4(.5,.5,.5,1)
    entityparent cam,cp
    moveentity cam,vec3(0,1,-1)
    pointentity cam,cp
    
    c=createsphere()
    
    mat=creatematerial()
    setmaterialshader mat,loadshader("abstract::mesh.vert","abstract::mesh_diffuse.frag")
    
    tex=createtexture(256,256)
    setmaterialtexture mat,tex,0
    
    paintentity c,mat
    
    tex_buffer=createbuffer(256,256,BUFFER_COLOR)
    setcolorbuffer tex_buffer,tex,0
    
    setbuffer tex_buffer
    SetColor vec3(0)
    DrawRect 0,0,256,256
    SetColor vec3(1)
    DrawRect 50,50,100,100
    
    Repeat
    
    If KeyHit(key_escape) Or AppTerminate() End
    
    turnentity cp,vec3(0,.2,0)
    
    setbuffer backbuffer()
    renderworld
    Flip 1
    
    Forever
    

     

    Here's the code to load cubemap from file, and just to check that mesh_cubemap.frag works:

    Framework leadwerks.engine
    
    registerabstractpath AppDir
    
    Graphics 800,600
    
    createworld
    
    cp=createpivot()
    cam=createcamera()
    cameraclearcolor cam,vec4(.5,.5,.5,1)
    entityparent cam,cp
    moveentity cam,vec3(0,1,-1)
    pointentity cam,cp
    
    c=createsphere()
    
    mat=creatematerial()
    setmaterialshader mat,loadshader("abstract::mesh_cubemap.vert","abstract::mesh_cubemap.frag")
    
    tex=loadtexture("abstract::sunol_cubemap.dds")
    setmaterialtexture mat,tex,0
    
    paintentity c,mat
    
    Repeat
    
    If KeyHit(key_escape) Or AppTerminate() End
    
    turnentity cp,vec3(0,.2,0)
    
    setbuffer backbuffer()
    renderworld
    Flip 1
    
    Forever
    

     

    And this is code like above, but drawing to cubemap:

    Framework leadwerks.engine
    
    registerabstractpath AppDir
    
    Graphics 800,600
    
    createworld
    
    cp=createpivot()
    cam=createcamera()
    cameraclearcolor cam,vec4(.5,.5,.5,1)
    entityparent cam,cp
    moveentity cam,vec3(0,1,-1)
    pointentity cam,cp
    
    c=createsphere()
    
    mat=creatematerial()
    setmaterialshader mat,loadshader("abstract::mesh_cubemap.vert","abstract::mesh_cubemap.frag")
    
    tex=createcubemap(256,256)
    setmaterialtexture mat,tex,0
    
    paintentity c,mat
    
    tex_buffer_0=createbuffer(256,256,BUFFER_COLOR)
    tex_buffer_1=createbuffer(256,256,BUFFER_COLOR)
    tex_buffer_2=createbuffer(256,256,BUFFER_COLOR)
    tex_buffer_3=createbuffer(256,256,BUFFER_COLOR)
    tex_buffer_4=createbuffer(256,256,BUFFER_COLOR)
    tex_buffer_5=createbuffer(256,256,BUFFER_COLOR)
    
    setcolorbuffer tex_buffer_0,tex,0,0
    setcolorbuffer tex_buffer_1,tex,0,1
    setcolorbuffer tex_buffer_2,tex,0,2
    setcolorbuffer tex_buffer_3,tex,0,3
    setcolorbuffer tex_buffer_4,tex,0,4
    setcolorbuffer tex_buffer_5,tex,0,5
    
    setbuffer tex_buffer_0
    SetColor vec3(0)
    DrawRect 0,0,256,256
    SetColor vec3(1)
    DrawRect 50,50,100,100
    
    setbuffer tex_buffer_1
    SetColor vec3(0)
    DrawRect 0,0,256,256
    SetColor vec3(1)
    DrawRect 50,50,100,100
    
    setbuffer tex_buffer_2
    SetColor vec3(0)
    DrawRect 0,0,256,256
    SetColor vec3(1)
    DrawRect 50,50,100,100
    
    setbuffer tex_buffer_3
    SetColor vec3(0)
    DrawRect 0,0,256,256
    SetColor vec3(1)
    DrawRect 50,50,100,100
    
    setbuffer tex_buffer_4
    SetColor vec3(0)
    DrawRect 0,0,256,256
    SetColor vec3(1)
    DrawRect 50,50,100,100
    
    setbuffer tex_buffer_5
    SetColor vec3(0)
    DrawRect 0,0,256,256
    SetColor vec3(1)
    DrawRect 50,50,100,100
    
    Repeat
    
    If KeyHit(key_escape) Or AppTerminate() End
    
    turnentity cp,vec3(0,.2,0)
    
    setbuffer backbuffer()
    renderworld
    Flip 1
    
    Forever
    

     

    As you can see - i'm using same technique as draw to 2D texture - assign it to buffer,

    But with cubemaps im assigning cubefaces to 6 buffers.

     

    Think this code must be work, but it didnt :) Maybe you can show the correct way to use render to cubemaps?

    Thanks.

    post-260-0-01704600-1325755765_thumb.jpg

    post-260-0-24003600-1325755769_thumb.jpg

    post-260-0-32037900-1325755773_thumb.jpg

  5. Long time fighting fith charachter controller don't give good result for my Last Chapter platformer.

    So Arbuz give me a good idea - make my own AABB collisions engine, because Last Chapter in fact have only box bodies.

     

    Hahaha!!!! Now with this i can make movable platforms, accurate to metall attachement player and much more!

     

    This is AABB collisions base, maybe someone will be make such platformer :P

     

    
    Global bodies:TList=CreateList()
    
    Type body
    
    Field x#,y# ' aa
    Field w#,h# ' bb
    
    Field width#
    Field height#
    
    End Type
    
    Function add_body:body(x#,y#,width#,height#)
    
    Local b:body=New body
    
    b.x=x-width/2
    b.y=y-height/2
    b.width=width
    b.height=height
    b.w=b.x+width
    b.h=b.y+height
    
    ListAddLast bodies,b
    
    Return b
    
    End Function
    
    Function render_bodies()
    
    For b:body=EachIn bodies
    	SetColor 255,255,255
    	DrawRect b.x,b.y,b.width,b.height
    	SetColor 50,50,50
    	DrawRect b.x+1,b.y+1,b.width-2,b.height-2
    Next
    
    End Function
    
    Function ol(pv#,cv#,nv#)
    Return cv>pv And cv<nv
    End Function
    
    
    Function move_body(b:body,x#,y#)
    
    nx#=b.x+x
    ny#=b.y+y
    nw#=b.w+x
    nh#=b.h+y
    fx#=x
    fy#=y
    
    For bb:body=EachIn bodies
    	If bb=b Continue
    	If fx>0
    		If ol(bb.x,nw,bb.w) Or ol(b.x,bb.x,nw)
    			If ol(bb.y,ny,bb.h)	fx=bb.x-b.w
    			If ol(bb.y,nh,bb.h)	fx=bb.x-b.w
    			If ol(ny,bb.y,nh)	fx=bb.x-b.w
    			If ol(ny,bb.h,nh)	fx=bb.x-b.w
    			If bb.y=b.y And b.h=bb.h fx=bb.x-b.w
    		End If
    	End If
    	If fx<0
    		If ol(bb.x,nx,bb.w) Or ol(nx,bb.w,b.w)
    			If ol(bb.y,ny,bb.h)	fx=bb.w-b.x
    			If ol(bb.y,nh,bb.h)	fx=bb.w-b.x
    			If ol(ny,bb.y,nh)	fx=bb.w-b.x
    			If ol(ny,bb.h,nh)	fx=bb.w-b.x
    			If bb.y=b.y And b.h=bb.h fx=bb.w-b.x
    		End If
    	End If
    	If fy>0
    		If ol(bb.y,nh,bb.h) Or ol(b.y,bb.y,nh)
    			If ol(bb.x,nx,bb.w)	fy=bb.y-b.h
    			If ol(bb.x,nw,bb.w)	fy=bb.y-b.h
    			If ol(nx,bb.x,nw)	fy=bb.y-b.h
    			If ol(nx,bb.w,nw)	fy=bb.y-b.h
    			If bb.x=b.x And b.w=bb.w fy=bb.y-b.h
    		End If
    	End If
    	If fy<0
    		If ol(bb.y,ny,bb.h) Or ol(ny,bb.h,b.h)
    			If ol(bb.x,nx,bb.w)	fy=bb.h-b.y
    			If ol(bb.x,nw,bb.w)	fy=bb.h-b.y
    			If ol(nx,bb.x,nw)	fy=bb.h-b.y
    			If ol(nx,bb.w,nw)	fy=bb.h-b.y
    			If bb.x=b.x And b.w=bb.w fy=bb.h-b.y
    		End If
    	End If
    Next
    
    b.x=b.x+fx
    b.y=b.y+fy
    b.w=b.w+fx
    b.h=b.h+fy
    
    End Function
    
    Graphics 800,600
    
    add_body(410,160,20,240)
    add_body(50,70,20,140)
    add_body(50,210,20,140)
    add_body(230,290,340,20)
    add_body(130,150,20,100)
    add_body(280,170,120,20)
    
    player=add_body(310,260,20,40)
    
    Repeat
    
    If KeyHit(KEY_escape) Or AppTerminate() End
    
    shift=KeyDown(key_lshift)*200
    
    If KeyDown(key_left) move_body player,-2-shift,0
    If KeyDown(key_right) move_body player,2+shift,0
    If KeyDown(key_up) move_body player,0,-2-shift
    If KeyDown(key_down) move_body player,0,2+shift
    
    Cls
    render_bodies
    Flip 1
    
    Forever
    

     

    Here's compiled EXE, arrows-for move, shift - some speedup movable body (check swept collisions)

    aabb_collisions.rar

    post-260-0-30616100-1324691141_thumb.jpg

  6. Hi to all

     

    I'm store 6 textures in one big texture, now it's like on image "rect.jpg", i.e. my texture is rectangle.

     

    Long time ago, when i started to learn OpenGL i was read that is need to store textures as rectangles

     

    32x32, 64x64.....2048x2048... because some of video hardware working with square textures only.

     

    But more handy and simple to store texture in one strip-line, as on "strip.jpg".

     

    Anybody know, how is better to store textures? Rectangles, or doesn't matter - textures can be any proportions?

    post-260-0-89877300-1324552686_thumb.jpg

    post-260-0-69279800-1324552691_thumb.jpg

  7. I don't know how your NPCs are walking.

     

    My first idea was a waypoints - and i maked it for LUA, my NPC can walk in Editor, but as like on rails.

     

    So i spended some time to write this simple mesh pathfinding.

     

    Now it on b3d, i'm planing to some update it and port in Leadwerks Editor.

     

    To set start-finish nodes use mouse right\left buttons.

    To see debug lines hold space button.

    post-260-0-76287500-1322018004_thumb.jpg

    post-260-0-75907300-1322018009_thumb.jpg

    navmesh_basics.rar

  8. The idea is simple:

     

    I want to make one lua class to control NPC for example.

     

    Now i have one NPC, lets call it JOE.gmf

    JOE have script JOE.lua, with architecture as all other LUA scripts in Leadwerks.

    JOE.lua have many lines of code, and many parameters.

     

    Now i add new NPC, let's call it MAX.gmf

    MAX have same code, but another parameters. May be MAX can shot.

    I copy now JOE.lua to MAX.lua, and ajust parameters.

     

    All cool, JOE and MAX walking in world.

     

    BUT!!!

    I see that them stacking in each other then close to each other.

    I need to fix both lua files in same time?

     

    I try to do:

    copy JOE.lua to "scripts\npc.lua" file

    clear JOE.lua code

    And put there only require("scripts/npc")

     

    And i have error, that classtable is nil. It is normal? Anyone knows how to correct include files?

  9.  

    It could become some official new Game Framework for LE2.

     

     

    Josh maked same in LUA scripts. So better was to do all game in LUA. But now - is not possible to move back, and i will finish it in Bmax. My next game will be in LUA.

×
×
  • Create New...