Author Topic: Scaler - Views displayed at any scale/size  (Read 118 times)

0 Members and 1 Guest are viewing this topic.

Offline gumby

Scaler - Views displayed at any scale/size
« on: December 02, 2017, 08:34:49 PM »
I ran into a need to have a view displayed at different scales based on the room it was displayed in.  Making things more difficult, it wasn't just one view, I needed logic for N views.  No way I was going to make 20+ different versions of the same view cel for all my views to accommodate all the different scales that I needed.

I started by creating views that were 'full size', meaning either 320 on the x-axis or 190 on the y.  Then I assigned relative 'scale values' or 'sizes' between them so they would sized appropriately when displayed with any other views.  For example:

Code: [Select]
(define SWORD_SCALE 80) 
(define LAMP_SCALE 65)              ; the lamp is 80% the size of the sword
(define CLOVE_OF_GARLIC_SCALE 5)    ; the clove of garlic is 6% the size of the sword

Then determine what your room scale value should be, 1 being a 'zoomed in' room and larger values get you 'further away' from them, effectively making them scaled down.

I added this procedure in the Actor.sc script:

Code: [Select]
;;;
;;;  Calculates what the scale should be based on the relative room scale (current room) and relative view scale
;;;    viewScale - a relative scaling value between ~5 (smallest) to ~100 (largest).
;;;    roomScale - value between 1 ('closest' or 'largest views') to ~50  ('furthest' or 'smallest views')
;;;
(procedure (calcRelativeScale view loop cel viewScale roomScale &tmp width height dim tmpScale)
   (= width  (CelWide view loop cel))
   (= height (CelHigh view loop cel))
   
   (if (> width height)
      (= dim width)
    else
      (= dim height)
   )

   (= tmpScale (/ (/ (* dim viewScale) 100) roomScale))
   
   (if (< tmpScale 3)
      (= tmpScale 3)    ; smallest possible scale with full-screen views
   )
   
   (if (> tmpScale 100) 
      (= tmpScale 100) ; full size
   )
   
   (return tmpScale)
)

Then prior to initing your view, calculate the scale by passing in the view, loop, cel and your viewScale and roomScale.  Just to be safe, make sure that the computed value is sane.

Code: [Select]
   
   (= view 10)   ; the sword view
   (= loop 4)
   (= cel 0)
   (= viewScale SWORD_SCALE)
   (= roomScale 50)    ;  I actually added a new property to the Room object and set the scales for the rooms there

   (= tmpScale (calcRelativeScale view loop cel viewScale roomScale))

   ; don't attempt to scale if we have no scale value defined
   (if (> tmpScale 0)   
      (myView init: show: setScale: Scaler tmpScale tmpScale)
    else
      (myView init: show:) 
   ) 

The scaled views that I generated from a 'full size' seemed pretty good at any size but this code could be improved by having more than just one view to choose from.  We could make a 'half-size' view with max dimensions of 160x85 and perhaps another 'quarter-size' one.  Compute the scales against all 3 views and choose the one that has a resulting scale nearest to 100 - this may help with any visual degradation when the scale size gets too small.

I've attached a screenshot of 3 different views, scaled at 5 different 'room sizes' using this process:
« Last Edit: December 02, 2017, 08:47:37 PM by gumby »


In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline Kawa

Re: Scaler - Views displayed at any scale/size
« Reply #1 on: December 03, 2017, 07:06:00 AM »
The scaled views that I generated from a 'full size' seemed pretty good at any size but this code could be improved by having more than just one view to choose from.  We could make a 'half-size' view with max dimensions of 160x85 and perhaps another 'quarter-size' one.  Compute the scales against all 3 views and choose the one that has a resulting scale nearest to 100 - this may help with any visual degradation when the scale size gets too small.
So basically mipmaps?

Offline gumby

Re: Scaler - Views displayed at any scale/size
« Reply #2 on: December 03, 2017, 09:05:17 AM »
Yes, that sure seems like the gist of it.
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline MusicallyInspired

Re: Scaler - Views displayed at any scale/size
« Reply #3 on: December 03, 2017, 04:41:59 PM »
Clever approach, for SCI.
Brass Lantern Prop Competition

Offline lskovlun

Re: Scaler - Views displayed at any scale/size
« Reply #4 on: December 05, 2017, 11:59:50 AM »
I think SCI can do that out of the box if I understand you correctly, I'd have to try it out though...

Offline gumby

Re: Scaler - Views displayed at any scale/size
« Reply #5 on: December 05, 2017, 08:13:11 PM »
I think SCI can do that out of the box if I understand you correctly, I'd have to try it out though...

If you get time to try (or point me in the right direction) that would be great.
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline lskovlun

Re: Scaler - Views displayed at any scale/size
« Reply #6 on: December 06, 2017, 12:04:52 PM »
The attached script illustrates it. You set the vanishing point (vanishingY, really) of your room, and call setScale on an actor with a single argument. The actor now scales according to the room perspective. See, for instance, Ernie Leach's office in LB2 or the starting room in SQ5, both of which have odd perspectives and use this feature.

Offline Kawa

Re: Scaler - Views displayed at any scale/size
« Reply #7 on: December 06, 2017, 12:15:26 PM »
Note: this does not do mipmapping.

Offline gumby

Re: Scaler - Views displayed at any scale/size
« Reply #8 on: December 07, 2017, 08:09:17 AM »
This isn't exactly what I'm looking for unless I'm missing something. 

The first part of the the problem I'm trying to solve is to be able to arbitrarily scale a set views that are all the same initial size in the resource (say 320x200) to be relatively correct between each other. The second part is to take these relatively correct views and display them at different scales/sizes in different rooms. 

It's not so much a matter of the vanishing point in the room I don't think (but I could easily be wrong).
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition


SMF 2.0.11 | SMF © 2015, Simple Machines
Simple Audio Video Embedder

Page created in 0.131 seconds with 21 queries.