Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > CopperCube Open discussion
Extended Javascript API and Showcase

just_in_case
Moderator
Quote
2023-01-21 17:00:15

Just to put a smile on your face, I was able to use Joystick( controller) with the Coppercube game engine and will create API for it so that we can use it easily in Coppercube game engine.

So yeah, Controller support will get added in future version of Coppercube.
Cheers



just_in_case
Moderator
Quote
2023-01-22 16:20:25

Created an Input event API for the controller buttons.

ccbRegisterJoyButtonEvent(funcstr)


previously I made it to return the button numbers that were pressed down, but now I changed it to return the buttonstate from a bitmask[32].
which means it will allow up to 32 buttons and can be more easily configured with multiple buttons simultaneously pressed.
It returns the button state in the power of 2.

like
[1,2,4,8,16,32,64,128,256,512,1024,2048,4096 and  so on]

let's say you pressed button 1 and button 3 at the same time then we know that button 1 = 1, and button 3 = 4, as per the above bitmask.
So it will sum up the bitmask for button 1 and button 3 which is equal to 5 and will return it.

We can then easily use it to check if buttons are pressed in combo and much more. While the button numbers that I was using previously only returned a single button value and didn't allow us to use more buttons at the same time simultaneously.

will add axis, pov, and all as input event receivers.

Here is a test video showcasing the usage of the controller, it prints the number of buttons that were pressed on the controller in the debug panel, if the number was 1 then it will move the cube ahead on X-axis. 0 means no button was pressed.
https://youtu.be/D0VSDiZkqw8

This video was created using the old method, I have updated the code a bit now.

let me know what you guys think about the controller support.

Edit:-

Added POV and Axis input control API

ccbActivateJoystick()
Activates the controller support for your game. Also returns the Joystick Information like number of buttons, axes, Joystick id, name etc.

ccbRegisterJoyButtonEvent(funcstr)
return the bitmap mask of the currently pressed buttons.

ccbRegisterJoyPovEvent(funcstr)
returns Pov value (generally angles)

ccbRegisterJoyAxisVerticalEvent(funcstr)
returns Axis value vertically -1 for down and +1 for up

ccbRegisterJoyAxisHorizontalEvent(funcstr)
returns Axis value horizontally -1 for left and +1 for right

ccbRegisterJoyAxis2VerticalEvent(funcstr)
returns second Axis value vertically -1 for down and +1 for up

ccbRegisterJoyAxis2HorizontalEvent(funcstr)
returns second Axis value horizontally -1 for left and +1 for right

hashtag.joybuttonpressed.button
Special coppercube variable that returns the button state of the button.



I don't have two controllers, so can't check the multiple controller's compatibilities. But the above code works on my controller.

Will soon update my GitHub repo, so that you guys can test the API yourself and let me know how it works.


Aiming_bullets
Guest
Quote
2023-01-22 20:02:37

Thanks @just_in_case for adding some of the core features to the engine, a game controller support is a must in my opinion in a game engine.

really appreciate your and sven's work in the community, you two guys are enhancing the engine day by day.


just_in_case
Moderator
Quote
2023-01-23 06:03:29

Thanks a lot for your kind words, but everybody in this community is contributing something, they are answering each other's questions, and helping each other with music, arts, and other things. I appreciate everybody's work.




DouweDabbe
Guest
Quote
2023-01-27 04:49:12

just_in-case wrote:
@Gree, unfortunately, no, as these commands are developed for the Windows platform only and will work there, not sure if @niko will implement them to work with other platforms as well.


Please update the scripting section of the manual

so as not to spend days and weeks programming something that just can't work on the target platform.

Section:
Windows only ccbCommands
Section:
WebGL only ccbCommands
Section:
Apple only ccbCommands
Section:
Android only ccbCommands


just_in_case
Moderator
Quote
2023-01-27 12:35:19

I don't know if you have noticed it or not, but almost every command that doesn't work in the editor or other platform has a NOTE in the manual that this commands only works on windows, and this command only works in the editor and all.

But yeah, I do think that there should be an easy way of checking them out, I remember I had created my own version of Javascript documentation for neophytes.cf
but never got enough time to work on it. Here is a direct link to the scripting reference on the neophyte.cf it is not complete, but you will get the idea of which commands work on webGL and which on windows, and which in the editor.

https://neophyte.cf/cc_js_ref.hm...

Most of the command has an icon of the supported platform.


DouweDabbe
Guest
Quote
2023-01-27 19:04:55

Nice
Wish everybody contributes a bit to your manual otherwise its a ton of work.


just_in_case
Moderator
Quote
2023-01-28 09:01:08

yeah, it gonna be a lot of work, but I am thinking of adding one code example every sunday, so that it won't hurt and can eventually be progressed.


just_in_case
Moderator
Quote
2023-02-05 05:35:27

