Having issues with glMatrix?

When I try to log my this.kernel array, I noticed that the values remain unchanged. However, according to the documentation, they should be changing as expected. For more information, refer to

    this.kernel = [];
    this.kernelSize = 16.0;
    var max = 1.0;
    var min = -1.0;
    var a = Math.random(); 

for (var i = 0; i < this.kernelSize; i++){
    this.kernel.push(Math.random() * (max - min) + min); // generates random float within range of -1 to 1
    this.kernel.push(Math.random() * (max - min) + min);
    this.kernel.push(Math.random()); // generates random float within range of 0 to 1

    vec3.normalize([this.kernel[i * 3], this.kernel[i * 3 + 1], this.kernel[i * 3 + 2]], [this.kernel[i * 3], this.kernel[i * 3 + 1], this.kernel[i * 3 +2]]);
    console.log(this.kernel);
    vec3.multiply([this.kernel[i * 3], this.kernel[i * 3 + 1], this.kernel[i * 3 + 2]], a, 1.0);
    console.log(this.kernel);

}

Answer №1

If you're encountering a simple issue, take a look at the API documentation. It seems like your problem could be something along the lines of x = f(x);

The vec3.normalize() function will adjust the input data (refer to the code snippet below)

For more information, visit

333 /**
334  * Normalize a vec3
335  *
336  * @param {vec3} out the receiving vector
337  * @param {vec3} a vector to normalize
338  * @returns {vec3} out
339  */
340 vec3.normalize = function(out, a) {
341     var x = a[0],
342         y = a[1],
343         z = a[2];
344     var len = x*x + y*y + z*z;
345     if (len > 0) {
346         //TODO: evaluate use of glm_invsqrt here?
347         len = 1 / Math.sqrt(len);
348         out[0] = a[0] * len;
349         out[1] = a[1] * len;
350         out[2] = a[2] * len;
351     }
352     return out;
353 };

To implement this, use the following lines in your code:

this.kernel = vec3.normalize([this.kernel[i * 3], this.kernel[i * 3 + 1], this.kernel[i * 3 + 2]], [this.kernel[i * 3], this.kernel[i * 3 + 1], this.kernel[i * 3 +2]]);
this.kernel = vec3.multiply([this.kernel[i * 3], this.kernel[i * 3 + 1], this.kernel[i * 3 + 2]], a, 1.0);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Linking a Checkbox to a Field's Value in AngularJS

I need assistance with checking/unchecking the checkbox depending on the value of the field services.Register.IsTest. If services.Register.IsTest=True, then the checkbox should be checked. Otherwise, it should remain unchecked. Here is the checkbox code: ...

bottom tab navigator not displayed on certain screens

Hey everyone! I've been working with createbottomtabnavigator in react native, but for some reason, the bottom tab isn't visible on all screens. I've searched online but haven't found a solution yet. My goal is to show the bottom tab on ...

Initiate a timer interval without relying on the useEffect hooks

Is it possible to start a timer interval in react native without relying on the useEffect hook? In my scenario, I need to initiate the timer once a promise is resolved and update a state variable every second. How can this be achieved without using useEffe ...

Javascript: Understanding Error Handling in the Context of Async Await

I am looking to strengthen my logical reasoning, not diving into abstract concepts. Scenario 1: try { var result = await new IamErrorAlways() if (result && result instanceof Error) return result // Is this the appropriate error handling method? } ca ...

AngularJS - Utilizing Google's Place Autocomplete API Key

Recently, I started digging into Google's APIs and attempting to integrate the Places Autocomplete API with Angular. Although I'm fairly new to autocomplete features in general, I haven't included the jQuery library in my project yet. I&apos ...

The absence of data in a c# web api controller is causing issues with jQuery AJAX post requests

When I am sending data to a c# web api controller, I use the following method: $.ajax({ type: "POST", url: "menuApi/menu/Cost", data: JSON.stringify(order), contentType: "application/json", success: function (data) { window.alert(&apo ...

Can OR be utilized within a find operation?

I am currently developing a social media platform similar to Facebook using Express and MongoDB. One of the features I'm working on is adding friends to user profiles. When a user clicks on a button that says "Send Friend Request" on another user&apos ...

Switch between various 3D models in three.js by utilizing dat.gui interface

I'm currently attempting to switch between multiple 3D models (loaded with OBJMTLLoader.js) that are rendered in my three.js scene. Using dat.gui, I've created a dropdown list of model names where selecting one will add the corresponding obj mode ...

Gatsby: Issue with Event Listeners persisting when using React useEffects hook

I'm currently utilizing Gatsby for my project. Within my code, I have implemented a useEffect() hook to manage Event Listeners on the document in order to track outside clicks and close specific menus. However, upon navigating to another route and at ...

"Encountered an error: Unable to access property 'fn' on an undefined object within the Wordpress

I attempted to recreate the steps outlined in this blog post Create A Realistic Self-solving Rubik's Cube With Three.js on a Wordpress page. However, I encountered the following error Uncaught TypeError: Cannot read property 'fn' of undefine ...

What is the best way to link data from SQL Server to an HTML webpage?

Seeking assistance on how to display data from a SQL Server database in an HTML page using JavaScript, AJAX, and jQuery without the need for C#, PHP, VB.NET etc. Can someone please provide some reference links or share example code? ...

What is the best way to retrieve the directory path from a FileReader in Java

Hey there, check out these codes I have for reading the file that the user uploads: function readURL(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function(e) { $('#myImg' ...

What methods can be used to expand the clickable area to encompass sibling elements?

<div> <div class="child-1">Interactive child element</div> <div class="child-2">Non-interactive child element</div> </div> If the interactive child element (child-1) is part of a third-party li ...

I'm currently attempting to establish a connection between my server.js express API and MongoDB, but I keep encountering an unfamiliar error message that I'm having trouble decipher

Here is the server.js code: import express from 'express'; import bodyParser from 'body-parser'; import userRoutes from './routes/users.js'; import mongoose from 'mongoose'; co ...

Challenges encountered on Chrome browser when using label:hover along with relative positioning

Currently, I am in the process of creating a price list for a section of a website I'm developing. To make it interactive, I am utilizing checkbox type inputs along with labels so that users can select the services they desire, and the webpage will au ...

What is the process for including a new item in a JavaScript dictionary?

I'm currently learning JavaScript and I've encountered a challenge. I have a dictionary that I'd like to update whenever a button is clicked and the user enters some data in a prompt. However, for some reason, I am unable to successfully upd ...

Exploring AngularJS testing using Protractor's browser.wait() method

In the process of developing an automated test suite for an AngularJS application using Protractor, I have reached a point where I no longer need to manually pause the script at each step with browser.pause(). Now, I want to let the script run through to c ...

When defining a class property in TypeScript, you can make it optional by not providing

Is there a way to make a property on a Class optional without it being undefined? In the following example, note that the Class constructor takes a type of itself (this is intentional) class Test { foo: number; bar: string; baz?: string; construc ...

Issue with JavaScript removeAttribute for the "readonly" attribute not functioning as expected

Hi there, I'm new to JavaScript and I'm trying to remove the readonly attribute from some text input fields. My code seems to be working, but there's a strange behavior where the readonly attribute is removed for about 1 second and then it g ...

Using Multer and Passport, we can upload and store a file in MongoDB by utilizing Node.js and Express

Despite searching through various similar questions, I have yet to find a solution to my current dilemma. The issue at hand involves intercepting a signup post request using passport, but also needing to upload and save the profile photo to the database. ...