I need help debugging this Spotlight implementation

I’m hoping someone can help me debug this wacky implementation of a Spotlight done in Java LWJGL that I found online. Basically, I found the bug, but I cannot figure out how to fix it so that the math makes sense.

The bug is that the code takes an angle and converts it radians and takes the cosine TWICE before passing it to an Open GL fragment shader. The value that the shader gets for the spotlight’s cutoff angle is like 0.99991065.

The first part of the bug appears in this class on lines 93-94: https://github.com/lwjglgamedev/lwjglbook/blob/master/chapter12/c12-p2/src/main/java/org/lwjglb/game/DummyGame.java

    float cutoff = (float) Math.cos(Math.toRadians(140));     SpotLight spotLight = new SpotLight(pointLight, coneDir, cutoff); 

The value being passed to with “cutoff” is -0.76604444. So that’s the cosine of 140 degrees in radians… so far I’m ok.

The second part of the bug is in the constructor of the Spotlight class itself: https://github.com/lwjglgamedev/lwjglbook/blob/master/chapter12/c12-p2/src/main/java/org/lwjglb/engine/graph/SpotLight.java

public SpotLight(PointLight pointLight, Vector3f coneDirection, float cutOffAngle) {     this.pointLight = pointLight;     this.coneDirection = coneDirection;     setCutOffAngle(cutOffAngle); } 

Combined with its setCutOffAngle method:

public void setCutOff(float cutOff) {     this.cutOff = cutOff; }  public final void setCutOffAngle(float cutOffAngle) {     this.setCutOff((float)Math.cos(Math.toRadians(cutOffAngle))); } 

Do you see the wackiness I’m talking about??? It’s treating the radian angle like degrees, converting it to radians again, and then setting the actual cutoff value to the cosine of that! That value is like 0.99991065 and that is what is passed to the fragment shader’s code.

This is the code in the actual fragment shader that uses the resulting value(line 112): https://github.com/lwjglgamedev/lwjglbook/blob/master/chapter12/c12-p2/src/main/resources/shaders/fragment.fs

vec4 calcSpotLight(SpotLight light, vec3 position, vec3 normal) {   vec3 light_direction = light.pl.position - position;   vec3 to_light_dir  = normalize(light_direction);   vec3 from_light_dir  = -to_light_dir;   float spot_alfa = dot(from_light_dir, normalize(light.conedir));    vec4 colour = vec4(0, 0, 0, 0);    if ( spot_alfa > light.cutoff )    {       colour = calcPointLight(light.pl, position, normal);       colour *= (1.0 - (1.0 - spot_alfa)/(1.0 - light.cutoff));   }   return colour;     } 

So I understand the concept of the Spotlight and it’s cutoff angle, but I’m not good at math or linear algebra. I’m hoping to learn how to use dot products and normalization from good examples. But this has got me totally confused. Yes, I can jury rig it to work by making my degree angle run through this bizarre double cosine(toRadians()) logic, but I’d rather do the math correctly…

Can anyone tell me how to fix this? This particular repository has been dormant for a couple years but it is still my top google search result and many people have recommended it online.

I really appreciate any expert help.

edit: maybe “bug” isn’t the right word for this. But I consider it a bug if the implementation intends for you to pass it an angle in degrees, but actually requires you to pass the value in radians…

Need an opinionated C++ book that focuses on 17 [on hold]

I’m looking for a book (or even web-based course or interactive tutorial but ideally book) that teaches C++ 17. My normal approach of “learn by doing and Google” isn’t working, it’s obvious I need a more structured, formal approach for this. Specifically, a book that:

  • Teaches C++ assuming v17, and doesn’t worry about giving the reader a historical journey on how to do something in older versions, nor any knowledge on how to work on a “legacy” project. I really just want 17 and forward, mostly to minimize the considerable learning curve already inherent to C++, and maximize productivity and safety. (Relatively speaking of course, knowing that none of those attributes are C++’s strong points in absolute modern terms compared to other languages).
  • Is highly opinionated. That minimally focuses only on what the author considers “best practices” solutions to some of the more near-universal problems that system utility programs tend to solve over and over, rather than teaching every possible approach to a problem. (Whether his/her ideas subjectively are “best-practice” or not isn’t actually the point.) C++ is pretty overwhelming with possible approaches. I may only ever use 1% of its capabilities and language features, and is all I have the bandwidth or even capacity to learn & use. (Unfortunately the exact 1% I need isn’t knowable now, or I’d iterate them!) If I learn one sub-optimal approach among 50 possible ones, the negative consequences are minimal.
    • I understand that there are languages with “opinionated” built-into them, such as Go. But I’m no longer in the “language choice” phase.
  • Is known within the community to at least not be a horribly-written cash-grab. There seems to be so many of those. Sand traps everywhere!

There are so many books. Tyranny of choice. I’ve spent hours scouring Amazon, web search, and the StackExchange site family, but books seem nonexistent, that:

  • Don’t assume baseline proficiency in previous versions of C++
  • Aren’t just a “tour” of new features to 17
  • Do focus on teaching the excellent new features of 17, to the exclusion of historical idioms that do similar things. (I know the overlap of new:old functionality is rarely if ever 1:1.)

So I suppose the real question is not what exact book meets those needs, but at least comes close and is known to not be awful. I also understand that there isn’t one ideal approach/pattern/idiom/toolkit to every or even any one problem; again, I’m OK with only learning a highly suboptimal subset.

This answer is great (if too exhaustive), but is just for general C++, and also doesn’t focus on “opinionated”.

This is the end of the question, but if additional info helps, here’s my relevant background:

  • Long ago I programmed in C, both hobby and in a small capacity professionally. But I’ve forgotten nearly everything about it, particularly the arguably arcane syntax, symbols, and idioms. (Less so general concepts, like raw memory pointers, stack/heap, etc. Those are mostly still with me. As are general programming and OO concepts.) I find the C++ symbol-based syntax especially inscrutable and confusing. C++ 17 seems to make it a little worse (or better?), which is why I want to avoid learning unnecessary “legacy” syntax. (But my use of negative adjectives shouldn’t be interpreted as an unwillingness to learn the symbols and syntax – quite the opposite!)
  • Although faint praise, I’m arguably in an advanced tier of professional proficiency in legacy Visual Basic / VBA, Bash scripting, and CMD scripting. Advanced SQL. Can and have gotten the job done in C#, Python, Java, and JavaScript. Have also used Perl, Pascal, and Fortran, which is mostly included to give you an idea of how old I am. (Not punch-card old though.)
  • I haven’t programmed professionally in many years, but am responsible for understanding full-stack nodejs-based web applications. But on a near-daily basis I “program” in at least Bash, in as structured and idiomatic way as the language allows, including solving problems it was never meant to address. (But it is after all touring-complete!)
  • I think best in terms of classes (favoring interfaces over inheritance). I still find myself struggling now and then with Javascript’s object/prototype model.
  • I understand and appreciate that duck-typing and generics are the future, and can deal with that, but strong explicit typing is my comfort food. (As are private members and immutability.)
  • I understand lambdas, anonymous functions, and the like – when I pause to think about it – but still often struggle with real-world application, and almost never use them. While I don’t need to learn them better, it would be nice, it seems like I could benefit from using them.

Current/evolving environment:

  • Currently g++ 7.4.0, but can switch to any version or flavor necessary.
  • Mostly Linux CLI, with occasional ports to Windows CLI and MacOS/Darwin CLI.
  • Currently favoring Visual Studio Code with popular C++ extensions. (Am comfy with Sublime too.)
  • CMake (struggling!)
  • No FLOSS C++ code yet but will use public Git repositories in future.

There are many reasons for my choice of moving to C++. But being the best tool for the problems I’m currently solving is not one of them. Let’s just say it’s not the most rational or necessarily best choice, but an exhaustively researched and well-thought-out choice nonetheless. (This is not a “what’s the best language to solve problem XYZ” question, that decision has already been made.) The long and short of it is, I’ve judged it to possibly be the least-evil, single-language solution to the next 5-10 years worth of problems to solve on the horizon. But more importantly, I’ve always just wanted to “be” reasonably proficient at it, as my own private badge of honor.

Thanks in advance!

The program to draw Hello I need the code from draw O and put in draw H to make a R

from turtle import *

def move_turtle(): #Pick up the turtle and move it to its start. penup() goto(-200, 100) pendown()

def draw_H(): # Draw the left leg of the H. # The turtle starts at the bottom left of the letter, pointing right. left(90) forward(100) # Draw the bar of the H. # The turtle starts at the top of the left leg, pointing up. forward(-50) right(90) forward(50) # Draw the right leg of the H. # The turtle starts on the right side of the bar, pointing right. left(90) forward(50) forward(-100) right(90) # The H is drawn. # The turtle is at the bottom right, pointing right.

def draw_space(): # Add a space 30 pixels wide. penup() forward(30) pendown()

def draw_E ():

Draw an E.

left(90) forward(100) right (90) forward (50) forward (-50) right (90) forward (50) left(90) forward (50) forward (-50) right (90) forward(50) left(90) forward(50) 

def draw_L():
# Draw an L. left(90) forward(100) forward(-100) right(90) forward(50)

def draw_O(): # Draw an o. forward(50) left(90) forward(100) left(90) forward(50) left(90) forward(100) left(90) forward(50) “newline()” “draw_newline()”

will move turtle to second line

penup() goto(-200,-50) pendown()

def draw_W(): # Draw an W. forward(100) right(25) forward(100) right(25)

def draw_O(): # Draw an o forward(50) left(90) forward(100) left(90) forward(50) left(90) forward(100) left(90) forward(50)

move_turtle() draw_H() draw_space() draw_E() draw_space() draw_L() draw_space() draw_L() draw_space() draw_O()

I need to buy ads from Poland based wesbites

Thanks for stopping by. I am after polish language website or the domain TLD is .PL. I am willing to buy ads on bulk so please hurry up and PM me if you meet my requirements.
I know the market rates and constantly engaged in buying ads so don't make any stupid offer please.
FYI, My website is medical based website.
Again, I repeat, Polish languages website or domain TLD .PL
Looking forward to hear from you!

Need suggestions for creating field level permissions which can be changed dynamically in an app

This is currently my User-Role-Permission model in the Db schema (excluded other tables to avoid confusion). My implementation goes like this: I have a Customer table and each Role has a different set of permissions to enable the User to interact with it. The User with Salesman role can only read from it while Admin has all the CRUD permissions. To do this I’ll save 4 entries in the Permission table with perm_type = “create customer”, “read customer” etc. I have a clear mapping of which role has which permissions and those can be changed dynamically as well; simply insert or delete entries in the Role_Permission table. So before performing any action I’ll just check the user role and whether the role has the required permission with a simple if statement in my code. enter image description here

All good so far but there’s a catch now. The Salesman is supposed to have permission to update Customer as well but only the balance field. Salesman cannot update anything else say Customer name, contact etc. There are 2 ways I can implement this:

  1. Grant update permission to Salesman but in the client side only display the form for updating balance. But then again someone can exploit this, right?
  2. Create 2 methods and their corresponding permissions in the Permission table: updateCustomer(Customer updatedCustomer) and updateCustomerBalance(int id, float balance). But what if in future I want salesman to be able to update contact or address of Customer? I’ll have to add more methods for that, compile and deploy my code again. I can do that for every field before deploying my app but it looks very cumbersome especially when I have at least 15 more tables.

So is there any other way I can do this?

How much twitter followers do you need to make money

I would like to know how much twitter followers you need to start making money
at this moment I have 12k followers in just 4 days, with a automatic twitter program that i made,should I wait until I got more followers like 100k or 500k?
and should I only use clickbank?

I am also thinking about using this strategy for instagram but wil that be worth it? I know facebook is the best but it is to secured.

2019 On-Prem Workflow. Need help without Javascript

I am using Sharepoint On-Prem 2019.

Using Sharepoint Designer and no Javascript due to new sharepoint limitations, I need to accomplish the following workflow. (I used to be able to pass the Patch ID number via Javascript.)

-Create a unique patch ID -email select user group that new patch has been applied to a server. -Have users submit a bug report for the that specific patch so I can sort the list by patch ID.

The problem I am having is how to assign the same patch ID for each unique patch to every bug report. The patches occur less than one per week, so I was thinking that I could somehow base a lookup on creation date+7 days, I have been unsuccessful so far.

Anywhere from 1-10 responses can be expected each time.