Added an extra parameter to the Render to Target API, that will hold the node that you want to exclude from rendering on the RTT texture, The best is to create a folder node in scenegraph explorer and then put all the nodes that you want to exclude in that folder, and simply supply that folder to the API command.
This is useful for example when you don't want overlays to be rendered to the texture.

ccbRenderToTexture(node, material index, camera, X resolution, Y resolution, node to be excluded)


However the RTT texture will cause flickering of water nodes, I am still trying to figure out a way to prevent this. If I will be not able to find a fix, I will try to create a custom water shader.


Added a few more commands:-


 ccbGetParentSceneNode()
Returns the parent node of a scenenode
 special attribut type "Id"
Returns the Id of a sceneNode
 ccbRegisterMouseDownEvent() and "behavior.prototype.onMouseEvent" 
now returns new values as well for DoubleClick and TripleClick for left mouse button
 ccbGetSceneNodeGravity(node)
Returns the gravity of a scene node
 ccbSetSceneNodeGravity(node,gravity)
Sets the gravity of a scenenode.

Above per scene node, gravity only works in the inbuilt collision system and doesn't work for the "physics simulation"
physics simulation still uses the scene gravity. There needs to be a "Collide when moved" behavior attached to the node.
ccbPackTextures(texture1,texture2,"newTextureName")
Pack two textures into 1, in a horizontal increase, can be used multiple times to pack multiple textures.
ccbRemoveTexture(texture)
Removes the provided texture from the memory, won't remove it from the objects that use this texture and can be useful in reloading external textures.
Added some sound recording API commands, for many events like start recording, stop recording, save recorded sound to disk and many more




coa
Registered User
Quote
2023-02-06 18:46:14

Just_in_case wrote:

Added an extra parameter to the Render to Target API, that will hold the node that you want to exclude from rendering on the RTT texture, The best is to create a folder node in scenegraph explorer and then put all the nodes that you want to exclude in that folder, and simply supply that folder to the API command.
This is useful for example when you don't want overlays to be rendered to the texture.



nice just_in_case will be very useful!


just_in_case
Moderator
Quote
2023-02-27 09:54:47

Continuation of previous Thread


ccbStartRecordingAudio()
Starts recording audio from the mic.
ccbStopRecordingAudio()
Stop recording the previsoulsy started audio recording.
ccbSaveRecordedAudioToDisk("Filename")
Saves the recorded audio to disk in .wav format.
ccbSaveRecordedAudioToMemory("Filename")
Saves the recorded audio to memory and can be later accessed with ccbPlaySound(). It gets clear when the game is closed.
ccbRemoveSound("FileName")
removes the sound source, useful when removing recorded audio from memory.
ccbAddSound("SoundFile", "Alias")
Add the sound to the game with the new name assigned to it, can be used to have a single sound file played differently with different sound effects.
[b][code]


More Sound related API's are still in development. Hope to bring more to the engine.
Also modified the per scenenode Gravity, just created a new Gravity attribute for every scene node, so instead of using ccbSetSceneNodeGravity() and ccbGetSceneNodeGravity()
one can set or get them directly as attribute using ccbSetSceneNodeProperty() command.


okeoke
Registered User
Quote
2023-02-27 14:03:40

It would be so great to have some basic pitch control. Super useful if you're making an automated fire or car engine sfx.


just_in_case
Moderator
Quote
2023-02-27 15:30:44

@okeoke if you have read the very first post, I already had the "Playback speed" parameter for the sound that also controls the pitch, when I was first learning the basic of C++, but that was breaking the sound node, so it didn't make into the update.

but as my skills are somewhat improved, I already implemented pitch control and sound effects like Chorus, Reverb, distortion, gargle, flanger, compressor, echo, reverb, and many more.

they all are working great, I am just testing out a few things to provide easy usage of the sound effects and other sound-related options.


serge
Registered User
Quote
2023-02-28 21:17:20

wrote:
Created an Input event API for the controller buttons.

ccbRegisterJoyButtonEvent(funcstr)


previously I made it to return the button numbers that were pressed down, but now I changed it to return the buttonstate from a bitmask[32].
which means it will allow up to 32 buttons and can be more easily configured with multiple buttons simultaneously pressed.
It returns the button state in the power of 2.

like
[1,2,4,8,16,32,64,128,256,512,1024,2048,4096 and  so on]

let's say you pressed button 1 and button 3 at the same time then we know that button 1 = 1, and button 3 = 4, as per the above bitmask.
So it will sum up the bitmask for button 1 and button 3 which is equal to 5 and will return it.

We can then easily use it to check if buttons are pressed in combo and much more. While the button numbers that I was using previously only returned a single button value and didn't allow us to use more buttons at the same time simultaneously.

will add axis, pov, and all as input event receivers.

Here is a test video showcasing the usage of the controller, it prints the number of buttons that were pressed on the controller in the debug panel, if the number was 1 then it will move the cube ahead on X-axis. 0 means no button was pressed.
https://youtu.be/D0VSDiZkqw8

