Jump to content

CrazyM

Members
  • Posts

    86
  • Joined

  • Last visited

Posts posted by CrazyM

  1. Can anyone recommend the best method to rotate an entity in global space, over time, to a specific angle (90 degree increments)?

     

    I wrote a bit that does this, but it feels like bloated attempt and has some issues when it comes to detecting when the rotation has arrived at it's destination due to float value variations.

     

    In the example below, a button click sets the rotation in motion with (self.rotateX = true), and increments the first step in the rotation with (self.rotateSpeed). In the update function, the current global x rotation is compared to the target (self.rotAngle.x) rotation, and the rotation should continue until the global and target rotations match. At this point, the rotateX flag is disabled (self.rotateX = false).

     

    function Script:UpdateWorld()
       -- Attempting to detect when the target rotation has been reached
       if Math:Round(self.selected:GetRotation(true).x) ~= self.rotAngle.x and self.rotateX == true then
        self.newRot = self.selected:GetRotation(true)
        self.newRot.x = Math:Inc(self.rotAngle.x, self.selected:GetRotation(true).x, self.rotateSpeed)
        self.selected:SetRotation(self.newRot, true)
        if Math:Round(self.selected:GetRotation(true).x) == self.rotAngle.x and self.rotateX == true then
    	    self.rotateX = false
    	    System:Print("X rotation complete")
        end
       end
    end
    
    function Script:ButtonClick(mPos)
       if self:IsInRect(mPos, self.upRect) == true then
        self.rotateX = true
        self.rotAngle = self.selected:GetRotation(true) + Vec3(90,0,0)
        self.newRot.x = Math:Inc(self.rotAngle.x, self.selected:GetRotation(true).x, self.rotateSpeed)
        self.selected:SetRotation(self.newRot, true)
       end
    end
    

  2. I have a Lua script that has the following exposed property.

     

    Script.pawns = nil --entity "Pawns"

     

    The Pawns entity is a pivot used as a parent to several other entities. Inside the script, I use this reference to iterate through the children.

     

    childCount = self.pawns:CountChildren()

     

    for i=0, i<childCount-1, 1 do

    --Some action

    end

     

    This normally works great, but I've had three occurances of this reference suddenly reading as nil when no change occurred in the script, and the UI for the exposed property still shows the Pawns entity being linked.

     

    Once this nil error occurs, nothing short of deleting the Pawns pivot, creating a new pivot and re-parenting all my child entities, and re-linking the Pawns property corrects the problem. I have tried un-linking and re-linking the reference, removing and re-adding the script, nothing else seems to work, and I've made no change to warrent reference failure.

  3. I'm assuming you mean top-down camera instead of 3rd person since you want the roof to disappear when the player walks in. If that's the case, here's the general approach.

     

    Start by performing a raycast (Pick) from your camera to the player and enable the [closest] parameter.

    http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/camera/camerapick-r199

     

    If the returned pickInfo.entity is not your player, then you can assume some kind of overhang (roof) is covering the player. Swap the material on the overhang.

    http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/material/materialsetshader-r247

  4. Thanks Josh, I'm working with the data now.

     

    To anyone interested, I found a really great article on processing audio with an FFT window. I think this might work, though I may have to read the article 3-4 more times. wink.png

     

    Part I

    http://www.edn.com/electronics-news/4383713/Windowing-Functions-Improve-FFT-Results-Part-I

     

    Part II

    http://www.edn.com/electronics-news/4386852/Windowing-Functions-Improve-FFT-Results-Part-II

     

    If I can build a getspectrum function, then we can try convince Josh to include it in the API. Having this ability brings a lot of cool possibilities, lip sync, music-based games, etc.

  5. I know, old post, but I wrote this LUA swinging door script as an alternative to the built in script, and maybe someone else might find it useful.

     

    This script does not use a hinge joint, it assumes it's attached to a 3D model door with it's pivot point on the side where a normal hinge would go. Set a [1] on the rotation axis you wish to rotate, adjust the movement speed, the open/close angles, and link to optional open/close sounds. It also assumes your operating the door from the FPSPlayer script.

     

    Script.rotationAxis = Vec3(0,1,0) --Vec3 "Rotation Axis"
    Script.movementSpeed = 3 --float "Movement Speed"
    Script.closeAngle = 0 --int "Close Angle"
    Script.openAngle = 135 --int "Open Angle"
    Script.closeSound = "" --path "Close Sound"
    Script.openSound = "" --path "Open Sound"
    
    rotation = Vec3(0,0,0)
    moveDoor = false
    openDoor = false
    openSnd = nil
    closeSnd = nil
    
    function Script:Start()
       if self.openSound ~= "" then
           openSnd = Sound:Load(self.openSound)
       end
    
       if self.closeSound ~= "" then
           closeSnd = Sound:Load(self.closeSound)
       end
    end
    
    --FPSPlayer Use method
    function Script:Use()
       if openDoor == true then
           if closeSnd ~= nil then
               closeSnd:Play()
           end
           openDoor = false
       else
           if openSnd ~= nil then
               openSnd:Play()
           end
           openDoor = true
       end
       moveDoor = true
    end
    
    function Script:UpdateWorld()
       -- Stop movement if the open/close angles have been reached
       if self.rotationAxis.x == 1 then -- X rotation axis set
           if openDoor == true and self.entity:GetRotation().x >= self.openAngle then
               moveDoor = false
           end
           if openDoor == false and self.entity:GetRotation().x <= self.closeAngle then
               moveDoor = false
           end
       end
    
       if self.rotationAxis.y == 1 then -- Y rotation axis set
           if openDoor == true and self.entity:GetRotation().y >= self.openAngle then
               moveDoor = false
           end
           if openDoor == false and self.entity:GetRotation().y <= self.closeAngle then
               moveDoor = false
           end
       end
    
       if self.rotationAxis.z == 1 then -- Z rotation axis set
           if openDoor == true and self.entity:GetRotation().z >= self.openAngle then
               moveDoor = false
           end
           if openDoor == false and self.entity:GetRotation().z <= self.closeAngle then
               moveDoor = false
           end
       end
    
       -- Move the door towards it's selected position
       if moveDoor == true then
           if openDoor == true then -- Close door    
               if self.rotationAxis.x == 1 then
                   rotation.x = rotation.x + (Time:GetSpeed() * self.movementSpeed)
               end
               if self.rotationAxis.y == 1 then
                   rotation.y = rotation.y + (Time:GetSpeed() * self.movementSpeed)
               end
               if self.rotationAxis.z == 1 then
                   rotation.z = rotation.z + (Time:GetSpeed() * self.movementSpeed)
               end            
           else -- Open door
               if self.rotationAxis.x == 1 then
                   rotation.x = rotation.x - (Time:GetSpeed() * self.movementSpeed)
               end
               if self.rotationAxis.y == 1 then
                   rotation.y = rotation.y - (Time:GetSpeed() * self.movementSpeed)
               end
               if self.rotationAxis.z == 1 then
                   rotation.z = rotation.z - (Time:GetSpeed() * self.movementSpeed)
               end
           end    
           self.entity:SetRotation(rotation)
       end
    end
    

  6. I'm trying to tap the OpenAL raw audio data to see if it can be processed with an FFT window to build a live stream of the spectrum or amplitude of a playing audio file. This is quite simple in FMOD since it ships with a getSpectrum function. However, we are evaluating the feasibility of bringing our automated lip sync solution, originally built for Unity on top of FMOD, to Leadwerks, and after speaking with Josh, including FMOD as a built in option for Leadwerks users isn't an option at this time. Personally, we would love to see an asset store for Leadwerks as we think Unity has proven it's a good source of income for the host company, encourages developer involvement, and makes it easier for new developers. It is popular enough to convince Unreal Engine to get on board and open their own asset store.

     

    Josh informed me that the Bank class pointer references the raw data but I'm struggling to determine if the data in the bank->buf could be processed through an FFT window.

     

    Are there any OpenAL pro's here that know if this can be done, and might be will to share some expertise?

     

    In case anyone is interested or curious, here are some of our promotional videos for our solution on Unity.

     

    Thanks

    • Upvote 1
  7. Thanks for posting that example test cubes. What I've discovered is that the bad normal values are only being returned on prefabs that are instantiated into the scene at runtime. If I place the block in the scene at design time, the normals are correct. I am setting the rotation to (0,0,0) on instantiation, but still getting the bad values. After trying your cubes, I tried my Blender cubes again and found the same thing, the Blender cube works fine when placed in the scene at design time, but not at runtime.

×
×
  • Create New...