Forum Groups
  All forums
    Help & Feedback
      Work in progress
      Finished Art
      Non-Max related

Maxunderground news unavailable

Trig-o-monogamy help
show user profile  9krausec
This is probably pretty basic for some of you out there, but I'm not a math wiz and I need some assistance if ya' got the time.

End game = trying to get a light to stay X amount of degrees away from camera as scene origin acts as origin (and looking straight down so all that I care about is the X and Y... or in my case the X and Z).

So below is a base to start out for explanation-
 photo tempv1_zpswvv5e2oy.jpg

^So the above I'm able to calculate the XY pos of the light by using sine/cosine based off of 165 degrees. This works fine, no problem. Only issue is when the camera moves (shown below).

 photo tempv2_zpskq6bbqy7.jpg

^Now that the camera is moving about, I figure I needed to fill in the gap and solve for theta. Then I needed to perform the same operation as the previous picture, but offset by however many degrees theta is. Below is my equation (melscript, but you should get the idea).

light.translateX = cosd((165+acosd(1/cam.translateX))) * hypot(cam.translateZ, cam.translateX);
light.translateZ = sind((165+asind(1/cam.translateZ))) * hypot(cam.translateZ, cam.translateX);

and here is a video of the results-

so what am I missing here? I'm not asking for someone to do the work for me, but I clearly am having a gap in logic.

Thanks much guys.

- Portfolio-

read 932 times
12/9/2015 9:11:06 PM (last edit: 12/9/2015 9:11:21 PM)
show user profile  donvella
I might be misunderstanding the question but couldnt you place a dummy at the origin of the world (centre of both camera/light) then link them both to it? Rotating the dummy should keep them at equal angles?

read 920 times
12/9/2015 9:50:30 PM (last edit: 12/9/2015 9:50:30 PM)
show user profile  9krausec
I think I got it, sorry for the spam. I wasn't calculating the asind() and acosd() correctly. It should not be "1/cam.translateX", but "cam.translateX/hypot"...

Woo! Look at my cubes go! This is the happiest moment of my entire life! Thanks for listening to me babble. Sorry for the spam, I was stuck.

edit: Yeah, that would work. This is for a more intricate project thing. It's only a part of it and I think it is necessary to have things setup this way with the maths.

edit edit: Isn't working, but it's a different issue. I'll post up in a bit after I've played around with it.

- Portfolio-

read 917 times
12/9/2015 9:56:05 PM (last edit: 12/9/2015 10:06:53 PM)
show user profile  donvella
oh I see, it needs to move aswell as rotate... :/

My maths is as good as my german, shiden froiden!

read 902 times
12/9/2015 10:17:42 PM (last edit: 12/9/2015 10:17:42 PM)
show user profile  9krausec
Solved for now.. The issue I was having was akin to flipped axis or something (issue demonstrated below)-

I fixed it by adding that if else statement to the bottom of the code. Probably not the most elegant way to fix it, but it works.

Thanks guys!

$camHypot = hypot(cam.translateZ, cam.translateX);
$primaryDegree = 165;
$offsetDegree = atand(cam.translateZ/cam.translateX);
$lightX = (cosd($primaryDegree+$offsetDegree)*$camHypot);
$lightZ = (sind($primaryDegree+$offsetDegree)*$camHypot);

if(cam.translateX >0){
light.translateZ = $lightZ;
light.translateX = $lightX;
light.translateZ = -$lightZ;
light.translateX = -$lightX;

- Portfolio-

read 886 times
12/9/2015 11:55:11 PM (last edit: 12/9/2015 11:55:11 PM)
show user profile  FX
"End game = trying to get a light to stay X amount of degrees away from camera as scene origin acts as origin (and looking straight down so all that I care about is the X and Y... or in my case the X and Z)."

Why ?

read 882 times
12/10/2015 12:40:34 AM (last edit: 12/10/2015 12:40:34 AM)
show user profile  9krausec
Umm, Auto light rig based on camera position for product rendering.. Completely dynamic with controllers for fine tweaking that are exported into a DB on our server that also retains saved camera positions/settings for various like-product types I deal with.

Then lets say a specific angle is requested, I'd have my 6 general lights adapt to the camera (warm soft side, cool soft side, rim light, key light, fill light).

Now, I could just rotate a custom HDRI, but I don't think that will give me the control I want since ultimately it would be too rigid of a solution.

I'd rather Python/Mel the fek out of my job if I'm going to have a workload of a small team. The above may seem a bit too sexy of a solution, but I feel it's justified for what I'm doing.

Edit: I already have a 2-3 click scene setup from scratch going on. Very nice for avoiding repetitive tasks.

Edit Edit: Also cause I'm a boss.

- Portfolio-

read 880 times
12/10/2015 12:54:58 AM (last edit: 12/10/2015 1:23:23 AM)
show user profile  Error404
Crap, this is to much math. I'll see you back at the Pub.

:-D -

read 865 times
12/10/2015 2:49:36 AM (last edit: 12/10/2015 2:49:36 AM)
show user profile  9krausec
^lol. I think the time is overdue for some pitchers of pale ale next to the beach. Next time I visit my brother IT'S ON.

- Portfolio-

read 862 times
12/10/2015 3:23:29 AM (last edit: 12/10/2015 3:23:29 AM)
show user profile  ijzerman
Clever stuff, you lost me already after the first line with cos/sin/tan in it ;)

Pushing buttons since "86
read 851 times
12/10/2015 8:34:58 AM (last edit: 12/10/2015 8:34:58 AM)
show user profile  FX

read 840 times
12/10/2015 11:55:16 AM (last edit: 12/10/2015 11:55:16 AM)
show user profile  jStins
Error and FX have this one right I think. Solved.


read 813 times
12/11/2015 9:39:14 AM (last edit: 12/11/2015 9:39:14 AM)
show user profile  9krausec
I actually got pretty excited about doing Trig. I'm not a math wizard , but something about finding solutions to these types of problems really get my hot and bothered.

Also optimization of production workflow seems to trip my trigger too.

- Portfolio-

read 795 times
12/11/2015 4:07:05 PM (last edit: 12/11/2015 4:07:05 PM)
show user profile  9krausec
So I picked this up the last day or so. Made some pretty substantial process.

Next thing I need to look at is creating specific inputs for each light object such as size, texture, intensity, and also offsets (so if I wanted to tweak the lights into a certain position from the default setup I can).

The whole idea behind this is production managing 400+ products with consistency. I already setup a camera database that pushes my camera information to a .INI config file and allows me to save out angles. That way if I ever want our standard 34ths product angle for a certain family, I just need to select it in my little script and the camera automatically changes pos, rot, f-stop, etc... to fit that profile.

So this will be the same concept (pushing to external DB), but with lights and camera info...

SO... Scene setup, one button click, apply materials I made out of my library, camera and light setup, one button click (after profiles have been created), render, one button click, post processing with actions in PS (mulitlayer EXR) one button click... Programming myself out of a job, one button click, lol.

- Portfolio-

read 691 times
12/31/2015 11:34:59 PM (last edit: 12/31/2015 11:40:20 PM)
#Maxforums IRC
Open chat window