This video was created using the old method, I have updated the code a bit now.

let me know what you guys think about the controller support.

Edit:-

Added POV and Axis input control API

ccbActivateJoystick()
Activates the controller support for your game. Also returns the Joystick Information like number of buttons, axes, Joystick id, name etc.

ccbRegisterJoyButtonEvent(funcstr)
return the bitmap mask of the currently pressed buttons.

ccbRegisterJoyPovEvent(funcstr)
returns Pov value (generally angles)

ccbRegisterJoyAxisVerticalEvent(funcstr)
returns Axis value vertically -1 for down and +1 for up

ccbRegisterJoyAxisHorizontalEvent(funcstr)
returns Axis value horizontally -1 for left and +1 for right

ccbRegisterJoyAxis2VerticalEvent(funcstr)
returns second Axis value vertically -1 for down and +1 for up

ccbRegisterJoyAxis2HorizontalEvent(funcstr)
returns second Axis value horizontally -1 for left and +1 for right

hashtag.joybuttonpressed.button
Special coppercube variable that returns the button state of the button.



I don't have two controllers, so can't check the multiple controller's compatibilities. But the above code works on my controller.

Will soon update my GitHub repo, so that you guys can test the API yourself and let me know how it works.


You add the POV mouse movement to ccbRegisterJoyAxis2VerticalEvent and ccbRegisterJoyAxis2HorizontalEvent???? May i see a cuppercube file test?


just_in_case
Moderator
Quote
2023-03-06 06:38:22

New SoundPlayback system with the API:-




ccbPlaySound("SoundFile","Repeat(bool)","SoundType(2D/3D)","SoundProperty","PropertyParameters")

Plays a sound in 2D or 3D also allows to update of sound properties and sound effects. There are multiple properties and every property has its own property parameter.

Properties:-

PlaybackSpeed(float)
sets the playback speed of a sound. It also changes the pitch as well
Pause(bool)
Allows to pause and play a sound.
Pan(int)
Allows panning the sound to the left, right, or center. Can only have -1,0,1 value.
Volume(float)
Allows to change the volume of a sound.
Looping(bool)
Set the sound to be looping or non-looping.
EnableSoundEffect
Enables the sound effect followed by the SFX type.
DisableSoundEffect
Disables the sound effect followed by the SFX type.

Properties for 3D sounds only:-

Radius(float)
Sets the radius for the 3D Sounds.
Position(vector3d)
Sets the Position of a 3D sound in the scene.
Velocity(vector3d)
Sets the Velocity of the 3D sound, Useful with Doppler Effects API.

SoundFX types and their parameters

Below are the available soundFX type and their optional parameters with their default value. You can specify these parameters to get results with more sophisticated effects.

Chorus
WetDryMix = 50, Depth = 10, Feedback = 25, Frequency = 1.1, sinusWaveForm = true, Delay = 16, Phase = 90 

Compressor
Gain = 0, Attack = 10, Release = 200, Threshold = -20, Ratio = 3, Predelay = 4

Distortion
Gain = -18, Edge = 15, PostEQCenterFrequency = 2400, PostEQBandwidth = 2400, PreLowpassCutoff = 8000

Echo
WetDryMix = 50, Feedback = 50, LeftDelay = 500, RightDelay = 500, PanDelay = 0 

Flanger
WetDryMix = 50, Depth = 100, Feedback = -50, Frequency = 0.25, triangleWaveForm = true, Delay = 2, Phase = 0

Gargle
rateHz = 20, sinusWaveForm = true 

I3DL2
Room = -1000, RoomHF = -100,  RoomRolloffFactor = 0, DecayTime = 1.49, DecayHFRatio = 0.83, Reflections = -2602, ReflectionsDelay = 0.007, Reverb = 200, ReverbDelay = 0.011, Diffusion = 100.0, Density = 100.0, HFReference = 5000.0  

ParametricEqualizer
Center = 8000, Bandwidth = 12, Gain = 0

Reverb
InGain = 0, ReverbMix = 0, ReverbTime = 1000, HighFreqRTRatio = 0.001


All the properties and their parameters are optional. You can play your sound in various ways. Below is the example code that plays sound in multiple ways.


ccbAddSound("music.wav", "Sound2D");
ccbAddSound("music.wav", "Sound3D");
ccbAddSound("music.wav", "SoundWithEffects");

ccbPlaySound("Sound2D",false,"2D"); // plays a 2D sound
ccbPlaySound("Sound3D",false,"3D", "Radius", 100); // Plays a 3D sound with a radius of 100, by default 3D sound plays at radius of 1.
ccbPlaySound("SoundWithEffects", false,"2D", "EnableSoundEffect","Reverb"); // Plays a 2D sound with Reverb effect with default values.




Please see the continuity post on the next page


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Intern?tional" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact